-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 does not respect json_name when generating the required properties #2874
Comments
Found a TODO comment for exactly this issue:
It also seems that it only accidentally worked for us in 2.7.3 and before, as we always had protobuf name = json name. |
Thanks for the bug report, and sorry about breaking your use case 😞. It sounds like you're already making good progress on a fix, is there anything I can do to help? CC @oyvindwe |
I investigated this when working on PR #2553. This was a partial fix for some cases where |
No worries, it looks like it was already broken before, just in the other direction.
My current plan would be to move the conversion of the required fields part out of |
@patrick246 I wish I had enough context on this code to say, but throw up a PR with some tests and lets see! |
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.
…mes (#2885) * protoc-gen-openapiv2: Use json_name when generating required field names 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. * Reformat protobuf * Fix failing test * Replace unclear condition when checking required query params Regenerate files, fix formatting
🐛 Bug Report
Starting with protoc-gen-openapiv2 v2.8.0, the generated OpenAPIv2 schema is generated incorrectly when using the
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema
option, together withjson_name
. The properties section uses the name from the json_name annotation, but the required section uses the autogenerated name instead.To Reproduce
I've tested this with multiple versions, the behavior between latest (v2.11.3 currently) and v2.8.0 does not change, this is the first version with the current behavior.
Protobuf file:
Project setup for v2.8.0:
Project setup for v2.7.3:
Expected behavior
The generated OpenAPIv2 spec is generated like in v2.7.3:
Actual Behavior
Instead the required section of the generated schema references a property with the wrong (autogenerated) name:
Diff between expected and actual:
Your Environment
MacOS Big Sur (11.6.8), go1.19 darwin/amd64, grpc-gateway versions v2.11.3, v2.8.0 and v2.7.3
The text was updated successfully, but these errors were encountered: