Skip to content

protoc-gen-openapiv2 generate odd prefix for Location message definition #2191

@nazy

Description

@nazy

🐛 Bug Report

When I generate Open API definition with protoc-gen-openapiv2, the definition for Location message has an odd prefix.
I believe the prefix of definitions is the last part of package name but only for Location message, it also contains the parent package name.
e.g. If package name is example.test. Usual message definition's prefix is test, but only for Location, the prefix will be exampletest.

To Reproduce

  1. Setup grpc-gateway according to README.md's Installation section
  2. Clone googleapis
    $ git clone --depth 1 https://github.com/googleapis/googleapis.git
  3. Create the following proto file
    syntax = "proto3";
    package example.test;
    option go_package = "example/test";
    import "google/api/annotations.proto";
    import "google/protobuf/empty.proto";
    
    service TestService {
      rpc Test(TestRequest) returns (google.protobuf.Empty) {
          option (google.api.http) = {};
      }
    }
    
    message TestRequest {
      Location x = 1;
      NotLocation y = 2;
    }
    message Location { }
    message NotLocation { }
  4. Generate OpenAPI definitions
    $ protoc -I googleapis -I . --openapiv2_out . test.proto 
  5. Check Location's definition
    $ grep -i location test.swagger.json
        "exampletestLocation": {
        "testNotLocation": {

Expected behavior

All message definitions' prefix are the last part of the package name.

e.g. package is example.test

  • Location -> testLocation
  • AnyOther -> testAnyOther

Actual Behavior

e.g. package is example.test

  • Location -> exampletestLocation
  • AnyOther -> testAnyOther

Your Environment

  • OS: Ubuntu 20.04 on Vagrant (box: generic/ubuntu2004).
  • golang : go version go1.16.5 linux/amd64
  • protoc: libprotoc 3.17.1
  • protoc-gen-openapiv2: Version dev, commit unknown, built at unknown
    • but I believe it is v2.4.0
  • go.mod
    module example.com/test
    
    go 1.16
    
    require (
            github.com/grpc-ecosystem/grpc-gateway/v2 v2.4.0
            google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
            google.golang.org/protobuf v1.26.0
    )
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions