Skip to content

Commit ee51345

Browse files
andrasczjohanbrandhorst
authored andcommitted
log warning if a service method has no HTTP rule
The original intention was to make this an error too, but that would break example generation badly.
1 parent 63d1fcc commit ee51345

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

protoc-gen-grpc-gateway/descriptor/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *Registry) loadServices(file *File) error {
3535
optsList = append(optsList, opts)
3636
}
3737
if len(optsList) == 0 {
38-
glog.V(1).Infof("Found non-target method: %s.%s", svc.GetName(), md.GetName())
38+
glog.Warningf("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName())
3939
}
4040
meth, err := r.newMethod(svc, md, optsList)
4141
if err != nil {

protoc-gen-grpc-gateway/descriptor/services_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,65 @@ func TestExtractServicesSimple(t *testing.T) {
219219
testExtractServices(t, []*descriptor.FileDescriptorProto{&fd}, "path/to/example.proto", file.Services)
220220
}
221221

222+
func TestExtractServicesWithoutAnnotation(t *testing.T) {
223+
src := `
224+
name: "path/to/example.proto",
225+
package: "example"
226+
message_type <
227+
name: "StringMessage"
228+
field <
229+
name: "string"
230+
number: 1
231+
label: LABEL_OPTIONAL
232+
type: TYPE_STRING
233+
>
234+
>
235+
service <
236+
name: "ExampleService"
237+
method <
238+
name: "Echo"
239+
input_type: "StringMessage"
240+
output_type: "StringMessage"
241+
>
242+
>
243+
`
244+
var fd descriptor.FileDescriptorProto
245+
if err := proto.UnmarshalText(src, &fd); err != nil {
246+
t.Fatalf("proto.UnmarshalText(%s, &fd) failed with %v; want success", src, err)
247+
}
248+
msg := &Message{
249+
DescriptorProto: fd.MessageType[0],
250+
Fields: []*Field{
251+
{
252+
FieldDescriptorProto: fd.MessageType[0].Field[0],
253+
},
254+
},
255+
}
256+
file := &File{
257+
FileDescriptorProto: &fd,
258+
GoPkg: GoPackage{
259+
Path: "path/to/example.pb",
260+
Name: "example_pb",
261+
},
262+
Messages: []*Message{msg},
263+
Services: []*Service{
264+
{
265+
ServiceDescriptorProto: fd.Service[0],
266+
Methods: []*Method{
267+
{
268+
MethodDescriptorProto: fd.Service[0].Method[0],
269+
RequestType: msg,
270+
ResponseType: msg,
271+
},
272+
},
273+
},
274+
},
275+
}
276+
277+
crossLinkFixture(file)
278+
testExtractServices(t, []*descriptor.FileDescriptorProto{&fd}, "path/to/example.proto", file.Services)
279+
}
280+
222281
func TestExtractServicesCrossPackage(t *testing.T) {
223282
srcs := []string{
224283
`

0 commit comments

Comments
 (0)