Repository: grpc-ecosystem/grpc-gateway

Issue #1015: protoc-gen-swagger: patch method request attributes do not map to query parameter
Created: 2019-08-29T11:52:09Z
This is a follow up issue to #1012.

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;
}


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"
            }
          }
        ],


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)))
)

Duplicate issue #1271: bug in protoc-gen-swagger with put method and field_mask
Created: 2020-05-07T12:24:35Z
protoc-gen-swagger from current grpc-gateway master
  rpc Update(AccountUpdateReq) returns (Account) {                                                              
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = { operation_id: "AccountUpdate";     
   responses: {                                                                                                 
     key: "default";                                                                                            
     value: {                                                                                                   
       description: "Error response";                                                                           
       schema: {                                                                                                
         json_schema: {                                                                                         
           ref: ".Error";                                                                              
         }                                                                                                      
       }                                                                                                        
     }                                                                                                          
   }                                                                                                            
                                                                                                                
};                                                                                                              
    option (google.api.http) = { put: "/api/v0/accounts/{account.uuid}" body: "account"; };            
  };                                                                                                            

message AccountUpdateReq {                           
  Account account = 1;                               
  google.protobuf.FieldMask fields = 2;              
};                                                   


generates:
   "/api/v0/accounts/{account.uuid}": {
     "put": {
       "operationId": "AccountUpdate",
       "responses": {
         "200": {
           "description": "A successful response.",
           "schema": {
             "$ref": "#/definitions/Account"
           }
         },
         "default": {
           "description": "Error response",
           "schema": {
             "$ref": "#/definitions/Error"
           }
         }
       },
       "parameters": [
          {
            "name": "account.uuid",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Account"
            }
          }
        ],
        "tags": [
          "AccountService"
        ]
      }
    },

Closing comment (2020-05-07T12:35:10Z): i think that my issue is the same as #1015