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

generate swagger output for streaming endpoints with a basic note #183

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make swagger generate a streaming client?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achew22 swagger spec doesn't address streaming endpoints (yet) there's some discussion on the openapi repo.

}
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