Skip to content

protoc-gen-swagger missing definition issue #504

Closed
@warmans

Description

@warmans

protoc-gen-swagger appears to have an issue where an entity is omitted from the definitions when a field is specified for the body rather than *.

Reproduce with the following code:

example.proto

syntax = "proto3";

package example;

import "google/api/annotations.proto";

service ExampleService {
    rpc DoSomething(DoSomethingRequest) returns (DoSomethingResponse) {
        option (google.api.http) = {
            post: "/do-something/{id}"
            body: "data"
        };
    }
}

message ExtraData {
    string foo = 1;
}

message DoSomethingRequest {
    string id = 1;
    ExtraData data = 2;
}

message DoSomethingResponse {
    string bar = 1;
}

Generate the code:

protoc -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. --swagger_out=logtostderr=true:. ./example.proto

Results in:

{
  "swagger": "2.0",
  "info": {
    "title": "example.proto",
    "version": "version not set"
  },
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/do-something/{id}": {
      "post": {
        "operationId": "DoSomething",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/exampleDoSomethingResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/exampleExtraData"
            }
          }
        ],
        "tags": [
          "ExampleService"
        ]
      }
    }
  },
  "definitions": {
    "exampleDoSomethingResponse": {
      "type": "object",
      "properties": {
        "bar": {
          "type": "string"
        }
      }
    }
  }
}

Note that there is a $ref to #/definitions/exampleExtraData but it does not appear in the definitions.

edit: actually I don't know if the body attribute is relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions