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 #2471 from josstn/non-ascii-discriminator-mapping-fix

Non ascii discriminator mapping fix

authored by

Lubos and committed by
GitHub
5b69b17d 0d39e43e

+85 -14
+5
.changeset/two-toys-join.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(parser): handle non-ascii characters in discriminator
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/discriminator-any-of/types.gen.ts
··· 10 10 11 11 export type Bar = Qux; 12 12 13 + export type Spæcial = Qux; 14 + 13 15 export type Qux = { 14 16 id: string; 15 17 type: Quux; ··· 21 23 type?: 'bar'; 22 24 } & Bar) | ({ 23 25 type?: 'baz'; 24 - } & Baz); 26 + } & Baz) | ({ 27 + type?: 'non-ascii'; 28 + } & Spæcial); 25 29 26 30 export type ClientOptions = { 27 31 baseUrl: `${string}://${string}` | (string & {});
+7 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/discriminator-mapped-many/types.gen.ts
··· 4 4 foo: 'one' | 'two'; 5 5 } & Bar) | ({ 6 6 foo: 'three'; 7 - } & Baz); 7 + } & Baz) | ({ 8 + foo: 'four'; 9 + } & Spæcial); 8 10 9 11 export type Bar = { 10 12 foo?: 'one' | 'two'; ··· 12 14 13 15 export type Baz = { 14 16 foo?: 'three'; 17 + }; 18 + 19 + export type Spæcial = { 20 + foo?: 'four'; 15 21 }; 16 22 17 23 export type ClientOptions = {
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts
··· 10 10 11 11 export type Bar = Qux; 12 12 13 + export type Spæcial = Qux; 14 + 13 15 export type Qux = { 14 16 id: string; 15 17 type: Quux; ··· 21 23 type: 'bar'; 22 24 } & Bar) | ({ 23 25 type: 'baz'; 24 - } & Baz); 26 + } & Baz) | ({ 27 + type: 'non-ascii'; 28 + } & Spæcial); 25 29 26 30 export type ClientOptions = { 27 31 baseUrl: `${string}://${string}` | (string & {});
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/discriminator-any-of/types.gen.ts
··· 10 10 11 11 export type Bar = Qux; 12 12 13 + export type Spæcial = Qux; 14 + 13 15 export type Qux = { 14 16 id: string; 15 17 type: Quux; ··· 21 23 type?: 'bar'; 22 24 } & Bar) | ({ 23 25 type?: 'baz'; 24 - } & Baz); 26 + } & Baz) | ({ 27 + type?: 'non-ascii'; 28 + } & Spæcial); 25 29 26 30 export type ClientOptions = { 27 31 baseUrl: `${string}://${string}` | (string & {});
+7 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/discriminator-mapped-many/types.gen.ts
··· 4 4 foo: 'one' | 'two'; 5 5 } & Bar) | ({ 6 6 foo: 'three'; 7 - } & Baz); 7 + } & Baz) | ({ 8 + foo: 'four'; 9 + } & Spæcial); 8 10 9 11 export type Bar = { 10 12 foo?: 'one' | 'two'; ··· 12 14 13 15 export type Baz = { 14 16 foo?: 'three'; 17 + }; 18 + 19 + export type Spæcial = { 20 + foo?: 'four'; 15 21 }; 16 22 17 23 export type ClientOptions = {
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/discriminator-one-of/types.gen.ts
··· 10 10 11 11 export type Bar = Qux; 12 12 13 + export type Spæcial = Qux; 14 + 13 15 export type Qux = { 14 16 id: string; 15 17 type: Quux; ··· 21 23 type: 'bar'; 22 24 } & Bar) | ({ 23 25 type: 'baz'; 24 - } & Baz); 26 + } & Baz) | ({ 27 + type: 'non-ascii'; 28 + } & Spæcial); 25 29 26 30 export type ClientOptions = { 27 31 baseUrl: `${string}://${string}` | (string & {});
+5
packages/openapi-ts-tests/specs/3.0.x/discriminator-any-of.yaml
··· 16 16 Bar: 17 17 allOf: 18 18 - $ref: '#/components/schemas/Qux' 19 + Spæcial: 20 + allOf: 21 + - $ref: '#/components/schemas/Qux' 19 22 Qux: 20 23 type: object 21 24 properties: ··· 35 38 anyOf: 36 39 - $ref: '#/components/schemas/Bar' 37 40 - $ref: '#/components/schemas/Baz' 41 + - $ref: '#/components/schemas/Spæcial' 38 42 discriminator: 39 43 propertyName: type 40 44 mapping: 41 45 bar: '#/components/schemas/Bar' 42 46 baz: '#/components/schemas/Baz' 47 + 'non-ascii': '#/components/schemas/Spæcial'
+9
packages/openapi-ts-tests/specs/3.0.x/discriminator-mapped-many.yaml
··· 8 8 oneOf: 9 9 - $ref: '#/components/schemas/Bar' 10 10 - $ref: '#/components/schemas/Baz' 11 + - $ref: '#/components/schemas/Spæcial' 11 12 discriminator: 12 13 propertyName: foo 13 14 mapping: 14 15 one: '#/components/schemas/Bar' 15 16 two: '#/components/schemas/Bar' 16 17 three: '#/components/schemas/Baz' 18 + four: '#/components/schemas/Spæcial' 17 19 Bar: 18 20 type: object 19 21 properties: ··· 29 31 type: string 30 32 enum: 31 33 - three 34 + Spæcial: 35 + type: object 36 + properties: 37 + foo: 38 + type: string 39 + enum: 40 + - four
+5
packages/openapi-ts-tests/specs/3.0.x/discriminator-one-of.yaml
··· 16 16 Bar: 17 17 allOf: 18 18 - $ref: '#/components/schemas/Qux' 19 + Spæcial: 20 + allOf: 21 + - $ref: '#/components/schemas/Qux' 19 22 Qux: 20 23 type: object 21 24 properties: ··· 35 38 oneOf: 36 39 - $ref: '#/components/schemas/Bar' 37 40 - $ref: '#/components/schemas/Baz' 41 + - $ref: '#/components/schemas/Spæcial' 38 42 discriminator: 39 43 propertyName: type 40 44 mapping: 41 45 bar: '#/components/schemas/Bar' 42 46 baz: '#/components/schemas/Baz' 47 + 'non-ascii': '#/components/schemas/Spæcial'
+5
packages/openapi-ts-tests/specs/3.1.x/discriminator-any-of.yaml
··· 16 16 Bar: 17 17 allOf: 18 18 - $ref: '#/components/schemas/Qux' 19 + Spæcial: 20 + allOf: 21 + - $ref: '#/components/schemas/Qux' 19 22 Qux: 20 23 type: object 21 24 properties: ··· 35 38 anyOf: 36 39 - $ref: '#/components/schemas/Bar' 37 40 - $ref: '#/components/schemas/Baz' 41 + - $ref: '#/components/schemas/Spæcial' 38 42 discriminator: 39 43 propertyName: type 40 44 mapping: 41 45 bar: '#/components/schemas/Bar' 42 46 baz: '#/components/schemas/Baz' 47 + 'non-ascii': '#/components/schemas/Spæcial'
+9
packages/openapi-ts-tests/specs/3.1.x/discriminator-mapped-many.yaml
··· 8 8 oneOf: 9 9 - $ref: '#/components/schemas/Bar' 10 10 - $ref: '#/components/schemas/Baz' 11 + - $ref: '#/components/schemas/Spæcial' 11 12 discriminator: 12 13 propertyName: foo 13 14 mapping: 14 15 one: '#/components/schemas/Bar' 15 16 two: '#/components/schemas/Bar' 16 17 three: '#/components/schemas/Baz' 18 + four: '#/components/schemas/Spæcial' 17 19 Bar: 18 20 type: object 19 21 properties: ··· 29 31 type: string 30 32 enum: 31 33 - three 34 + Spæcial: 35 + type: object 36 + properties: 37 + foo: 38 + type: string 39 + enum: 40 + - four
+5
packages/openapi-ts-tests/specs/3.1.x/discriminator-one-of.yaml
··· 16 16 Bar: 17 17 allOf: 18 18 - $ref: '#/components/schemas/Qux' 19 + Spæcial: 20 + allOf: 21 + - $ref: '#/components/schemas/Qux' 19 22 Qux: 20 23 type: object 21 24 properties: ··· 35 38 oneOf: 36 39 - $ref: '#/components/schemas/Bar' 37 40 - $ref: '#/components/schemas/Baz' 41 + - $ref: '#/components/schemas/Spæcial' 38 42 discriminator: 39 43 propertyName: type 40 44 mapping: 41 45 bar: '#/components/schemas/Bar' 42 46 baz: '#/components/schemas/Baz' 47 + 'non-ascii': '#/components/schemas/Spæcial'
+4 -4
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
··· 538 538 ); 539 539 540 540 // `$ref` should be defined with discriminators 541 - if (schema.discriminator && '$ref' in compositionSchema) { 541 + if (schema.discriminator && irCompositionSchema.$ref != null) { 542 542 const values = discriminatorValues( 543 - compositionSchema.$ref, 543 + irCompositionSchema.$ref, 544 544 schema.discriminator.mapping, 545 545 ); 546 546 const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map( ··· 719 719 ); 720 720 721 721 // `$ref` should be defined with discriminators 722 - if (schema.discriminator && '$ref' in compositionSchema) { 722 + if (schema.discriminator && irCompositionSchema.$ref != null) { 723 723 const values = discriminatorValues( 724 - compositionSchema.$ref, 724 + irCompositionSchema.$ref, 725 725 schema.discriminator.mapping, 726 726 ); 727 727 const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(
+4 -4
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
··· 541 541 }); 542 542 543 543 // `$ref` should be defined with discriminators 544 - if (schema.discriminator && compositionSchema.$ref) { 544 + if (schema.discriminator && irCompositionSchema.$ref != null) { 545 545 const values = discriminatorValues( 546 - compositionSchema.$ref, 546 + irCompositionSchema.$ref, 547 547 schema.discriminator.mapping, 548 548 ); 549 549 const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map( ··· 697 697 }); 698 698 699 699 // `$ref` should be defined with discriminators 700 - if (schema.discriminator && compositionSchema.$ref) { 700 + if (schema.discriminator && irCompositionSchema.$ref != null) { 701 701 const values = discriminatorValues( 702 - compositionSchema.$ref, 702 + irCompositionSchema.$ref, 703 703 schema.discriminator.mapping, 704 704 ); 705 705 const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(