Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-swagger missing definition issue #504

Closed
warmans opened this issue Dec 15, 2017 · 0 comments · Fixed by #505
Closed

protoc-gen-swagger missing definition issue #504

warmans opened this issue Dec 15, 2017 · 0 comments · Fixed by #505

Comments

@warmans
Copy link
Contributor

warmans commented Dec 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant