grpc-ecosystem/grpc-gateway

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

Open

#2.889 aberto em 15 de set. de 2022

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)Go (2.250 forks)batch import
buggood first issuehelp wantedopenapi

Métricas do repositório

Stars
 (16.971 stars)
Métricas de merge de PR
 (Mesclagem média 1d 4h) (141 fundiu PRs em 30d)

Description

🐛 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.

Guia do colaborador