-
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-swagger: json_names_for_fields=true does not respect json_name for path parameters #1084
Comments
v1.9.6 changes the URL parameter naming. The updated naming does not respect the `json_name` in the Protobuf file. See also: grpc-ecosystem/grpc-gateway#1084.
Thanks for the report @brocaar, as you surmise this is because of a complex interaction between the two different parsers we have, the URL path/query parameter parser and the JSON content parser. It's not an easy fix unfortunately, as you'll need to build the JSON options into the URL path and query parameter parsing. |
Thanks for the quick response @johanbrandhorst . Please note that this only seems to affect the path parameters, I believe the query parameters are named as expected and do respect the I'm not 100% familiar all the internal logic, I would need to dive in deeper. However, the code does generate: "parameters": [
{
"name": "devEui",
"description": "Device EUI (HEX encoded).",
"in": "path",
"required": true,
"type": "string"
}
], Since it is able to read the description from the Protobuf file, wouldn't that mean that it would be possible to iterate over the fields in the Protobuf message find the field ( |
Try it :). I don't know what issues you might run into. |
@brocaar , Thanks for pointing it out! I will look into the code. |
@brocaar , @johanbrandhorst , just created a PR for this: #1085 |
* Support reserved json name and add tests * Correct some variable names * Optimize a logic for assigning a reserved json name to jsonCamelCaseName * Put a logic for checking if there is a reseved json name in the method of lowerCamelCase Fixes grpc-ecosystem#1084
I'm using the
json_names_for_fields=true
option and am seeing inconsistent results, specifically between the URL parameter names and the names in the request / response bodies. Example:I believe this is because the fieldnames in the request / response body are get using the
f.GetJsonName()
(e.g. https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/genswagger/template.go#L342) where the URL parameter names are get using thelowerCamelCase
function (e.g. https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/genswagger/template.go#L772).The
json_name
is respected by theGetJsonName()
function (e.g.[json_name = "devEUI"]
, but not by thelowerCamelCase
function.The generated Swagger JSON looks like:
I would have expected:
Note that the camel casing for URL parameters was implemented in v1.9.6 (#986). Before this version URL parameters were always using the Protobuf name (in the above example it would have been
dev_eui
).@xin-au since you have worked on #986, do you think this would be easy to fix? I think instead of generating the name using the
lowerCamelCase
function and replicate the Protobuf (default) JSON naming convention, it would be better to somehow lookup the Protobuf field object and call itsGetJsonName
method.The text was updated successfully, but these errors were encountered: