grpc-ecosystem/grpc-gateway

Protoc panics while generating openapiv2 files from proto with custom HttpRule in additional_bindings

Open

#2889 aperta il 15 set 2022

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Go (2250 fork)batch import
buggood first issuehelp wantedopenapi

Metriche repository

Star
 (16.971 star)
Metriche merge PR
 (Merge medio 1g 4h) (141 PR mergiate in 30 g)

Descrizione

🐛 Bug Report

Proto file with the following part:

service HealthService {
    rpc GetAllHealthChecks (GetAllHealthChecksRequest) returns (GetAllHealthChecksReply) {
        option (google.api.http) = {
            get: "/api/rest/v1/health/all"
            additional_bindings: [{ 
                custom: {
                    kind: "HEAD" 
                    path: "/api/rest/v1/health/all"
                }; 
            }];
        };
        option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
            summary: "Get all health checks";
            description: "This endpoint returns all the health checks of all instances of this component";
            tags: "Health checks";
        };
    };
}

openapi files generation run with:

          protoc --proto_path=api/proto/v1  --proto_path=api/proto/third_party \
            --openapiv2_out api/swagger/v1-tags \
            --openapiv2_opt logtostderr=true \
            `basename $file`

results with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x134978c]

goroutine 1 [running]:
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi.renderServices({0xc00069c678, 0x1, 0xc0004eeb18}, 0xa, 0xc0001e4000, 0xa, 0xa, {0xc00027df40, 0x7, 0x8})
        /Users/x/go/src/projectX/grpc-gateway/protoc-gen-openapiv2/internal/genopenapi/template.go:1083 +0xa2c
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi.applyTemplate({0xc0003fd3b0, 0xc0001e4000})
        /Users/x/go/src/projectX/grpc-gateway/protoc-gen-openapiv2/internal/genopenapi/template.go:1394 +0x2f6
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi.(*generator).Generate(0xc0004efce0, {0xc00069c680, 0x14, 0x1014bd4})
        /Users/x/go/src/projectX/grpc-gateway/protoc-gen-openapiv2/internal/genopenapi/generator.go:194 +0x177
main.main()
        /Users/x/go/src/projectX/grpc-gateway/protoc-gen-openapiv2/main.go:160 +0xd1c
--openapiv2_out: protoc-gen-openapiv2: Plugin failed with status code 2.

Replacing the custom HttpRule with non-custom one such as get: "/path" results with a successful generation.

Guida contributor