-
Notifications
You must be signed in to change notification settings - Fork 2.3k
protoc-gen-openapiv2: Use json_name when generating required field names #2885
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-openapiv2: Use json_name when generating required field names #2885
Conversation
Fix the bug from grpc-ecosystem#2874 where the required fields section in the JSON schema would contain autogenerated field names, even when fields had a custom json_name value set. These would then not match up with the actual fields defined in the schema, resulting in an invalid OpenAPI spec.
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
I'll have to debug the failing CLA check tomorrow, there should be a signed corporate CLA in place |
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
Looks like we got a formatting diff in the proto changes, you can fix it with |
@oyvindwe could you please have a look at this as well? |
Regenerate files, fix formatting
Thanks for your contribution! |
Hi, are there already plans for releasing this? |
) [](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.11.3` -> `v2.13.0` | --- ### Release Notes <details> <summary>grpc-ecosystem/grpc-gateway</summary> ### [`v2.13.0`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.13.0) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.12.0...v2.13.0) #### What's Changed - Updated gRPC code Cancelled replaced with HTTP code 499 by [@​tech-sumit](https://togithub.com/tech-sumit) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2957](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2957) - fix: remove default service tag generation for methods by [@​kkolur](https://togithub.com/kkolur) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2960](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2960) - Use tag instead of has pin for SLSA generator by [@​laurentsimon](https://togithub.com/laurentsimon) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2969](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2969) - Add Conduit to adopters by [@​hariso](https://togithub.com/hariso) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2981](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2981) - feat(gen-openapiv2): support trailing comments by [@​ionling](https://togithub.com/ionling) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2965](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2965) - feat(gen-openapiv2): keep fields next to "$ref" fields by [@​gostajonasson](https://togithub.com/gostajonasson) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2986](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2986) #### New Contributors - [@​tech-sumit](https://togithub.com/tech-sumit) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2957](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2957) - [@​hariso](https://togithub.com/hariso) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2981](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2981) - [@​ionling](https://togithub.com/ionling) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2965](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2965) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.12.0...v2.13.0 ### [`v2.12.0`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.12.0) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.11.3...v2.12.0) #### What's Changed - fix: support for oneof fields in request bodies by [@​isbang](https://togithub.com/isbang) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2867](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2867) - mux: calculate verb correctly for cases like DELETE /foo/bar:archive when user provided wrong method by [@​jonathaningram](https://togithub.com/jonathaningram) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2870](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2870) - Update googleapis dependency by [@​johanbrandhorst](https://togithub.com/johanbrandhorst) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2875](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2875) - protoc-gen-openapiv2: RPC visibility setting transitively applied to messages by [@​erademacher](https://togithub.com/erademacher) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2880](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2880) - protoc-gen-openapiv2: Use json_name when generating required field names by [@​patrick246](https://togithub.com/patrick246) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2885](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2885) - fix: support service tags in OpenAPI config file ([#​2817](https://togithub.com/grpc-ecosystem/grpc-gateway/issues/2817)) by [@​y-takuya](https://togithub.com/y-takuya) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2858](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2858) - feat: add option to disable rendering of service tags by [@​kkolur](https://togithub.com/kkolur) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2928](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2928) - fix: required properties of message type are required in OpenAPI by [@​gostajonasson](https://togithub.com/gostajonasson) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2904](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2904) - feat: add option to add description to tags by [@​same-id](https://togithub.com/same-id) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2939](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2939) - add extensions for Tag object by [@​kkolur](https://togithub.com/kkolur) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2950](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2950) - Make registry load packages deterministically by [@​gonzaloserrano](https://togithub.com/gonzaloserrano) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2945](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2945) #### New Contributors - [@​erademacher](https://togithub.com/erademacher) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2880](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2880) - [@​patrick246](https://togithub.com/patrick246) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2885](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2885) - [@​y-takuya](https://togithub.com/y-takuya) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2858](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2858) - [@​kkolur](https://togithub.com/kkolur) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2928](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2928) - [@​gostajonasson](https://togithub.com/gostajonasson) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2904](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2904) - [@​same-id](https://togithub.com/same-id) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2939](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2939) - [@​gonzaloserrano](https://togithub.com/gonzaloserrano) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/2945](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/2945) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.11.3...v2.12.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:eyJjcmVhdGVkSW5WZXIiOiIzMi4yNDEuOSIsInVwZGF0ZWRJblZlciI6IjM0LjEyLjAifQ==--> Co-authored-by: Rex P <[email protected]>
References to other Issues or PRs
Fixes #2874
Have you read the Contributing Guidelines?
yes
Brief description of what is fixed or changed
Fix the bug from #2874 where the required fields section in the JSON schema would contain autogenerated field names, even when fields had a custom json_name value set. These would then not match up with the actual fields defined in the schema, resulting in an invalid OpenAPI spec.
This adds checks if we need to convert Protobuf field names into JSON field names in template.go
schemaOfField
andnestedQueryParams
and removes a check fromupdateswaggerObjectFromJSONSchema
that assumed no json_name was set and prevented another conversion inrenderMessageAsDefinition
from working.The PR also contains additions to the tests for functions that were modified, in addition to examples in
a_bit_of_everything.proto
.Other comments