-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Option for omitting zero enum value from generated Swagger #888
Comments
Thanks for the detailed feature request. I think this sounds okay, but you're sure you want it as an annotation rather than a generator option to remove all the zero enums in a document? |
Well, I think all of the enums in my proto files would benefit from this behavior, but there could be enums where there is a natural default (or the zero value is otherwise valid/intentional), and you could imagine some project having a mix of those two cases. |
Considering you're the first to ask for this, if it's good enough for you it's probably good enough for an MVP :). Do you intend to submit a PR to cover this behaviour change? |
If a PR for adding the generator command-line flag would be well-received, I can try to take a stab at it at some point :-) |
I assure you it would be well received 😁 |
Any news on this? |
We would love to have this capability too. Just thought I'll chime in a +1 vote. Any plans on doing this anytime soon? |
I don't know of anyone working actively on this at this time. Would you like to contribute this feature? |
Hi, I'd like to work on this if possible. |
Sure, do you need anymore information than what is covered in the issue already? A command line flag would mean adding an entry here: grpc-gateway/protoc-gen-openapiv2/main.go Lines 17 to 39 in c52fba1
|
Thanks @johanbrandhorst. |
It's pretty typical practice in proto APIs for enum types with no natural default to declare the 0 value as UNKNOWN (or similar). Often UNKNOWN is not a valid option, but is declared to differentiate the "unset" case.
JSON semantics are different: The "unset" case is explicit, because the field is not present in the map object.
Currently, the generated Swagger spec exposes such an "UNKNOWN" option as a legitimate choice, and records it as the default choice. For cases where "UNKNOWN" is not a legitimate choice and should not be recorded as such in API docs/generated client code.
Bug reports:
Fill in the following sections with explanations of what's gone wrong.
Steps you follow to reproduce the error:
Example input:
Current Swagger type definition output:
What did you expect to happen instead:
An annotation or other option to emit:
What's your theory on why it isn't working:
Current behavior is the safe default.
An option to adjust this would most likely take the form of a new EnumOption annotation, with boolean field
omit_default
or similar to control this behavior: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/options/annotations.protoThe text was updated successfully, but these errors were encountered: