From 342772a560378c6718d25c29871eeab9a72c62a6 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 4 Jul 2024 01:34:39 +0100 Subject: [PATCH] fix: handle properties in one-of composition --- .changeset/unlucky-birds-work.md | 5 ++ .../openApi/v3/parser/getModelComposition.ts | 74 ++++++++++++------- .../test/generated/v3/schemas.gen.ts.snap | 26 +++++++ .../test/generated/v3/types.gen.ts.snap | 8 +- .../generated/v3_angular/schemas.gen.ts.snap | 26 +++++++ .../generated/v3_angular/types.gen.ts.snap | 8 +- .../generated/v3_axios/schemas.gen.ts.snap | 26 +++++++ .../test/generated/v3_axios/types.gen.ts.snap | 8 +- .../generated/v3_client/types.gen.ts.snap | 8 +- .../v3_enums_typescript/types.gen.ts.snap | 8 +- .../schemas.gen.ts.snap | 26 +++++++ .../v3_hey-api_client-axios/types.gen.ts.snap | 8 +- .../schemas.gen.ts.snap | 26 +++++++ .../v3_hey-api_client-fetch/types.gen.ts.snap | 8 +- .../generated/v3_node/schemas.gen.ts.snap | 26 +++++++ .../test/generated/v3_node/types.gen.ts.snap | 8 +- .../v3_schemas_form/schemas.gen.ts.snap | 26 +++++++ .../v3_schemas_json/schemas.gen.ts.snap | 26 +++++++ .../v3_tree_shakeable/types.gen.ts.snap | 8 +- .../test/generated/v3_types/types.gen.ts.snap | 8 +- .../test/generated/v3_xhr/schemas.gen.ts.snap | 26 +++++++ .../test/generated/v3_xhr/types.gen.ts.snap | 8 +- packages/openapi-ts/test/sample.cjs | 8 +- packages/openapi-ts/test/spec/v3.json | 25 +++++++ 24 files changed, 381 insertions(+), 53 deletions(-) create mode 100644 .changeset/unlucky-birds-work.md diff --git a/.changeset/unlucky-birds-work.md b/.changeset/unlucky-birds-work.md new file mode 100644 index 000000000..a72d996d0 --- /dev/null +++ b/.changeset/unlucky-birds-work.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: handle properties in one-of composition diff --git a/packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts b/packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts index b9f8b65e9..ed309ecf7 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getModelComposition.ts @@ -116,33 +116,53 @@ export const getModelComposition = ({ if (properties.length) { const foundComposition = findModelComposition(definition); - if (foundComposition?.type === 'one-of') { - composition.properties.forEach((property) => { - property.properties = [...property.properties, ...properties]; - }); - } else { - composition.properties = [ - ...composition.properties, - { - $refs: [], - base: 'unknown', - description: '', - enum: [], - enums: [], - export: 'interface', - imports: [], - in: '', - isDefinition: false, - isNullable: false, - isReadOnly: false, - isRequired: false, - link: null, - name: 'properties', - properties, - template: null, - type: 'unknown', - }, - ]; + if (foundComposition) { + const propertiesProperty: Model = { + $refs: [], + base: 'unknown', + description: '', + enum: [], + enums: [], + export: 'interface', + imports: [], + in: '', + isDefinition: false, + isNullable: false, + isReadOnly: false, + isRequired: false, + link: null, + name: 'properties', + properties, + template: null, + type: 'unknown', + }; + + if (foundComposition.type === 'one-of') { + composition.properties = [ + { + ...composition, + base: '', + description: null, + enum: [], + in: '', + isDefinition: false, + isNullable: false, + isReadOnly: false, + isRequired: true, + link: null, + name: '', + template: null, + type: '', + }, + propertiesProperty, + ]; + composition.export = 'all-of'; + } else { + composition.properties = [ + ...composition.properties, + propertiesProperty, + ]; + } } } diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap index f0ac4f520..28364407c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap index 760489e78..22066ae2b 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap @@ -687,10 +687,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -835,6 +834,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap index f0ac4f520..28364407c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap index fe32fbe19..30ea3f5db 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap @@ -687,10 +687,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -835,6 +834,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap index e31720c19..774c2066a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap @@ -750,10 +750,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -914,6 +913,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap index 928068a36..27e0fb216 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap index 928068a36..27e0fb216 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap index f0ac4f520..28364407c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap index 42877c8e2..b425dc3dc 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_form/schemas.gen.ts.snap @@ -1561,6 +1561,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { type: 'string' } as const; diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_schemas_json/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap index 58b39fd83..40ce295c2 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap index 138708033..9f36e465d 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_types/types.gen.ts.snap @@ -687,10 +687,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -835,6 +834,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/schemas.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/schemas.gen.ts.snap index e5c0ba16f..0fc34061f 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/schemas.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/schemas.gen.ts.snap @@ -1709,6 +1709,32 @@ export const $ModelWithBackticksInDescription = { } } as const; +export const $ModelWithOneOfAndProperties = { + type: 'object', + oneOf: [ + { + '$ref': '#/components/parameters/SimpleParameter' + }, + { + '$ref': '#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串' + } + ], + required: ['baz', 'qux'], + properties: { + baz: { + type: 'integer', + format: 'uint16', + minimum: 0, + nullable: true + }, + qux: { + type: 'integer', + format: 'uint8', + minimum: 0 + } + } +} as const; + export const $ParameterSimpleParameterUnused = { description: 'Model used to test deduplication strategy (unused)', type: 'string' diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap index f0ac4f520..28364407c 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap @@ -783,10 +783,9 @@ export type NestedAnyOfArraysNullable = { export type CompositionWithOneOfAndProperties = { foo: ParameterSimpleParameter; - baz: number | null; - qux: number; } | { bar: NonAsciiStringæøåÆØÅöôêÊ字符串; +} & { baz: number | null; qux: number; }; @@ -958,6 +957,11 @@ export type ModelWithBackticksInDescription = { template?: string; }; +export type ModelWithOneOfAndProperties = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串 & { + baz: number | null; + qux: number; +}; + /** * Model used to test deduplication strategy (unused) */ diff --git a/packages/openapi-ts/test/sample.cjs b/packages/openapi-ts/test/sample.cjs index 990b4a364..9a1a17627 100644 --- a/packages/openapi-ts/test/sample.cjs +++ b/packages/openapi-ts/test/sample.cjs @@ -17,14 +17,14 @@ const main = async () => { }, services: { // asClass: true, - // export: false, + export: false, // name: '^Parameters', }, types: { // dates: 'types+transform', - enums: 'typescript', - // include: - // '^ModelWithPrefixItemsConstantSizeArray|ModelWithAnyOfConstantSizeArray', + // enums: 'typescript', + include: + '^(ModelWithOneOfAndProperties|CompositionWithOneOfAndProperties)', // name: 'PascalCase', }, // useOptions: false, diff --git a/packages/openapi-ts/test/spec/v3.json b/packages/openapi-ts/test/spec/v3.json index 1cb5c0980..713a0b36d 100644 --- a/packages/openapi-ts/test/spec/v3.json +++ b/packages/openapi-ts/test/spec/v3.json @@ -3282,6 +3282,31 @@ } } }, + "ModelWithOneOfAndProperties": { + "type": "object", + "oneOf": [ + { + "$ref": "#/components/parameters/SimpleParameter" + }, + { + "$ref": "#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串" + } + ], + "required": ["baz", "qux"], + "properties": { + "baz": { + "type": "integer", + "format": "uint16", + "minimum": 0.0, + "nullable": true + }, + "qux": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + } + }, "ParameterSimpleParameterUnused": { "description": "Model used to test deduplication strategy (unused)", "type": "string"