-
-
Notifications
You must be signed in to change notification settings - Fork 272
Fix: Typescript union types for openapi 3.1 #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Typescript union types for openapi 3.1 #2502
Conversation
|
|
🦋 Changeset detectedLatest commit: ac7efbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@malcolm-kee is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2502 +/- ##
=======================================
Coverage 24.13% 24.13%
=======================================
Files 342 342
Lines 33874 33874
Branches 1454 1454
=======================================
Hits 8174 8174
Misses 25690 25690
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mrlubos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix @malcolm-kee! This is a ridiculously clean pull request. But... how come it fixes things? I'm going to assume there was some mutation happening on the object if it wasn't shallow copied, can you explain?
| if (type === 'null') { | ||
| schemaItems.push({ type: 'null' }); | ||
| } else { | ||
| const irTypeSchema = parseOneType({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
@mrlubos that's right. I assume the code is written this way for performance reason? |
|
@malcolm-kee that's right! |
The generated types for OpenAPI 3.1.x spec is incorrect when the schema type is an array of primitive.