From e9dca89c1947af1303578aa34b165226d7b650de Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Mon, 13 Jun 2016 20:13:12 -0700 Subject: [PATCH] generate swagger output for streaming endpoints with a basic note --- .../a_bit_of_everything.swagger.json | 20 +++++++++---------- examples/examplepb/echo_service.swagger.json | 4 ++-- protoc-gen-swagger/genswagger/template.go | 20 ++++++++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/examplepb/a_bit_of_everything.swagger.json b/examples/examplepb/a_bit_of_everything.swagger.json index fc6611d210f..e52f7c70e8b 100644 --- a/examples/examplepb/a_bit_of_everything.swagger.json +++ b/examples/examplepb/a_bit_of_everything.swagger.json @@ -20,7 +20,7 @@ "operationId": "CreateBody", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbABitOfEverything" } @@ -46,7 +46,7 @@ "operationId": "Echo", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/subStringMessage" } @@ -71,7 +71,7 @@ "operationId": "Create", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbABitOfEverything" } @@ -194,7 +194,7 @@ "operationId": "DeepPathEcho", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbABitOfEverything" } @@ -227,7 +227,7 @@ "operationId": "Lookup", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbABitOfEverything" } @@ -250,7 +250,7 @@ "operationId": "Delete", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/protobufEmpty" } @@ -273,7 +273,7 @@ "operationId": "Update", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/protobufEmpty" } @@ -306,7 +306,7 @@ "operationId": "Echo", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/subStringMessage" } @@ -320,7 +320,7 @@ "operationId": "Echo", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/subStringMessage" } @@ -346,7 +346,7 @@ "operationId": "Timeout", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/protobufEmpty" } diff --git a/examples/examplepb/echo_service.swagger.json b/examples/examplepb/echo_service.swagger.json index 94e1abde9ac..f6c6d8b9814 100644 --- a/examples/examplepb/echo_service.swagger.json +++ b/examples/examplepb/echo_service.swagger.json @@ -23,7 +23,7 @@ "operationId": "Echo", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbSimpleMessage" } @@ -49,7 +49,7 @@ "operationId": "EchoBody", "responses": { "200": { - "description": "Description", + "description": "", "schema": { "$ref": "#/definitions/examplepbSimpleMessage" } diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index 2c616b2cb7e..fd7b1dfe00d 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -335,9 +335,6 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re // Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array. for svcIdx, svc := range services { for methIdx, meth := range svc.Methods { - if meth.GetClientStreaming() || meth.GetServerStreaming() { - return fmt.Errorf(`service uses streaming, which is not currently supported. Maybe you would like to implement it? It wouldn't be that hard and we don't bite. Why don't you send a pull request to https://github.com/gengo/grpc-gateway?`) - } for _, b := range meth.Bindings { // Iterate over all the swagger parameters parameters := swaggerParametersObject{} @@ -369,10 +366,15 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re } // Now check if there is a body parameter if b.Body != nil { + desc := "" + if meth.GetClientStreaming() { + desc = "(streaming inputs)" + } parameters = append(parameters, swaggerParameterObject{ - Name: "body", - In: "body", - Required: true, + Name: "body", + Description: desc, + In: "body", + Required: true, Schema: &swaggerSchemaObject{ schemaCore: schemaCore{ Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)), @@ -387,13 +389,17 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re } methProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.ServiceDescriptorProto)(nil)), "Method") + desc := "" + if meth.GetServerStreaming() { + desc += "(streaming responses)" + } operationObject := &swaggerOperationObject{ Tags: []string{svc.GetName()}, OperationID: fmt.Sprintf("%s", meth.GetName()), Parameters: parameters, Responses: swaggerResponsesObject{ "200": swaggerResponseObject{ - Description: "Description", + Description: desc, Schema: swaggerSchemaObject{ schemaCore: schemaCore{ Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)),