Skip to content

Commit e9eb74a

Browse files
author
Bohdan Kovalevskyi
committed
Merge branch 'feat/support-nested-any-of' into support-nested-any-of-update
2 parents 36b9a8f + c5797a0 commit e9eb74a

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

src/openApi/v3/parser/getModelComposition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export const getModelComposition = (
3030
.filter(model => {
3131
const hasProperties = model.properties.length;
3232
const hasEnums = model.enums.length;
33+
const hasLink = typeof model.link !== 'undefined' && model.link !== null;
3334
const isObject = model.type === 'any';
3435
const isDictionary = model.export === 'dictionary';
35-
const isEmpty = isObject && !hasProperties && !hasEnums;
36+
const isEmpty = isObject && !hasProperties && !hasEnums && !hasLink;
3637
return !isEmpty || isDictionary;
3738
})
3839
.forEach(model => {

test/__snapshots__/index.spec.ts.snap

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,7 @@ export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAl
36863686
export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
36873687
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
36883688
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
3689+
export type { CompositionWithNestedAnyAndTypeNull } from './models/CompositionWithNestedAnyAndTypeNull';
36893690
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
36903691
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
36913692
export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable';
@@ -3756,6 +3757,7 @@ export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllO
37563757
export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf';
37573758
export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable';
37583759
export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous';
3760+
export { $CompositionWithNestedAnyAndTypeNull } from './schemas/$CompositionWithNestedAnyAndTypeNull';
37593761
export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf';
37603762
export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary';
37613763
export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable';
@@ -4105,6 +4107,23 @@ export type CompositionWithAnyOfAnonymous = {
41054107
"
41064108
`;
41074109

4110+
exports[`v3 should generate: test/generated/v3/models/CompositionWithNestedAnyAndTypeNull.ts 1`] = `
4111+
"/* generated using openapi-typescript-codegen -- do no edit */
4112+
/* istanbul ignore file */
4113+
/* tslint:disable */
4114+
/* eslint-disable */
4115+
import type { ModelWithArray } from './ModelWithArray';
4116+
import type { ModelWithDictionary } from './ModelWithDictionary';
4117+
/**
4118+
* This is a model with nested 'any of' property with a type null
4119+
*/
4120+
export type CompositionWithNestedAnyAndTypeNull = {
4121+
propA?: (Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>);
4122+
};
4123+
4124+
"
4125+
`;
4126+
41084127
exports[`v3 should generate: test/generated/v3/models/CompositionWithOneOf.ts 1`] = `
41094128
"/* generated using openapi-typescript-codegen -- do not edit */
41104129
/* istanbul ignore file */
@@ -5303,6 +5322,43 @@ export const $CompositionWithAnyOfAnonymous = {
53035322
"
53045323
`;
53055324

5325+
exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithNestedAnyAndTypeNull.ts 1`] = `
5326+
"/* generated using openapi-typescript-codegen -- do no edit */
5327+
/* istanbul ignore file */
5328+
/* tslint:disable */
5329+
/* eslint-disable */
5330+
export const $CompositionWithNestedAnyAndTypeNull = {
5331+
description: \`This is a model with nested 'any of' property with a type null\`,
5332+
properties: {
5333+
propA: {
5334+
type: 'any-of',
5335+
contains: [{
5336+
type: 'array',
5337+
contains: {
5338+
type: 'any-of',
5339+
contains: [{
5340+
type: 'ModelWithDictionary',
5341+
}, {
5342+
type: 'null',
5343+
}],
5344+
},
5345+
}, {
5346+
type: 'array',
5347+
contains: {
5348+
type: 'any-of',
5349+
contains: [{
5350+
type: 'ModelWithArray',
5351+
}, {
5352+
type: 'null',
5353+
}],
5354+
},
5355+
}],
5356+
},
5357+
},
5358+
} as const;
5359+
"
5360+
`;
5361+
53065362
exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithOneOf.ts 1`] = `
53075363
"/* generated using openapi-typescript-codegen -- do not edit */
53085364
/* istanbul ignore file */

test/spec/v3.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,43 @@
25532553
"description": "This is a free-form object with additionalProperties: {}.",
25542554
"type": "object",
25552555
"additionalProperties": {}
2556+
},
2557+
"CompositionWithNestedAnyAndTypeNull": {
2558+
"description": "This is a model with nested 'any of' property with a type null",
2559+
"type": "object",
2560+
"properties": {
2561+
"propA": {
2562+
"type": "object",
2563+
"anyOf": [
2564+
{
2565+
"items": {
2566+
"anyOf": [
2567+
{
2568+
"$ref": "#/components/schemas/ModelWithDictionary"
2569+
},
2570+
{
2571+
"type": "null"
2572+
}
2573+
]
2574+
},
2575+
"type": "array"
2576+
},
2577+
{
2578+
"items": {
2579+
"anyOf": [
2580+
{
2581+
"$ref": "#/components/schemas/ModelWithArray"
2582+
},
2583+
{
2584+
"type": "null"
2585+
}
2586+
]
2587+
},
2588+
"type": "array"
2589+
}
2590+
]
2591+
}
2592+
}
25562593
}
25572594
}
25582595
}

0 commit comments

Comments
 (0)