-
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
Add support for OpenAPI YAML annotations #1665
Conversation
I think this is ready for review, though I can't quite figure how to fix the generate CI test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is an amazing achievement! Well done! I'd like to see an example of these new annotations in action, do you think you could add some annotations to the unannotated_echo_service.yaml
to show users how to use these new annotations, and as a test to see that it generates correctly?
The generation error is because of a dependency issue in the generation job - make realclean
deletes all the generated files, and then make examples
tries to install the generators before regenerating the files - but now the grpc-gateway generator depends on the generated openapi options, so we can't build it. We'll probably have to split up cleaning and building, so that we can still have the confidence that the generated files are the same as are checked into the repo (by deleting and regenerating). There is a bit of an interesting chicken-and-egg problem here though in that we can't be sure that the files we regenerated are correct until we've regenerated them and reinstalled the generators and generated them again, since what if the generator was built with an old generated file?
Another option which is tempting is to remove the dependency on protoc-gen-openapiv2 options from protoc-gen-grpc-gateway
. This seems a bit of a weird dependency anyway, and the part of apiconfig that needs the new options is actually unused by protoc-gen-grpc-gateway
. We may need to split the packages.
What do you think?
Sure. Should I also add options inline to echo_service.proto to maintain parity between the annotated and unannotated versions for the messages and services that are in both the annotated and unannotated protos?
Splitting the package up makes sense to me. Would moving the OpenAPI config options to github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/openapiconfig" suffice? |
Looks like I'm a bit confused at how |
Turns out that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The final step would be to add a little blurb about these new capabilities to the docs - we already have a page for the grpc api configuration and it would make sense to add this to that page. The docs can be found in the /docs subfolder, and are simple markdown documents.
Thanks again for this work, it's really appreciated!
Hi, I merged a generator update so you'll need to rebase on v2, sorry for the inconvenience 😬. |
Don't set the method option "tag" so examples/internal/clients/unannotatedecho/api/swagger.yaml generates a examples/internal/clients/unannotatedecho/api_unannotated_echo_service.go that works with existing tests.
No problem! I rebased and updated the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small thoughts on the new docs and how we want to display the protoc invocations. Great work on this Jason!
Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
What do you think about moving openapiconfig.proto to an exported package instead of under internal? My idea is that it would make generating OpenAPI annotations easier if you could fill out the struct in Go, then marshal to JSON and then to YAML instead of having to work with templates. |
I'd like to limit our API surface as much as possible. I see the benefit of what you're saying, but I'd be more inclined to let users copy the generated struct for their internal use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you so much for your work!
I'm going to make another beta release of v2 once we've cherry picked the new unbound method generator, we've had some incredible contributions lately, yours definitely among them! |
Thanks for being so responsive to review requests, Johan! Happy to contribute. |
References to other Issues or PRs
Fixes #701
Have you read the Contributing Guidelines?
Yep
Brief description of what is fixed or changed
Added support for passing OpenAPI/Swagger annotations in YAML file to protoc-gen-openapiv2
Other comments
Extended template tests that tested proto options to set options via registry.