Skip to content

Commit eedadee

Browse files
committed
Merge branch 'master' of github.com:ferdikoomen/openapi-typescript-codegen
2 parents b32c85e + 54d1bfe commit eedadee

File tree

3 files changed

+197
-1
lines changed

3 files changed

+197
-1
lines changed

src/openApi/v3/parser/getModelComposition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export const getModelComposition = (
3131
const hasProperties = model.properties.length;
3232
const hasEnums = model.enums.length;
3333
const isObject = model.type === 'any';
34+
const isDictionary = model.export === 'dictionary';
3435
const isEmpty = isObject && !hasProperties && !hasEnums;
35-
return !isEmpty;
36+
return !isEmpty || isDictionary;
3637
})
3738
.forEach(model => {
3839
composition.imports.push(...model.imports);

test/__snapshots__/index.spec.ts.snap

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,10 @@ export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
36613661
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
36623662
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
36633663
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
3664+
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
36643665
export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable';
3666+
export type { CompositionWithOneOfAndSimpleArrayDictionary } from './models/CompositionWithOneOfAndSimpleArrayDictionary';
3667+
export type { CompositionWithOneOfAndSimpleDictionary } from './models/CompositionWithOneOfAndSimpleDictionary';
36653668
export type { CompositionWithOneOfAnonymous } from './models/CompositionWithOneOfAnonymous';
36663669
export type { CompositionWithOneOfDiscriminator } from './models/CompositionWithOneOfDiscriminator';
36673670
export type { DictionaryWithArray } from './models/DictionaryWithArray';
@@ -3722,7 +3725,10 @@ export { $CompositionWithAnyOf } from './schemas/$CompositionWithAnyOf';
37223725
export { $CompositionWithAnyOfAndNullable } from './schemas/$CompositionWithAnyOfAndNullable';
37233726
export { $CompositionWithAnyOfAnonymous } from './schemas/$CompositionWithAnyOfAnonymous';
37243727
export { $CompositionWithOneOf } from './schemas/$CompositionWithOneOf';
3728+
export { $CompositionWithOneOfAndComplexArrayDictionary } from './schemas/$CompositionWithOneOfAndComplexArrayDictionary';
37253729
export { $CompositionWithOneOfAndNullable } from './schemas/$CompositionWithOneOfAndNullable';
3730+
export { $CompositionWithOneOfAndSimpleArrayDictionary } from './schemas/$CompositionWithOneOfAndSimpleArrayDictionary';
3731+
export { $CompositionWithOneOfAndSimpleDictionary } from './schemas/$CompositionWithOneOfAndSimpleDictionary';
37263732
export { $CompositionWithOneOfAnonymous } from './schemas/$CompositionWithOneOfAnonymous';
37273733
export { $CompositionWithOneOfDiscriminator } from './schemas/$CompositionWithOneOfDiscriminator';
37283734
export { $DictionaryWithArray } from './schemas/$DictionaryWithArray';
@@ -4056,6 +4062,20 @@ export type CompositionWithOneOf = {
40564062
"
40574063
`;
40584064

4065+
exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndComplexArrayDictionary.ts 1`] = `
4066+
"/* istanbul ignore file */
4067+
/* tslint:disable */
4068+
/* eslint-disable */
4069+
4070+
/**
4071+
* This is a model that contains a dictionary of complex arrays (composited) within composition
4072+
*/
4073+
export type CompositionWithOneOfAndComplexArrayDictionary = {
4074+
propA?: (boolean | Record<string, Array<(number | string)>>);
4075+
};
4076+
"
4077+
`;
4078+
40594079
exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndNullable.ts 1`] = `
40604080
"/* istanbul ignore file */
40614081
/* tslint:disable */
@@ -4076,6 +4096,34 @@ export type CompositionWithOneOfAndNullable = {
40764096
"
40774097
`;
40784098

4099+
exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndSimpleArrayDictionary.ts 1`] = `
4100+
"/* istanbul ignore file */
4101+
/* tslint:disable */
4102+
/* eslint-disable */
4103+
4104+
/**
4105+
* This is a model that contains a dictionary of simple arrays within composition
4106+
*/
4107+
export type CompositionWithOneOfAndSimpleArrayDictionary = {
4108+
propA?: (boolean | Record<string, Array<boolean>>);
4109+
};
4110+
"
4111+
`;
4112+
4113+
exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAndSimpleDictionary.ts 1`] = `
4114+
"/* istanbul ignore file */
4115+
/* tslint:disable */
4116+
/* eslint-disable */
4117+
4118+
/**
4119+
* This is a model that contains a simple dictionary within composition
4120+
*/
4121+
export type CompositionWithOneOfAndSimpleDictionary = {
4122+
propA?: (boolean | Record<string, number>);
4123+
};
4124+
"
4125+
`;
4126+
40794127
exports[`v3 should generate: ./test/generated/v3/models/CompositionWithOneOfAnonymous.ts 1`] = `
40804128
"/* istanbul ignore file */
40814129
/* tslint:disable */
@@ -5084,6 +5132,36 @@ export const $CompositionWithOneOf = {
50845132
} as const;"
50855133
`;
50865134

5135+
exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndComplexArrayDictionary.ts 1`] = `
5136+
"/* istanbul ignore file */
5137+
/* tslint:disable */
5138+
/* eslint-disable */
5139+
export const $CompositionWithOneOfAndComplexArrayDictionary = {
5140+
description: \`This is a model that contains a dictionary of complex arrays (composited) within composition\`,
5141+
properties: {
5142+
propA: {
5143+
type: 'one-of',
5144+
contains: [{
5145+
type: 'boolean',
5146+
}, {
5147+
type: 'dictionary',
5148+
contains: {
5149+
type: 'array',
5150+
contains: {
5151+
type: 'one-of',
5152+
contains: [{
5153+
type: 'number',
5154+
}, {
5155+
type: 'string',
5156+
}],
5157+
},
5158+
},
5159+
}],
5160+
},
5161+
},
5162+
} as const;"
5163+
`;
5164+
50875165
exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndNullable.ts 1`] = `
50885166
"/* istanbul ignore file */
50895167
/* tslint:disable */
@@ -5112,6 +5190,53 @@ export const $CompositionWithOneOfAndNullable = {
51125190
} as const;"
51135191
`;
51145192

5193+
exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndSimpleArrayDictionary.ts 1`] = `
5194+
"/* istanbul ignore file */
5195+
/* tslint:disable */
5196+
/* eslint-disable */
5197+
export const $CompositionWithOneOfAndSimpleArrayDictionary = {
5198+
description: \`This is a model that contains a dictionary of simple arrays within composition\`,
5199+
properties: {
5200+
propA: {
5201+
type: 'one-of',
5202+
contains: [{
5203+
type: 'boolean',
5204+
}, {
5205+
type: 'dictionary',
5206+
contains: {
5207+
type: 'array',
5208+
contains: {
5209+
type: 'boolean',
5210+
},
5211+
},
5212+
}],
5213+
},
5214+
},
5215+
} as const;"
5216+
`;
5217+
5218+
exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAndSimpleDictionary.ts 1`] = `
5219+
"/* istanbul ignore file */
5220+
/* tslint:disable */
5221+
/* eslint-disable */
5222+
export const $CompositionWithOneOfAndSimpleDictionary = {
5223+
description: \`This is a model that contains a simple dictionary within composition\`,
5224+
properties: {
5225+
propA: {
5226+
type: 'one-of',
5227+
contains: [{
5228+
type: 'boolean',
5229+
}, {
5230+
type: 'dictionary',
5231+
contains: {
5232+
type: 'number',
5233+
},
5234+
}],
5235+
},
5236+
},
5237+
} as const;"
5238+
`;
5239+
51155240
exports[`v3 should generate: ./test/generated/v3/schemas/$CompositionWithOneOfAnonymous.ts 1`] = `
51165241
"/* istanbul ignore file */
51175242
/* tslint:disable */

test/spec/v3.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,76 @@
20662066
}
20672067
}
20682068
},
2069+
"CompositionWithOneOfAndSimpleDictionary": {
2070+
"description": "This is a model that contains a simple dictionary within composition",
2071+
"type": "object",
2072+
"properties": {
2073+
"propA": {
2074+
"oneOf": [
2075+
{
2076+
"type": "boolean"
2077+
},
2078+
{
2079+
"type": "object",
2080+
"additionalProperties": {
2081+
"type": "number"
2082+
}
2083+
}
2084+
]
2085+
}
2086+
}
2087+
},
2088+
"CompositionWithOneOfAndSimpleArrayDictionary": {
2089+
"description": "This is a model that contains a dictionary of simple arrays within composition",
2090+
"type": "object",
2091+
"properties": {
2092+
"propA": {
2093+
"oneOf": [
2094+
{
2095+
"type": "boolean"
2096+
},
2097+
{
2098+
"type": "object",
2099+
"additionalProperties": {
2100+
"type": "array",
2101+
"items": {
2102+
"type": "boolean"
2103+
}
2104+
}
2105+
}
2106+
]
2107+
}
2108+
}
2109+
},
2110+
"CompositionWithOneOfAndComplexArrayDictionary": {
2111+
"description": "This is a model that contains a dictionary of complex arrays (composited) within composition",
2112+
"type": "object",
2113+
"properties": {
2114+
"propA": {
2115+
"oneOf": [
2116+
{
2117+
"type": "boolean"
2118+
},
2119+
{
2120+
"type": "object",
2121+
"additionalProperties": {
2122+
"type": "array",
2123+
"items": {
2124+
"oneOf": [
2125+
{
2126+
"type": "number"
2127+
},
2128+
{
2129+
"type": "string"
2130+
}
2131+
]
2132+
}
2133+
}
2134+
}
2135+
]
2136+
}
2137+
}
2138+
},
20692139
"CompositionWithAllOfAndNullable": {
20702140
"description": "This is a model with one property with a 'all of' relationship",
20712141
"type": "object",

0 commit comments

Comments
 (0)