grpc-gateway
grpc-gateway copied to clipboard
Add enum type to defintions in swagger/openapi files if they do not appear in a message.
🚀 Feature
Looking to export a set of enum values for our API consumers to understand the type of error that is occurring. Currently we are just appending a set of constant keys to status errors.Aborted with errdetails of type ErrInfo. Since the error spec returns type Any
for details we aren't able to provide a list to our consumers of different error keys.
We are duplicating what is done for ErrorInfo and the example enum for our own domain.
Since the enum isn't directly exported in any message it obviously isn't showing up in the definitions of the swagger/openapi spec files. Is there a way of adding enums to the definitions of the spec file that's generated if they aren't part of any message?
Thank you in advance if this is an already existing feature that I haven't been able to figure out.
I believe that you should be able to do this by specifying a custom response schema. See https://github.com/grpc-ecosystem/grpc-gateway/blob/063d62321ae7e7fddbe89b0daa08a47843b4275e/examples/internal/proto/examplepb/a_bit_of_everything.proto#L151-L169 for an example of this. You can specify your ErrInfo type and it'll automatically render any dependent types (including your enum). Bonus, your error response will now show up in your swagger file too!
Let me know if that doesn't solve your problem.