Skip to content

Commit

Permalink
log warning if a service method has no HTTP rule
Browse files Browse the repository at this point in the history
The original intention was to make this an error too,
but that would break example generation badly.
  • Loading branch information
andrascz authored and johanbrandhorst committed Mar 17, 2020
1 parent 63d1fcc commit ee51345
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion protoc-gen-grpc-gateway/descriptor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *Registry) loadServices(file *File) error {
optsList = append(optsList, opts)
}
if len(optsList) == 0 {
glog.V(1).Infof("Found non-target method: %s.%s", svc.GetName(), md.GetName())
glog.Warningf("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName())
}
meth, err := r.newMethod(svc, md, optsList)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions protoc-gen-grpc-gateway/descriptor/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,65 @@ func TestExtractServicesSimple(t *testing.T) {
testExtractServices(t, []*descriptor.FileDescriptorProto{&fd}, "path/to/example.proto", file.Services)
}

func TestExtractServicesWithoutAnnotation(t *testing.T) {
src := `
name: "path/to/example.proto",
package: "example"
message_type <
name: "StringMessage"
field <
name: "string"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
>
>
service <
name: "ExampleService"
method <
name: "Echo"
input_type: "StringMessage"
output_type: "StringMessage"
>
>
`
var fd descriptor.FileDescriptorProto
if err := proto.UnmarshalText(src, &fd); err != nil {
t.Fatalf("proto.UnmarshalText(%s, &fd) failed with %v; want success", src, err)
}
msg := &Message{
DescriptorProto: fd.MessageType[0],
Fields: []*Field{
{
FieldDescriptorProto: fd.MessageType[0].Field[0],
},
},
}
file := &File{
FileDescriptorProto: &fd,
GoPkg: GoPackage{
Path: "path/to/example.pb",
Name: "example_pb",
},
Messages: []*Message{msg},
Services: []*Service{
{
ServiceDescriptorProto: fd.Service[0],
Methods: []*Method{
{
MethodDescriptorProto: fd.Service[0].Method[0],
RequestType: msg,
ResponseType: msg,
},
},
},
},
}

crossLinkFixture(file)
testExtractServices(t, []*descriptor.FileDescriptorProto{&fd}, "path/to/example.proto", file.Services)
}

func TestExtractServicesCrossPackage(t *testing.T) {
srcs := []string{
`
Expand Down

0 comments on commit ee51345

Please sign in to comment.