-
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
protoc-gen-openapiv2: json_names_for_fields=true can generate invalid OpenAPI output #2363
Comments
Hi Roger, good to see you in our neck of the woods 😁. That certainly looks like a bug, and I think it's probably because of this line:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Go away stalebot. |
I'm not sure if it is the path template that is wrong or the parameter name (or both). What are the expected JSON field names for
I could argue for any of these 3 variants: I guess what matters is how is this implemented (for query parameters and JSON fields) in the actual gateway (grpc-gateway as well as ESPv1 and ESPv2). |
Preserve uppercase characters is probably the safe choice, given that the original proto field must be supported. However, that may lead to problems if combining with |
I could take a stab at this if I get help to figure out the expected casing. Do you know, @rogpeppe or @johanbrandhorst? |
I believe https://github.com/protocolbuffers/protobuf-go/blob/3992ea83a23c00882339f33511074d251e19822c/internal/strs/strings.go#L92-L106 is the canonical mapping function that |
It doesn't look like a license violation to copy the above method, but copyright notice has to be copied as well to relevant places. Is this acceptable? |
Yes, that sounds good to me |
🐛 Bug Report
With
json_names_for_fields=true
(the default), some parameter names cause the generated OpenAPI JSON to contain parameter name mismatches.To Reproduce
Create an
example.proto
file with the following content:Copy the
third_party
directory from thegithub.com/grpc-ecosystem/grpc-gateway
repository into a localthird_party
directory.Generate the OpenAPI JSON by running:
Run the generated
example.swagger.json
file through an OpenAPI verifier, such as https://editor.swagger.io/.Expected behavior
I'd expect the verification to succeed (i.e. the generated OpenAPI should be valid).
Actual Behavior
There is an inconsistency between the parameter names in the URL and those in the
parameters
field.For example:
OpenAPI parameters are case sensitive.
Here's an example of the reported errors:
(as an aside:
iD
is not a great spelling for the JSON name).Your Environment
I'm using github.com/grpc-ecosystem/grpc-gateway/v2 at v2.5.0 under Ubuntu.
The text was updated successfully, but these errors were encountered: