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
Support request header parameters #3010
Support request header parameters #3010
Conversation
986694c
to
93e49cf
Compare
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.
Thanks a lot for looking at this! Some minor comments, but in addition to those please add a section to the docs about this ✨ new feature ✨. This sort of thing has been requested a lot, thanks for helping bring it over the line. Please ensure the docs make it clear that adding headers to your schema via these annotations does nothing to change the behavior of the gateway and that these annotations should only be coupled with custom header parsing behavior in the application. Also that adding header parameters can chance the forward and backward compatibility guarantees of the schema. Thanks!
Co-Authored-By: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
964f82f
to
b3a8280
Compare
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 code changes look fine but could you please add something to the docs as well? Also, it looks like you need to regenerate the files again 😁.
@johanbrandhorst added documentation & regenerated the go code. I noticed when I run |
Just running |
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.
LGTM
I think this is one of the most user requested features, so thank you for this great contribution! I'll consider making a new release shortly. |
) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/grpc-ecosystem/grpc-gateway/v2](https://togithub.com/grpc-ecosystem/grpc-gateway) | require | minor | `v2.13.0` -> `v2.14.0` | --- ### Release Notes <details> <summary>grpc-ecosystem/grpc-gateway</summary> ### [`v2.14.0`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.14.0) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.13.0...v2.14.0) #### New features This release contains two significant new OpenAPIv2 generator features, contributed by [@​krak3n](https://togithub.com/krak3n): 1. A new option to [disable rendering of 200 OK responses](https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/customizing_openapi_output/#disable-default-responses). This is useful if you define custom responses for your endpoints and you modify the return code a forward response writer. Note that this does not change the behavior of the gateway itself. 2. A new annotation for [defining header parameters](https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/customizing_openapi_output/#custom-http-header-request-parameters). This lets to define header parameters you want to be rendered in the swagger.json output in addition to those defined in your API messages. Note that this does not change the behavior of the gateway itself and must be coupled with custom header parsing in your application. #### What's Changed - release: Update release.yml with option to workaround SLSA generator failure by [@​asraa](https://togithub.com/asraa) in [grpc-ecosystem/grpc-gateway#2987 - release: add a workflow_dispatch trigger for testing by [@​asraa](https://togithub.com/asraa) in [grpc-ecosystem/grpc-gateway#2989 - Use io/os instread of ioutil and use suitable verb by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#2991 - runtime pkg cleanup by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#2993 - mux: fix path components mutation by [@​jonathaningram](https://togithub.com/jonathaningram) in [grpc-ecosystem/grpc-gateway#3001 - fix: set consumes definition per operation by [@​stomy13](https://togithub.com/stomy13) in [grpc-ecosystem/grpc-gateway#2995 - protoc gen oas v2 cleanup by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#2996 - Use ReplaceAll instead of Replace with -1 pos by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#3003 - Errors cleanup by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#3004 - Cleanup by [@​sashamelentyev](https://togithub.com/sashamelentyev) in [grpc-ecosystem/grpc-gateway#3012 - Support disabling default response rendering by [@​krak3n](https://togithub.com/krak3n) in [grpc-ecosystem/grpc-gateway#3006 - Support request header parameters by [@​krak3n](https://togithub.com/krak3n) in [grpc-ecosystem/grpc-gateway#3010 #### New Contributors - [@​asraa](https://togithub.com/asraa) made their first contribution in [grpc-ecosystem/grpc-gateway#2987 - [@​sashamelentyev](https://togithub.com/sashamelentyev) made their first contribution in [grpc-ecosystem/grpc-gateway#2991 - [@​stomy13](https://togithub.com/stomy13) made their first contribution in [grpc-ecosystem/grpc-gateway#2995 - [@​krak3n](https://togithub.com/krak3n) made their first contribution in [grpc-ecosystem/grpc-gateway#3006 **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.13.0...v2.14.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on monday" in timezone Australia/Sydney, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/google/osv.dev). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4zNy4wIiwidXBkYXRlZEluVmVyIjoiMzQuMzcuMCJ9-->
Thanks @krak3n |
hi @amitavaghosh1 @johanbrandhorst if I have a HTTP header that is used across all API (not for security), is there any way to use something like this in swagger.
I was thinking about doing such thing on the operation
|
Fixes #2932
Feature 🚀
Adds support for optional HTTP request header parameters to be defined on method operations, for example:
This should generate the following
yaml
:Changes