Skip to content

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

Conversation

patrick246
Copy link
Contributor

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 and nestedQueryParams and removes a check from updateswaggerObjectFromJSONSchema that assumed no json_name was set and prevented another conversion in renderMessageAsDefinition 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

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.
@google-cla
Copy link

google-cla bot commented Sep 12, 2022

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.

@patrick246
Copy link
Contributor Author

I'll have to debug the failing CLA check tomorrow, there should be a signed corporate CLA in place

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johanbrandhorst
Copy link
Collaborator

Looks like we got a formatting diff in the proto changes, you can fix it with buf format.

@johanbrandhorst
Copy link
Collaborator

@oyvindwe could you please have a look at this as well?

@johanbrandhorst johanbrandhorst merged commit 6dbe965 into grpc-ecosystem:master Sep 14, 2022
@johanbrandhorst
Copy link
Collaborator

Thanks for your contribution!

@patrick246
Copy link
Contributor Author

Hi, are there already plans for releasing this?

@johanbrandhorst
Copy link
Collaborator

Sure, we have a few in-flight PRs (#2928, #2904) but if we don't move forward on those soon I can cut another minor.

another-rex referenced this pull request in google/osv.dev Nov 4, 2022
)

[![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.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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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

- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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 [@&#8203;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 [@&#8203;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
([#&#8203;2817](https://togithub.com/grpc-ecosystem/grpc-gateway/issues/2817))
by [@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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

- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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)
- [@&#8203;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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

protoc-gen-openapiv2 does not respect json_name when generating the required properties
3 participants