Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/openApi/v3/parser/getModelComposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export const getModelComposition = (
.filter(model => {
const hasProperties = model.properties.length;
const hasEnums = model.enums.length;
const hasLink = typeof model.link !== 'undefined' && model.link !== null;
const isObject = model.type === 'any';
const isDictionary = model.export === 'dictionary';
const isEmpty = isObject && !hasProperties && !hasEnums;
const isEmpty = isObject && !hasProperties && !hasEnums && !hasLink;
return !isEmpty || isDictionary;
})
.forEach(model => {
Expand Down
56 changes: 56 additions & 0 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,7 @@ export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAl
export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
export type { CompositionWithNestedAnyAndTypeNull } from './models/CompositionWithNestedAnyAndTypeNull';
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable';
Expand Down Expand Up @@ -3752,6 +3753,7 @@ export { $CompositionWithAllOfAndNullable } from './schemas/$CompositionWithAllO
export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf';
export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable';
export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous';
export { $CompositionWithNestedAnyAndTypeNull } from './schemas/$CompositionWithNestedAnyAndTypeNull';
export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf';
export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary';
export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable';
Expand Down Expand Up @@ -4101,6 +4103,23 @@ export type CompositionWithAnyOfAnonymous = {
"
`;

exports[`v3 should generate: test/generated/v3/models/CompositionWithNestedAnyAndTypeNull.ts 1`] = `
"/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ModelWithArray } from './ModelWithArray';
import type { ModelWithDictionary } from './ModelWithDictionary';
/**
* This is a model with nested 'any of' property with a type null
*/
export type CompositionWithNestedAnyAndTypeNull = {
propA?: (Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>);
};

"
`;

exports[`v3 should generate: test/generated/v3/models/CompositionWithOneOf.ts 1`] = `
"/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
Expand Down Expand Up @@ -5299,6 +5318,43 @@ export const $CompositionWithAnyOfAnonymous = {
"
`;

exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithNestedAnyAndTypeNull.ts 1`] = `
"/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $CompositionWithNestedAnyAndTypeNull = {
description: \`This is a model with nested 'any of' property with a type null\`,
properties: {
propA: {
type: 'any-of',
contains: [{
type: 'array',
contains: {
type: 'any-of',
contains: [{
type: 'ModelWithDictionary',
}, {
type: 'null',
}],
},
}, {
type: 'array',
contains: {
type: 'any-of',
contains: [{
type: 'ModelWithArray',
}, {
type: 'null',
}],
},
}],
},
},
} as const;
"
`;

exports[`v3 should generate: test/generated/v3/schemas/$CompositionWithOneOf.ts 1`] = `
"/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
Expand Down
37 changes: 37 additions & 0 deletions test/spec/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,43 @@
"description": "This is a free-form object with additionalProperties: {}.",
"type": "object",
"additionalProperties": {}
},
"CompositionWithNestedAnyAndTypeNull": {
"description": "This is a model with nested 'any of' property with a type null",
"type": "object",
"properties": {
"propA": {
"type": "object",
"anyOf": [
{
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/ModelWithDictionary"
},
{
"type": "null"
}
]
},
"type": "array"
},
{
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/ModelWithArray"
},
{
"type": "null"
}
]
},
"type": "array"
}
]
}
}
}
}
}
Expand Down