Skip to content

Commit 4174eb7

Browse files
committed
chore(model): add another test case
1 parent 72094f6 commit 4174eb7

File tree

3 files changed

+105
-11
lines changed

3 files changed

+105
-11
lines changed

src/openApi/v3/parser/getModelComposition.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ 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;
34+
console.log(model.name, model)
3335
const isObject = model.type === 'any';
3436
const isDictionary = model.export === 'dictionary';
35-
const isEmpty = isObject && !hasProperties && !hasEnums;
37+
const isEmpty = isObject && !hasProperties && !hasEnums && !hasLink;
3638
return !isEmpty || isDictionary;
3739
})
3840
.forEach(model => {

test/__snapshots__/index.spec.ts.snap

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,7 @@ export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAl
37103710
export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
37113711
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
37123712
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
3713+
export type { CompositionWithNestedAnyAndTypeNull } from './models/CompositionWithNestedAnyAndTypeNull';
37133714
export type { CompositionWithNestedAnyOfAndNull } from './models/CompositionWithNestedAnyOfAndNull';
37143715
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
37153716
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
@@ -3786,6 +3787,7 @@ export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllO
37863787
export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf';
37873788
export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable';
37883789
export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous';
3790+
export { $CompositionWithNestedAnyAndTypeNull } from './schemas/$CompositionWithNestedAnyAndTypeNull';
37893791
export { $CompositionWithNestedAnyOfAndNull } from './schemas/$CompositionWithNestedAnyOfAndNull';
37903792
export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf';
37913793
export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary';
@@ -3894,11 +3896,14 @@ exports[`v3 should generate: test/generated/v3/models/AnyOfArrays.ts 1`] = `
38943896
/* istanbul ignore file */
38953897
/* tslint:disable */
38963898
/* eslint-disable */
3899+
/**
3900+
* This is a simple array with any of properties
3901+
*/
38973902
export type AnyOfArrays = {
38983903
results?: Array<({
3899-
onePro?: boolean;
3904+
foo?: string;
39003905
} | {
3901-
anotherProp?: boolean;
3906+
bar?: string;
39023907
})>;
39033908
};
39043909

@@ -4167,6 +4172,23 @@ export type CompositionWithAnyOfAnonymous = {
41674172
"
41684173
`;
41694174

4175+
exports[`v3 should generate: test/generated/v3/models/CompositionWithNestedAnyAndTypeNull.ts 1`] = `
4176+
"/* generated using openapi-typescript-codegen -- do no edit */
4177+
/* istanbul ignore file */
4178+
/* tslint:disable */
4179+
/* eslint-disable */
4180+
import type { ModelWithArray } from './ModelWithArray';
4181+
import type { ModelWithDictionary } from './ModelWithDictionary';
4182+
/**
4183+
* This is a model with nested 'any of' property with a type null
4184+
*/
4185+
export type CompositionWithNestedAnyAndTypeNull = {
4186+
propA?: ((ModelWithDictionary | null) | (ModelWithArray | null));
4187+
};
4188+
4189+
"
4190+
`;
4191+
41704192
exports[`v3 should generate: test/generated/v3/models/CompositionWithNestedAnyOfAndNull.ts 1`] = `
41714193
"/* generated using openapi-typescript-codegen -- do no edit */
41724194
/* istanbul ignore file */
@@ -5110,19 +5132,20 @@ exports[`v3 should generate: test/generated/v3/schemas/$AnyOfArrays.ts 1`] = `
51105132
/* tslint:disable */
51115133
/* eslint-disable */
51125134
export const $AnyOfArrays = {
5135+
description: \`This is a simple array with any of properties\`,
51135136
properties: {
51145137
results: {
51155138
type: 'any-of',
51165139
contains: [{
51175140
properties: {
5118-
onePro: {
5119-
type: 'boolean',
5141+
foo: {
5142+
type: 'string',
51205143
},
51215144
},
51225145
}, {
51235146
properties: {
5124-
anotherProp: {
5125-
type: 'boolean',
5147+
bar: {
5148+
type: 'string',
51265149
},
51275150
},
51285151
}],
@@ -5464,6 +5487,37 @@ export const $CompositionWithAnyOfAnonymous = {
54645487
"
54655488
`;
54665489

5490+
exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithNestedAnyAndTypeNull.ts 1`] = `
5491+
"/* generated using openapi-typescript-codegen -- do no edit */
5492+
/* istanbul ignore file */
5493+
/* tslint:disable */
5494+
/* eslint-disable */
5495+
export const $CompositionWithNestedAnyAndTypeNull = {
5496+
description: \`This is a model with nested 'any of' property with a type null\`,
5497+
properties: {
5498+
propA: {
5499+
type: 'any-of',
5500+
contains: [{
5501+
type: 'any-of',
5502+
contains: [{
5503+
type: 'ModelWithDictionary',
5504+
}, {
5505+
type: 'null',
5506+
}],
5507+
}, {
5508+
type: 'any-of',
5509+
contains: [{
5510+
type: 'ModelWithArray',
5511+
}, {
5512+
type: 'null',
5513+
}],
5514+
}],
5515+
},
5516+
},
5517+
} as const;
5518+
"
5519+
`;
5520+
54675521
exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithNestedAnyOfAndNull.ts 1`] = `
54685522
"/* generated using openapi-typescript-codegen -- do no edit */
54695523
/* istanbul ignore file */

test/spec/v3.json

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,43 @@
20952095
}
20962096
}
20972097
},
2098+
"CompositionWithNestedAnyAndTypeNull": {
2099+
"description": "This is a model with nested 'any of' property with a type null",
2100+
"type": "object",
2101+
"properties": {
2102+
"propA": {
2103+
"type": "object",
2104+
"anyOf": [
2105+
{
2106+
"items": {
2107+
"anyOf": [
2108+
{
2109+
"$ref": "#/components/schemas/ModelWithDictionary"
2110+
},
2111+
{
2112+
"type": "null"
2113+
}
2114+
]
2115+
},
2116+
"type": "array"
2117+
},
2118+
{
2119+
"items": {
2120+
"anyOf": [
2121+
{
2122+
"$ref": "#/components/schemas/ModelWithArray"
2123+
},
2124+
{
2125+
"type": "null"
2126+
}
2127+
]
2128+
},
2129+
"type": "array"
2130+
}
2131+
]
2132+
}
2133+
}
2134+
},
20982135
"Enum1": {
20992136
"enum": [
21002137
"Bird",
@@ -2304,6 +2341,7 @@
23042341
}
23052342
},
23062343
"AnyOfArrays": {
2344+
"description": "This is a simple array with any of properties",
23072345
"type": "object",
23082346
"properties": {
23092347
"results": {
@@ -2312,16 +2350,16 @@
23122350
{
23132351
"type": "object",
23142352
"properties": {
2315-
"oneProp": {
2316-
"type": "boolean"
2353+
"foo": {
2354+
"type": "string"
23172355
}
23182356
}
23192357
},
23202358
{
23212359
"type": "object",
23222360
"properties": {
2323-
"anotherProp": {
2324-
"type": "boolean"
2361+
"bar": {
2362+
"type": "string"
23252363
}
23262364
}
23272365
}

0 commit comments

Comments
 (0)