-
-
Notifications
You must be signed in to change notification settings - Fork 505
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 colliding enumValues exports #2051
Conversation
🦋 Changeset detectedLatest commit: 9b38b53 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 |
7a8b70f
to
0abed11
Compare
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.
Same as the other PR—would love to use this as the base for 8.x. Thank you for adding such a big improvement to the library!
This can merge into 8.x with the minor conflict resolved (apologies if I merged them out-of-order)
0838a67
to
c0a74fe
Compare
* Add schema to postTransform options Closes openapi-ts#2013 * fixup! Add schema to postTransform options Closes openapi-ts#2013 * fixup! Add schema to postTransform options Closes openapi-ts#2013 * fixup! Add schema to postTransform options
* Only check GitHub token for docs build when update needed * Add Netlify badge * Use link
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
c0a74fe
to
5b0cbf9
Compare
Preserve capitalization of named, exported enum values. Type exported const values as const, instead of their location within the operations or components schemas. Derive and export types for enum values from concrete values in const arrays. Use derived enum value types in operations and components schemas. Use non-conflicting variable names for composed OpenAPI enums (anyOf: [enum1, enum2])
5b0cbf9
to
9b38b53
Compare
I rebased this off of |
Ah yeah no worries. 8.x may diverge from |
🗣️ Discussion
This work stemmed from an error encountered when using
enumValues: true
, and escalated from there.🐞 The bugs
💨 Non-exhaustive types
The existing values exported when using
enumValues
express their type relative to the union defined in the TS schema.Instead, if we start with an exhaustive concrete value, the union type can be derived.
➕ Composing OpenAPI enums generates conflicting variable names
Given the following schema composing two enum schemas, the following bad code is generated.
By unifying the enum member and literal string traversal + generation paths, I was able to generate non-conflicting export names.
Changes
How to Review
enum: true
. Since enums aren't composable, we still generate nonsense code likeModeratedStatus: components["schemas"]["Status"] | ModeratedStatusAnyOf1;
(see the node-utilsoptions > enum
case for this example. This isn't resolved by this PR, and may be entirely unresolvable.sanitizeMemberName
and using it intransformers/schema-object
. That alone makes this a breaking change.as const
style literals may not be for everyone, though I've found them to be succinct, reliable, and versatile for composition (literal and type-level) and iteration.Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)