这是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/grumpy-rings-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(parser): OpenAPI 3.1 parser handles multiple `type` values
8 changes: 8 additions & 0 deletions packages/openapi-ts-tests/main/test/3.1.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ describe(`OpenAPI ${version}`, () => {
description:
'handles various enum names and values (TypeScript, preserve)',
},
{
config: createConfig({
input: 'union-types.json',
output: 'union-types',
plugins: ['@hey-api/typescript'],
}),
description: 'handles union of primitive types',
},
{
config: createConfig({
input: 'enum-null.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is auto-generated by @hey-api/openapi-ts
export * from './types.gen';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is auto-generated by @hey-api/openapi-ts

export type Foo = {
bar?: number | boolean | string;
};

export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
};
19 changes: 19 additions & 0 deletions packages/openapi-ts-tests/specs/3.1.x/union-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"openapi": "3.1.0",
"info": {
"title": "OpenAPI 3.1.0 union types example",
"version": "1"
},
"components": {
"schemas": {
"Foo": {
"type": "object",
"properties": {
"bar": {
"type": ["number", "boolean", "string"]
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ const parseManyTypes = ({
} else {
const irTypeSchema = parseOneType({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseOneType would mutate the irSchema passed to it, which causes the object pushed to schemaItems all having the same type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explaining! Weird I haven't caught this before, glad you did

context,
irSchema: typeIrSchema,
irSchema: { ...typeIrSchema },
schema: {
...schema,
type,
Expand Down
Loading