grpc-gateway: protoc-gen-swagger: patch method request attributes do not map to query parameter

This is a follow up issue to https://github.com/grpc-ecosystem/grpc-gateway/issues/1012.

  1. use the following proto file to genrate a swagger file.
syntax="proto3";

package book;
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";

service BookService {
  // Updates a book.
  rpc UpdateBook(UpdateBookRequest) returns (Book) {
    // Update maps to HTTP PATCH. Resource name is mapped to a URL path.
    // Resource is contained in the HTTP request body.
    option (google.api.http) = {
      // Note the URL template variable which captures the resource name of the
      // book to update.
      patch: "/v1/{book.name=shelves/*/books/*}"
      body: "book"
    };
  }
}

message UpdateBookRequest {
  // The book resource which replaces the resource on the server.
  Book book = 1;

  string title = 2;
}

message Book {
  string name = 1;
  string author = 2;
}
  1. title shoud be mapped to a url query parameter, but it is not in the swagger file. The following is the parameter section of swagger output.
        "parameters": [
          {
            "name": "book.name",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "description": "The book resource which replaces the resource on the server.",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/bookBook"
            }
          }
        ],
  1. title is not part of the go generate file output either. This is the url pattern in the gateway output.
 pattern_BookService_UpdateBook_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 2, 2, 1, 0, 4, 4, 5, 3}, []string{"v1", "shelves", "books", "book.name"}, "", runtime.AssumeColonVerbOpt(true)))
)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I have a similar problem, if i defined the path get: "/v1/{book.name=shelves/*/books/*}" in proto file according to google api design, then generate the swagger file and i will get the same path v1/{book.name=shelves/*/books/*} defined in swagger file.The problem is that the path not correct (it should looks like: /v1/shelves/*/books/* )and we can not use the swagger ui to test the api directly. And i found the gateway works fine, it looks only swagger file wrong