Closed

Description
Steps you follow to reproduce the error:
Create the following proto file:
syntax = "proto3";
package sample;
import "google/api/annotations.proto";
service AvailabilityGroup {
rpc GetParent(GetParentRequest) returns (GetParentResponse) {
option (google.api.http) = {
get: "/api/v3/availabilityGroup/{xid}/parent"
};
}
}
message GetParentRequest {
string xid = 1;
}
message GetParentResponse {
string name = 1;
}
Run protoc to generate the swagger for the service, observe the following panic:
panic: runtime error: index out of range [1] with length 0
goroutine 1 [running]:
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger.templateToSwaggerPath(0xc0000b3230, 0x26, 0xc0000f28c0, 0x0, 0x0)
/Users/bob_allison/go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go:688 +0xc38
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger.renderServices(0xc0000b44b0, 0x1, 0x1, 0xc0001d6000, 0xc0000f28c0, 0xc0001dee20, 0xc0001dedf0, 0x2e00000008, 0x8)
/Users/bob_allison/go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go:732 +0x10f1
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger.applyTemplate(0xc0001b3780, 0xc0000f28c0, 0xc000169df0, 0x0, 0x1)
/Users/bob_allison/go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/template.go:1066 +0x357
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger.(*generator).Generate(0xc0000b4310, 0xc0000b44b8, 0x1, 0x1, 0x1, 0xc0000b44b8, 0x0, 0x1, 0x340)
/Users/bob_allison/go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger/generator.go:188 +0x6d9
main.main()
/Users/bob_allison/go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/main.go:119 +0x7fb
--swagger_out: protoc-gen-swagger: Plugin failed with status code 2.
What did you expect to happen instead:
Creation of the apidocs file
What's your theory on why it isn't working:
The regexp object canRegexp
does not differentiate between parent
and {parent}
, returning parent
in both cases. This causes the test on line 686 to be incorrectly true leading to parsing the string on line 687 which results in an empty slice. The panic occurs when line 688 tries to read the second element of the slice without first checking the length.
Metadata
Metadata
Assignees
Labels
No labels