-
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
protoc-gen-swagger: Support Response-specific examples #1117
Comments
This SGTM, I guess we have to copy the values verbatim into the output swagger definition. Would you be interested in implementing this? |
I would like to, though history suggests I should be skeptical of my availability to do so (see #888, #877 ). I may be able to get this one prioritized though because it's harder than those to temporarily patch over using jq-based post-processing. I expect this would be a pretty simple case of piping the new input field into the output Swagger? |
The only thing I might like to discuss before launching into implementation is whether we should simplify the input to be
would simplify applications of the annotation from
to
While that seems like a small thing, we're already struggling a bit in practice with the verbosity / trickiness of the openapi mapping annotations, and keeping this bit simpler would be a win. What do you think @johanbrandhorst ? Note the proposed alternative name |
I invite @ivucica to this discussion, he has more opinions/knowledge than I in this area specifically, but I think we want to keep the mapping between the swagger proto spec and the swagger 2.0 as 1:1 as possible, and adding a field On the implementation side, it sounds like it shouldn't be too bad, touch wood! Thanks again for your interest in the project. |
Agreed, the clarity value of maintaining direct correspondence with the Swagger standard probably does win out here. It would be nice if text-format protobuf allowed writing maps more succinctly (for this and other applications), but that is out of scope here and we shouldn't try to work around it in the message definitions.
|
Add support for examples in operation annotation responses. Merge custom response data into the default 200 response.
Hey @johanbrandhorst, I put up a PR for this: #1124 |
) * Fix grpc-ecosystem#1117: Support response examples. Add support for examples in operation annotation responses. Merge custom response data into the default 200 response. * Regenerate files. * Documentation improvements.
) * Fix grpc-ecosystem#1117: Support response examples. Add support for examples in operation annotation responses. Merge custom response data into the default 200 response. * Regenerate files. * Documentation improvements.
Swagger 2.0 supports specifying a per-mimetype response example for a given operation:
https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#responseObject
https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#exampleObject
This allows displaying a per-operation example for a given response schema, typically overriding any example specified on the response schema type definition in generated documentation. This is useful for clearly documenting workflows where the same schema type is returned with varied or evolving state/status.
This capability seems to have been anticipated but left unimplemented in the protobuf annotation types used by grpc-gateway:
grpc-gateway/protoc-gen-swagger/options/openapiv2.proto
Line 87 in 29dafe9
This issue is a feature request for the addition of that capability.
I propose that the added field be structured like
to support the specification's requirement of mapping mime types to examples, and to match the pattern string-based example value specification elsewhere in the grpc-gateway annotations (see https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#example-object-example )
The text was updated successfully, but these errors were encountered: