grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

Spurious Tags emitted when tags list is specified

Open eccles opened this issue 1 year ago • 2 comments

🐛 Bug Report

Specifying a list of tags with descriptions in the swagger options results in an extra duplicate tag without a description being emitted.

To Reproduce

At top of file add a list of tags to the options:

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
    info: {
        title: "Locations API"
        description: "API to manage locations."
        version: "1.0"
        contact: {
            name: "RKVST"
            url: "https://www.rkvst.com"
        }
    };
    base_path: "/_api";
    schemes: HTTPS;
    consumes: "application/json";
    produces: "application/json";
    tags: [
        {
            name: "Locations",
            description: "Read and modify Locations"
        },
        {
            name: "Unsupported",
            description: "Internal APIs that are unstable and should not be used in a production setting."
        }
    ];
};

Execute:

protoc -I . {{.PROTOC_INC}}
     --go_out=paths=source_relative:.
     --go-grpc_out=paths=source_relative:.
     --validate_out=lang=go,paths=source_relative:.
     --openapiv2_out=.
     --openapiv2_opt disable_default_errors=true
     --openapiv2_opt json_names_for_fields=false
     --openapiv2_opt logtostderr=true
     --grpc-gateway_out=paths=source_relative,logtostderr=true:.
     --plugin /go/bin/protoc-gen-doc
     --doc_out=api/{{.API}}/
     --doc_opt=api/confluence_doc.tmpl,confluence.storage
     api/{{.API}}/*.proto

Expected behavior

Swagger looks like this:

{
  "swagger": "2.0",
  "info": {
    "title": "Locations API",
    "description": "API to manage locations.",
    "version": "1.0",
    "contact": {
      "name": "RKVST",
      "url": "https://www.rkvst.com"
    }
  },
  "tags": [
    {
      "name": "Locations",
      "description": "Read and modify Locations"
    },
    {
      "name": "Unsupported",
      "description": "Internal APIs that are unstable and should not be used in a production setting."
    }
  ],
  "basePath": "/_api",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],

Actual Behavior

but actually gets this:

{
  "swagger": "2.0",
  "info": {
    "title": "Locations API",
    "description": "API to manage locations.",
    "version": "1.0",
    "contact": {
      "name": "RKVST",
      "url": "https://www.rkvst.com"
    }
  },
  "tags": [
    {
          "name": "Locations"
    },
    {
      "name": "Locations",
      "description": "Read and modify Locations"
    },
    {
      "name": "Unsupported",
      "description": "Internal APIs that are unstable and should not be used in a production setting."
    }
  ],
  "basePath": "/_api",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],

Your Environment

grpc gateway version 2.14.0 protoc 21.9

eccles avatar Dec 07 '22 17:12 eccles

Is this tag not based on the package or protobuf file name? Otherwise, this certainly seems like a silly bug, thanks for reporting it!

johanbrandhorst avatar Dec 08 '22 01:12 johanbrandhorst

Are you defining the Locations service in the proto and generating it with the disable_service_tags=false (default) option?

eyasy1217 avatar Jan 21 '24 12:01 eyasy1217