Skip to content

Commit c5797a0

Browse files
committed
feat: support nested any-of to use with openapi v3.1 type null
1 parent 9b796e0 commit c5797a0

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
@@ -3682,6 +3682,7 @@ export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAl
36823682
export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
36833683
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
36843684
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
3685+
export type { CompositionWithNestedAnyAndTypeNull } from './models/CompositionWithNestedAnyAndTypeNull';
36853686
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
36863687
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
36873688
export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable';
@@ -3752,6 +3753,7 @@ export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllO
37523753
export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf';
37533754
export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable';
37543755
export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous';
3756+
export { $CompositionWithNestedAnyAndTypeNull } from './schemas/$CompositionWithNestedAnyAndTypeNull';
37553757
export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf';
37563758
export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary';
37573759
export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable';
@@ -4101,6 +4103,23 @@ export type CompositionWithAnyOfAnonymous = {
41014103
"
41024104
`;
41034105

4106+
exports[`v3 should generate: test/generated/v3/models/CompositionWithNestedAnyAndTypeNull.ts 1`] = `
4107+
"/* generated using openapi-typescript-codegen -- do no edit */
4108+
/* istanbul ignore file */
4109+
/* tslint:disable */
4110+
/* eslint-disable */
4111+
import type { ModelWithArray } from './ModelWithArray';
4112+
import type { ModelWithDictionary } from './ModelWithDictionary';
4113+
/**
4114+
* This is a model with nested 'any of' property with a type null
4115+
*/
4116+
export type CompositionWithNestedAnyAndTypeNull = {
4117+
propA?: (Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>);
4118+
};
4119+
4120+
"
4121+
`;
4122+
41044123
exports[`v3 should generate: test/generated/v3/models/CompositionWithOneOf.ts 1`] = `
41054124
"/* generated using openapi-typescript-codegen -- do no edit */
41064125
/* istanbul ignore file */
@@ -5299,6 +5318,43 @@ export const $CompositionWithAnyOfAnonymous = {
52995318
"
53005319
`;
53015320

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