-
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
Fix parameter names when using JSON names. #879
Fix parameter names when using JSON names. #879
Conversation
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.
Thanks for this, that looks reasonable! Could we add some tests that cover this? I think the existing framework should allow you to specify this flag.
Codecov Report
@@ Coverage Diff @@
## master #879 +/- ##
==========================================
+ Coverage 52.99% 53.12% +0.13%
==========================================
Files 39 39
Lines 3910 3891 -19
==========================================
- Hits 2072 2067 -5
+ Misses 1642 1630 -12
+ Partials 196 194 -2
Continue to review full report at Codecov.
|
@johanbrandhorst are there any tests that cover the |
I'm not sure, but I think you should be able to copy and modify one of the tests in https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/genswagger/template_test.go. Let me know if you need more assistance. |
I've pushed a test which tests a field with and without I believe the same must be added to: if reg.GetUseJSONNamesForFields() {
kv.Key = f.GetJsonName()
}
if !reg.GetUseJSONNamesForFields() || kv.Key == "" {
kv.Key = f.GetName()
} It was not clear to me how to add a testcase for that. Would you mind making that modification? |
I expect the reason that isn't required is because the JsonName is guaranteed by the protoc compiler. See https://github.com/protocolbuffers/protobuf/blob/f2ef7970fe704c4ec604d39fc1d70bec2c59e4a7/src/google/protobuf/descriptor.proto#L207. You can probably remove it from your test case and the code as well if you wish. Otherwise looks good! |
Ah, I didn't know that. I've removed the fallback :-) |
Great work, thanks for this! |
Thanks for reviewing and your prompt responses! |
* Fix parameter names when using JSON names. * Add test. Fix fallback when `json_name` is unset (query params). * Remove fallback. See grpc-ecosystem#879 (comment).
When using
json_names_for_fields=true
, I noticed that this works fine for field names in the request body when generating Swagger definitions, but URL parameters remainsnake_case
.I believe this should fix it. Looking forward to your feedback.