fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2108 from hey-api/fix/array-nested-one-of

fix(typescript): generates union of arrays when items use nested oneOf

authored by

Lubos and committed by
GitHub
d0a321b0 497f9881

+126 -2
+5
.changeset/modern-nails-clap.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(typescript): generates union of arrays when items use nested oneOf
+7
packages/openapi-ts-tests/test/3.0.x.test.ts
··· 76 76 }, 77 77 { 78 78 config: createConfig({ 79 + input: 'array-nested-one-of.yaml', 80 + output: 'array-nested-one-of', 81 + }), 82 + description: 'generates union of arrays when items use nested oneOf', 83 + }, 84 + { 85 + config: createConfig({ 79 86 input: 'body-response-text-plain.yaml', 80 87 output: 'body-response-text-plain', 81 88 plugins: [
+7
packages/openapi-ts-tests/test/3.1.x.test.ts
··· 76 76 }, 77 77 { 78 78 config: createConfig({ 79 + input: 'array-nested-one-of.yaml', 80 + output: 'array-nested-one-of', 81 + }), 82 + description: 'generates union of arrays when items use nested oneOf', 83 + }, 84 + { 85 + config: createConfig({ 79 86 input: 'body-response-text-plain.yaml', 80 87 output: 'body-response-text-plain', 81 88 plugins: [
+2
packages/openapi-ts-tests/test/__snapshots__/3.0.x/array-nested-one-of/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen';
+16
packages/openapi-ts-tests/test/__snapshots__/3.0.x/array-nested-one-of/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type Foo = Array<{ 4 + foo?: string; 5 + bar?: string; 6 + } | { 7 + baz?: string; 8 + qux?: string; 9 + }> | Array<{ 10 + foo?: string; 11 + bar?: string; 12 + }>; 13 + 14 + export type ClientOptions = { 15 + baseUrl: `${string}://${string}` | (string & {}); 16 + };
+2
packages/openapi-ts-tests/test/__snapshots__/3.1.x/array-nested-one-of/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen';
+16
packages/openapi-ts-tests/test/__snapshots__/3.1.x/array-nested-one-of/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type Foo = Array<{ 4 + foo?: string; 5 + bar?: string; 6 + } | { 7 + baz?: string; 8 + qux?: string; 9 + }> | Array<{ 10 + foo?: string; 11 + bar?: string; 12 + }>; 13 + 14 + export type ClientOptions = { 15 + baseUrl: `${string}://${string}` | (string & {}); 16 + };
+7 -2
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 44 44 // openapi: '3.1.0', 45 45 // paths: {}, 46 46 // }, 47 - path: path.resolve(__dirname, 'spec', '3.1.x', 'full.json'), 47 + path: path.resolve( 48 + __dirname, 49 + 'spec', 50 + '3.1.x', 51 + 'array-nested-one-of.yaml', 52 + ), 48 53 // path: 'http://localhost:4000/', 49 54 // path: 'https://get.heyapi.dev/', 50 55 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', ··· 110 115 // enumsCase: 'camelCase', 111 116 // enumsConstantsIgnoreNull: true, 112 117 // exportInlineEnums: true, 113 - identifierCase: 'snake_case', 118 + // identifierCase: 'snake_case', 114 119 name: '@hey-api/typescript', 115 120 // readOnlyWriteOnlyBehavior: 'off', 116 121 // readableNameBuilder: 'Readable{{name}}',
+31
packages/openapi-ts-tests/test/spec/3.0.x/array-nested-one-of.yaml
··· 1 + openapi: 3.0.3 2 + info: 3 + title: OpenAPI 3.0.3 array nested one of example 4 + version: 1 5 + components: 6 + schemas: 7 + Foo: 8 + oneOf: 9 + - type: array 10 + items: 11 + oneOf: 12 + - type: object 13 + properties: 14 + foo: 15 + type: string 16 + bar: 17 + type: string 18 + - type: object 19 + properties: 20 + baz: 21 + type: string 22 + qux: 23 + type: string 24 + - type: array 25 + items: 26 + type: object 27 + properties: 28 + foo: 29 + type: string 30 + bar: 31 + type: string
+31
packages/openapi-ts-tests/test/spec/3.1.x/array-nested-one-of.yaml
··· 1 + openapi: 3.1.1 2 + info: 3 + title: OpenAPI 3.1.1 array nested one of example 4 + version: 1 5 + components: 6 + schemas: 7 + Foo: 8 + oneOf: 9 + - type: array 10 + items: 11 + oneOf: 12 + - type: object 13 + properties: 14 + foo: 15 + type: string 16 + bar: 17 + type: string 18 + - type: object 19 + properties: 20 + baz: 21 + type: string 22 + qux: 23 + type: string 24 + - type: array 25 + items: 26 + type: object 27 + properties: 28 + foo: 29 + type: string 30 + bar: 31 + type: string
+1
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
··· 730 730 // to avoid unnecessary brackets 731 731 if ( 732 732 irCompositionSchema.logicalOperator === 'or' && 733 + irCompositionSchema.type !== 'array' && 733 734 irCompositionSchema.items 734 735 ) { 735 736 schemaItems = schemaItems.concat(irCompositionSchema.items);
+1
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
··· 767 767 // to avoid unnecessary brackets 768 768 if ( 769 769 irCompositionSchema.logicalOperator === 'or' && 770 + irCompositionSchema.type !== 'array' && 770 771 irCompositionSchema.items 771 772 ) { 772 773 schemaItems = schemaItems.concat(irCompositionSchema.items);