-
-
Notifications
You must be signed in to change notification settings - Fork 528
Add support for x-enum-varnames and x-enum-descriptions #1374
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
Conversation
🦋 Changeset detectedLatest commit: 5d9f276 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 |
.changeset/chilled-news-design.md
Outdated
@@ -0,0 +1,5 @@ | |||
--- | |||
"openapi-typescript": major |
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.
"openapi-typescript": major | |
"openapi-typescript": minor |
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.
done
@@ -229,6 +229,8 @@ export function tsDedupe(types: ts.TypeNode[]): ts.TypeNode[] { | |||
export function tsEnum( | |||
name: string, | |||
members: (string | number)[], | |||
membersNames?: string[], |
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.
membersNames?: string[], | |
metadata?: { name?: string, description?: string }[], |
I think this is an easier-to-use signature; I find the former where multiple ordered params have the same type to be easy to make mistakes in rearranging them.
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.
Agree, done 👍
Great tests! Before we ship this though this will need to be added to the docs somewhere. Perhaps in a section in |
@@ -521,3 +521,44 @@ Cat: { type?: "cat"; } & components["schemas"]["PetCommonProperties"]; | |||
_Note: you optionally could provide `discriminator.propertyName: "type"` on `Pet` ([docs](https://spec.openapis.org/oas/v3.1.0#discriminator-object)) to automatically generate the `type` key, but is less explicit._ | |||
|
|||
While the schema permits you to use composition in any way you like, it’s good to always take a look at the generated types and see if there’s a simpler way to express your unions & intersections. Limiting the use of `oneOf` is not the only way to do that, but often yields the greatest benefits. | |||
|
|||
### Enum with custom names and descriptions |
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.
I didn't come up with something better than copying the existing description from one of the OpenAPI generators projects :)
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.
Looks great to me!
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.
Thanks so much! This will go out in the v7 stable release 🙂
Changes
This MR adds support for
x-enum-varnames
andx-enum-descriptions
fields.x-enum-varnames
is used to set enum members names.x-enum-descriptions
is used to add comments for enum members.Both fields are optional and affect generated code only if they are present in the schema.
How to Review
There are no specific requirements.
The feature is similar to:
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)