Skip to content

Commit

Permalink
generate swagger output for streaming endpoints with a basic note
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jun 14, 2016
1 parent e4ae50d commit 787aa12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
20 changes: 10 additions & 10 deletions examples/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"operationId": "CreateBody",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
Expand All @@ -46,7 +46,7 @@
"operationId": "Echo",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/subStringMessage"
}
Expand All @@ -71,7 +71,7 @@
"operationId": "Create",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
Expand Down Expand Up @@ -194,7 +194,7 @@
"operationId": "DeepPathEcho",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
Expand Down Expand Up @@ -227,7 +227,7 @@
"operationId": "Lookup",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
Expand All @@ -250,7 +250,7 @@
"operationId": "Delete",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/protobufEmpty"
}
Expand All @@ -273,7 +273,7 @@
"operationId": "Update",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/protobufEmpty"
}
Expand Down Expand Up @@ -306,7 +306,7 @@
"operationId": "Echo",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/subStringMessage"
}
Expand All @@ -320,7 +320,7 @@
"operationId": "Echo",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/subStringMessage"
}
Expand All @@ -346,7 +346,7 @@
"operationId": "Timeout",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/protobufEmpty"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/examplepb/echo_service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"operationId": "Echo",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbSimpleMessage"
}
Expand All @@ -49,7 +49,7 @@
"operationId": "EchoBody",
"responses": {
"200": {
"description": "Description",
"description": "",
"schema": {
"$ref": "#/definitions/examplepbSimpleMessage"
}
Expand Down
20 changes: 13 additions & 7 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down

0 comments on commit 787aa12

Please sign in to comment.