Support generating enum varnames/descriptions#1540
Open
zackyancey wants to merge 2 commits intojuhaku:masterfrom
Open
Support generating enum varnames/descriptions#1540zackyancey wants to merge 2 commits intojuhaku:masterfrom
zackyancey wants to merge 2 commits intojuhaku:masterfrom
Conversation
This lets a builder build up extensions incrementally instead of with just one call to extensions, which is helpful for some automatically-added extensions.
This addresses juhaku#1317. `x-enum-varnames` and `x-enum-descriptions` are commonly used extensions, especially for enums with a numeric representation. This adds options to generate both of those values, so an enum like this: ```rust #[schema(repr, enum_varnames, enum_descriptions)] #[repr(u8)] pub enum MyEnum { /// Value A A = 0, /// Value B B = 1, /// Value C C = 2, } ``` Will have a schema like this: ```json { "type": "integer", "enum": [ 0, 1, 2 ], "x-enum-varnames": [ "A", "B", "C" ], "x-enum-descriptions": [ "Value A", "Value B", "Value C" ] } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses #1317.
x-enum-varnamesandx-enum-descriptionsare commonly used extensions,especially for enums with a numeric representation. This adds options to generate
both of those values, so an enum like this:
Will have a schema like this:
{ "type": "integer", "enum": [ 0, 1, 2 ], "x-enum-varnames": [ "A", "B", "C" ], "x-enum-descriptions": [ "Value A", "Value B", "Value C" ] }(Note that this example uses the
#[schema(repr)]syntax from this PR, just because theenum_varnamesfeature makes most sense with a numerical enum. The two branches aren't dependent on each other though.)