diff --git a/src/openApi/v3/parser/getModelComposition.ts b/src/openApi/v3/parser/getModelComposition.ts index 6b5e4c305..2c27d1815 100644 --- a/src/openApi/v3/parser/getModelComposition.ts +++ b/src/openApi/v3/parser/getModelComposition.ts @@ -31,8 +31,9 @@ export const getModelComposition = ( const hasProperties = model.properties.length; const hasEnums = model.enums.length; const isObject = model.type === 'any'; + const isDictionary = model.export === 'dictionary'; const isEmpty = isObject && !hasProperties && !hasEnums; - return !isEmpty; + return !isEmpty || isDictionary; }) .forEach(model => { composition.imports.push(...model.imports); diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index f294281b3..0ff454589 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -3507,7 +3507,10 @@ export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf'; export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable'; export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous'; export type { CompositionWithOneOf } from './models/CompositionWithOneOf'; +export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary'; export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable'; +export type { CompositionWithOneOfAndSimpleArrayDictionary } from './models/CompositionWithOneOfAndSimpleArrayDictionary'; +export type { CompositionWithOneOfAndSimpleDictionary } from './models/CompositionWithOneOfAndSimpleDictionary'; export type { CompositionWithOneOfAnonymous } from './models/CompositionWithOneOfAnonymous'; export type { CompositionWithOneOfDiscriminator } from './models/CompositionWithOneOfDiscriminator'; export type { DictionaryWithArray } from './models/DictionaryWithArray'; @@ -3568,7 +3571,10 @@ export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf'; export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable'; export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous'; export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf'; +export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary'; export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable'; +export { $CompositionWithOneOfAndSimpleArrayDictionary } from './schemas/$CompositionWithOneOfAndSimpleArrayDictionary'; +export { $CompositionWithOneOfAndSimpleDictionary } from './schemas/$CompositionWithOneOfAndSimpleDictionary'; export { $CompositionWithOneOfAnonymous } from './schemas/$CompositionWithOneOfAnonymous'; export { $CompositionWithOneOfDiscriminator } from './schemas/$CompositionWithOneOfDiscriminator'; export { $DictionaryWithArray } from './schemas/$DictionaryWithArray'; @@ -3902,6 +3908,20 @@ export type CompositionWithOneOf = { " `; +exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndComplexArrayDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: (boolean | Record>); +}; +" +`; + exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndNullable.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ @@ -3922,6 +3942,34 @@ export type CompositionWithOneOfAndNullable = { " `; +exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndSimpleArrayDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: (boolean | Record>); +}; +" +`; + +exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndSimpleDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: (boolean | Record); +}; +" +`; + exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAnonymous.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ @@ -4928,6 +4976,36 @@ export const $CompositionWithOneOf = { } as const;" `; +exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndComplexArrayDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithOneOfAndComplexArrayDictionary = { + description: \`This is a model that contains a dictionary of complex arrays (composited) within composition\`, + properties: { + propA: { + type: 'one-of', + contains: [{ + type: 'boolean', + }, { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'one-of', + contains: [{ + type: 'number', + }, { + type: 'string', + }], + }, + }, + }], + }, + }, +} as const;" +`; + exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndNullable.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ @@ -4956,6 +5034,53 @@ export const $CompositionWithOneOfAndNullable = { } as const;" `; +exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndSimpleArrayDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithOneOfAndSimpleArrayDictionary = { + description: \`This is a model that contains a dictionary of simple arrays within composition\`, + properties: { + propA: { + type: 'one-of', + contains: [{ + type: 'boolean', + }, { + type: 'dictionary', + contains: { + type: 'array', + contains: { + type: 'boolean', + }, + }, + }], + }, + }, +} as const;" +`; + +exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndSimpleDictionary.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $CompositionWithOneOfAndSimpleDictionary = { + description: \`This is a model that contains a simple dictionary within composition\`, + properties: { + propA: { + type: 'one-of', + contains: [{ + type: 'boolean', + }, { + type: 'dictionary', + contains: { + type: 'number', + }, + }], + }, + }, +} as const;" +`; + exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAnonymous.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ diff --git a/test/spec/v3.json b/test/spec/v3.json index c336bda80..e41bfd52c 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -2064,6 +2064,76 @@ } } }, + "CompositionWithOneOfAndSimpleDictionary": { + "description": "This is a model that contains a simple dictionary within composition", + "type": "object", + "properties": { + "propA": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "type": "number" + } + } + ] + } + } + }, + "CompositionWithOneOfAndSimpleArrayDictionary": { + "description": "This is a model that contains a dictionary of simple arrays within composition", + "type": "object", + "properties": { + "propA": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "boolean" + } + } + } + ] + } + } + }, + "CompositionWithOneOfAndComplexArrayDictionary": { + "description": "This is a model that contains a dictionary of complex arrays (composited) within composition", + "type": "object", + "properties": { + "propA": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "oneOf": [ + { + "type": "number" + }, + { + "type": "string" + } + ] + } + } + } + ] + } + } + }, "CompositionWithAllOfAndNullable": { "description": "This is a model with one property with a 'all of' relationship", "type": "object",