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

gen-swagger does not generate PATCH method endpoints #211

Closed
sdemos opened this issue Aug 9, 2016 · 2 comments
Closed

gen-swagger does not generate PATCH method endpoints #211

sdemos opened this issue Aug 9, 2016 · 2 comments

Comments

@sdemos
Copy link
Contributor

sdemos commented Aug 9, 2016

The grpc-gateway generator correctly generates working endpoints using the patch method, but the swagger generator just outputs empty data for those paths.

For example:

service ExampleService {
    rpc SetAppLabel(SetAppLabelReq) returns (SetAppLabelResp) {
        option (google.api.http) = {
            patch: "/apps/{id}/label"
            body: "*"
        };
    }
}

message SetAppLabelReq {
    string id = 1;
    string label = 2;
}

message SetAppLabelResp{
    string id = 1;
}

generates a path that looks like this:

  '/apps/{id}/label": {}

instead of generating the correct swagger output, which would be something like this:

  '/apps/{id}/label':
    patch:
      operationId: SetAppLabel
      responses:
        '200':
          description: ''
          schema:
            $ref: '#/definitions/protoSetAppLabelResp'
      parameters:
        - name: id
          in: path
          required: true
          type: string
          format: string
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/protoSetAppLabelReq'
@ericlagergren
Copy link

ericlagergren commented Oct 3, 2016

AFAICT the patch is fairly simple:

diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go
index d33aba5..9db445c 100644
--- a/protoc-gen-swagger/genswagger/template.go
+++ b/protoc-gen-swagger/genswagger/template.go
@@ -437,6 +437,9 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
                case "PUT":
                    pathItemObject.Put = operationObject
                    break
+               case "PATCH":
+                   pathItemObject.Patch = operationObject
+                   break
                }
                paths[templateToSwaggerPath(b.PathTmpl.Template)] = pathItemObject
            }
diff --git a/protoc-gen-swagger/genswagger/types.go b/protoc-gen-swagger/genswagger/types.go
index b91e457..a31f3ec 100644
--- a/protoc-gen-swagger/genswagger/types.go
+++ b/protoc-gen-swagger/genswagger/types.go
@@ -66,6 +66,7 @@ type swaggerPathItemObject struct {
    Delete *swaggerOperationObject `json:"delete,omitempty"`
    Post   *swaggerOperationObject `json:"post,omitempty"`
    Put    *swaggerOperationObject `json:"put,omitempty"`
+   Patch  *swaggerOperationObject `json:"patch,omitempty"`
 }

 // http://swagger.io/specification/#operationObject

@achew22
Copy link
Collaborator

achew22 commented Oct 4, 2016

That looks like a really great start! Do you think you could turn that into a pull request and send it in? Thanks so much

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

No branches or pull requests

3 participants