Skip to content
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

Use json camel case when GetUseJSONNamesForFields is enabled #985

Merged
merged 10 commits into from
Aug 9, 2019
16 changes: 11 additions & 5 deletions protoc-gen-grpc-gateway/descriptor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (r *Registry) loadServices(file *File) error {
for _, sd := range file.GetService() {
glog.V(2).Infof("Registering %s", sd.GetName())
svc := &Service{
File: file,
File: file,
ServiceDescriptorProto: sd,
}
for _, md := range sd.GetMethod() {
Expand Down Expand Up @@ -258,10 +258,16 @@ func (r *Registry) newResponse(meth *Method, path string) (*Body, error) {

// lookupField looks up a field named "name" within "msg".
// It returns nil if no such field found.
func lookupField(msg *Message, name string) *Field {
func (r *Registry) lookupField(msg *Message, name string) *Field {
for _, f := range msg.Fields {
if f.GetName() == name {
return f
if r.GetUseJSONNamesForFields() {
if f.GetJsonName() == name {
return f
}
} else {
if f.GetName() == name {
return f
}
}
}
return nil
Expand Down Expand Up @@ -291,7 +297,7 @@ func (r *Registry) resolveFieldPath(msg *Message, path string, isPathParam bool)
}

glog.V(2).Infof("Lookup %s in %s", c, msg.FQMN())
f := lookupField(msg, c)
f := r.lookupField(msg, c)
if f == nil {
return nil, fmt.Errorf("no field %q found in %s", path, root.GetName())
}
Expand Down