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

Unable to create HTTP mapping with "/parent" #1079

Closed
ghost opened this issue Nov 6, 2019 · 3 comments
Closed

Unable to create HTTP mapping with "/parent" #1079

ghost opened this issue Nov 6, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 6, 2019

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.

@ghost
Copy link
Author

ghost commented Nov 6, 2019

Tagging @ch3rub1m

@johanbrandhorst
Copy link
Collaborator

This was fixed by #1078.

@johanbrandhorst
Copy link
Collaborator

Thanks for the report @mheBobAllison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant