Closed seanlaff closed 4 years ago
If we wanted to be a little more specific and bound the error type to the 400/500 range, maybe we can use the status code range syntax that the spec defines, i.e 5XX
, although I think thats a little less common?
Hi Sean!
To be pedantic, we only support swagger 2, but happily the default
field of the responses
object is a thing in 2.0 as well, so no worries!
This makes great sense to me, and shouldn't break any existing users. I'd be happy to review this if you have spare cycles to contribute this. I'm not sure we need to export the type, unless you mean just to the swagger generator? We could still solve that with an internal package, which I'd prefer to adding to the API surface.
If we wanted to be a little more specific and bound the error type to the 400/500 range, maybe we can use the status code range syntax that the spec defines, i.e 5XX, although I think thats a little less common?
I think we can keep it as the default, we already allow users to specify custom responses, so really anything that isn't defined should be an error.
@johanbrandhorst I think that adding this default to all responses without a config option is a bit aggressive - for example, we have a custom error handler that translates an internal error details message into an RFC7807 https://tools.ietf.org/html/rfc7807 response for our REST clients (and so this default misrepresents the error format we return to clients)
Argh, I did know this would be incorrect for those with custom error handlers, but I figured it was better than nothing. I agree it should be possible to turn this off... I'll add something.
The gateway has an error object which any rpc can return- however it doesn't end up in the generated swagger/openapi.
https://github.com/grpc-ecosystem/grpc-gateway/blob/2da5bfafe05e07c9401137126e55eb0ca4f76472/runtime/errors.go#L68-L76
OpenAPI's pattern for something like this is to include it as the
default
case. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#responses-objectCan we do the following?
With an entry in
schemas
for the new type:I wrote some jq to handle this in the meantime:
Not sure all that's required to make this change. I think at the least the errorBody struct would need to be made public. Thoughts?