这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-toys-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(parser): handle non-ascii characters in discriminator
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type Baz = Qux;

export type Bar = Qux;

export type Spæcial = Qux;

export type Qux = {
id: string;
type: Quux;
Expand All @@ -21,7 +23,9 @@ export type Quuz = ({
type?: 'bar';
} & Bar) | ({
type?: 'baz';
} & Baz);
} & Baz) | ({
type?: 'non-ascii';
} & Spæcial);

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export type Foo = ({
foo: 'one' | 'two';
} & Bar) | ({
foo: 'three';
} & Baz);
} & Baz) | ({
foo: 'four';
} & Spæcial);

export type Bar = {
foo?: 'one' | 'two';
Expand All @@ -14,6 +16,10 @@ export type Baz = {
foo?: 'three';
};

export type Spæcial = {
foo?: 'four';
};

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type Baz = Qux;

export type Bar = Qux;

export type Spæcial = Qux;

export type Qux = {
id: string;
type: Quux;
Expand All @@ -21,7 +23,9 @@ export type Quuz = ({
type: 'bar';
} & Bar) | ({
type: 'baz';
} & Baz);
} & Baz) | ({
type: 'non-ascii';
} & Spæcial);

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type Baz = Qux;

export type Bar = Qux;

export type Spæcial = Qux;

export type Qux = {
id: string;
type: Quux;
Expand All @@ -21,7 +23,9 @@ export type Quuz = ({
type?: 'bar';
} & Bar) | ({
type?: 'baz';
} & Baz);
} & Baz) | ({
type?: 'non-ascii';
} & Spæcial);

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export type Foo = ({
foo: 'one' | 'two';
} & Bar) | ({
foo: 'three';
} & Baz);
} & Baz) | ({
foo: 'four';
} & Spæcial);

export type Bar = {
foo?: 'one' | 'two';
Expand All @@ -14,6 +16,10 @@ export type Baz = {
foo?: 'three';
};

export type Spæcial = {
foo?: 'four';
};

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type Baz = Qux;

export type Bar = Qux;

export type Spæcial = Qux;

export type Qux = {
id: string;
type: Quux;
Expand All @@ -21,7 +23,9 @@ export type Quuz = ({
type: 'bar';
} & Bar) | ({
type: 'baz';
} & Baz);
} & Baz) | ({
type: 'non-ascii';
} & Spæcial);

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ components:
Bar:
allOf:
- $ref: '#/components/schemas/Qux'
Spæcial:
allOf:
- $ref: '#/components/schemas/Qux'
Qux:
type: object
properties:
Expand All @@ -35,8 +38,10 @@ components:
anyOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: type
mapping:
bar: '#/components/schemas/Bar'
baz: '#/components/schemas/Baz'
'non-ascii': '#/components/schemas/Spæcial'
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ components:
oneOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: foo
mapping:
one: '#/components/schemas/Bar'
two: '#/components/schemas/Bar'
three: '#/components/schemas/Baz'
four: '#/components/schemas/Spæcial'
Bar:
type: object
properties:
Expand All @@ -29,3 +31,10 @@ components:
type: string
enum:
- three
Spæcial:
type: object
properties:
foo:
type: string
enum:
- four
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ components:
Bar:
allOf:
- $ref: '#/components/schemas/Qux'
Spæcial:
allOf:
- $ref: '#/components/schemas/Qux'
Qux:
type: object
properties:
Expand All @@ -35,8 +38,10 @@ components:
oneOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: type
mapping:
bar: '#/components/schemas/Bar'
baz: '#/components/schemas/Baz'
'non-ascii': '#/components/schemas/Spæcial'
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ components:
Bar:
allOf:
- $ref: '#/components/schemas/Qux'
Spæcial:
allOf:
- $ref: '#/components/schemas/Qux'
Qux:
type: object
properties:
Expand All @@ -35,8 +38,10 @@ components:
anyOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: type
mapping:
bar: '#/components/schemas/Bar'
baz: '#/components/schemas/Baz'
'non-ascii': '#/components/schemas/Spæcial'
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ components:
oneOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: foo
mapping:
one: '#/components/schemas/Bar'
two: '#/components/schemas/Bar'
three: '#/components/schemas/Baz'
four: '#/components/schemas/Spæcial'
Bar:
type: object
properties:
Expand All @@ -29,3 +31,10 @@ components:
type: string
enum:
- three
Spæcial:
type: object
properties:
foo:
type: string
enum:
- four
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ components:
Bar:
allOf:
- $ref: '#/components/schemas/Qux'
Spæcial:
allOf:
- $ref: '#/components/schemas/Qux'
Qux:
type: object
properties:
Expand All @@ -35,8 +38,10 @@ components:
oneOf:
- $ref: '#/components/schemas/Bar'
- $ref: '#/components/schemas/Baz'
- $ref: '#/components/schemas/Spæcial'
discriminator:
propertyName: type
mapping:
bar: '#/components/schemas/Bar'
baz: '#/components/schemas/Baz'
'non-ascii': '#/components/schemas/Spæcial'
8 changes: 4 additions & 4 deletions packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,9 @@ const parseAnyOf = ({
);

// `$ref` should be defined with discriminators
if (schema.discriminator && '$ref' in compositionSchema) {
if (schema.discriminator && irCompositionSchema.$ref != null) {
const values = discriminatorValues(
compositionSchema.$ref,
irCompositionSchema.$ref,
schema.discriminator.mapping,
);
const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(
Expand Down Expand Up @@ -719,9 +719,9 @@ const parseOneOf = ({
);

// `$ref` should be defined with discriminators
if (schema.discriminator && '$ref' in compositionSchema) {
if (schema.discriminator && irCompositionSchema.$ref != null) {
const values = discriminatorValues(
compositionSchema.$ref,
irCompositionSchema.$ref,
schema.discriminator.mapping,
);
const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(
Expand Down
8 changes: 4 additions & 4 deletions packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ const parseAnyOf = ({
});

// `$ref` should be defined with discriminators
if (schema.discriminator && compositionSchema.$ref) {
if (schema.discriminator && irCompositionSchema.$ref != null) {
const values = discriminatorValues(
compositionSchema.$ref,
irCompositionSchema.$ref,
schema.discriminator.mapping,
);
const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(
Expand Down Expand Up @@ -697,9 +697,9 @@ const parseOneOf = ({
});

// `$ref` should be defined with discriminators
if (schema.discriminator && compositionSchema.$ref) {
if (schema.discriminator && irCompositionSchema.$ref != null) {
const values = discriminatorValues(
compositionSchema.$ref,
irCompositionSchema.$ref,
schema.discriminator.mapping,
);
const valueSchemas: ReadonlyArray<IR.SchemaObject> = values.map(
Expand Down
Loading