Skip to content

Commit faa3576

Browse files
committed
Merge remote-tracking branch 'tmc/swagger_streaming'
2 parents e712347 + dffa18a commit faa3576

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

examples/examplepb/a_bit_of_everything.swagger.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"operationId": "CreateBody",
2121
"responses": {
2222
"200": {
23-
"description": "Description",
23+
"description": "",
2424
"schema": {
2525
"$ref": "#/definitions/examplepbABitOfEverything"
2626
}
@@ -46,7 +46,7 @@
4646
"operationId": "Echo",
4747
"responses": {
4848
"200": {
49-
"description": "Description",
49+
"description": "",
5050
"schema": {
5151
"$ref": "#/definitions/subStringMessage"
5252
}
@@ -71,7 +71,7 @@
7171
"operationId": "Create",
7272
"responses": {
7373
"200": {
74-
"description": "Description",
74+
"description": "",
7575
"schema": {
7676
"$ref": "#/definitions/examplepbABitOfEverything"
7777
}
@@ -194,7 +194,7 @@
194194
"operationId": "DeepPathEcho",
195195
"responses": {
196196
"200": {
197-
"description": "Description",
197+
"description": "",
198198
"schema": {
199199
"$ref": "#/definitions/examplepbABitOfEverything"
200200
}
@@ -227,7 +227,7 @@
227227
"operationId": "Lookup",
228228
"responses": {
229229
"200": {
230-
"description": "Description",
230+
"description": "",
231231
"schema": {
232232
"$ref": "#/definitions/examplepbABitOfEverything"
233233
}
@@ -250,7 +250,7 @@
250250
"operationId": "Delete",
251251
"responses": {
252252
"200": {
253-
"description": "Description",
253+
"description": "",
254254
"schema": {
255255
"$ref": "#/definitions/protobufEmpty"
256256
}
@@ -273,7 +273,7 @@
273273
"operationId": "Update",
274274
"responses": {
275275
"200": {
276-
"description": "Description",
276+
"description": "",
277277
"schema": {
278278
"$ref": "#/definitions/protobufEmpty"
279279
}
@@ -306,7 +306,7 @@
306306
"operationId": "Echo",
307307
"responses": {
308308
"200": {
309-
"description": "Description",
309+
"description": "",
310310
"schema": {
311311
"$ref": "#/definitions/subStringMessage"
312312
}
@@ -320,7 +320,7 @@
320320
"operationId": "Echo",
321321
"responses": {
322322
"200": {
323-
"description": "Description",
323+
"description": "",
324324
"schema": {
325325
"$ref": "#/definitions/subStringMessage"
326326
}
@@ -346,7 +346,7 @@
346346
"operationId": "Timeout",
347347
"responses": {
348348
"200": {
349-
"description": "Description",
349+
"description": "",
350350
"schema": {
351351
"$ref": "#/definitions/protobufEmpty"
352352
}

examples/examplepb/echo_service.swagger.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"operationId": "Echo",
2424
"responses": {
2525
"200": {
26-
"description": "Description",
26+
"description": "",
2727
"schema": {
2828
"$ref": "#/definitions/examplepbSimpleMessage"
2929
}
@@ -49,7 +49,7 @@
4949
"operationId": "EchoBody",
5050
"responses": {
5151
"200": {
52-
"description": "Description",
52+
"description": "",
5353
"schema": {
5454
"$ref": "#/definitions/examplepbSimpleMessage"
5555
}

protoc-gen-swagger/genswagger/template.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,6 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
335335
// Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array.
336336
for svcIdx, svc := range services {
337337
for methIdx, meth := range svc.Methods {
338-
if meth.GetClientStreaming() || meth.GetServerStreaming() {
339-
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?`)
340-
}
341338
for _, b := range meth.Bindings {
342339
// Iterate over all the swagger parameters
343340
parameters := swaggerParametersObject{}
@@ -369,10 +366,15 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
369366
}
370367
// Now check if there is a body parameter
371368
if b.Body != nil {
369+
desc := ""
370+
if meth.GetClientStreaming() {
371+
desc = "(streaming inputs)"
372+
}
372373
parameters = append(parameters, swaggerParameterObject{
373-
Name: "body",
374-
In: "body",
375-
Required: true,
374+
Name: "body",
375+
Description: desc,
376+
In: "body",
377+
Required: true,
376378
Schema: &swaggerSchemaObject{
377379
schemaCore: schemaCore{
378380
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)),
@@ -387,13 +389,17 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
387389
}
388390

389391
methProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.ServiceDescriptorProto)(nil)), "Method")
392+
desc := ""
393+
if meth.GetServerStreaming() {
394+
desc += "(streaming responses)"
395+
}
390396
operationObject := &swaggerOperationObject{
391397
Tags: []string{svc.GetName()},
392398
OperationID: fmt.Sprintf("%s", meth.GetName()),
393399
Parameters: parameters,
394400
Responses: swaggerResponsesObject{
395401
"200": swaggerResponseObject{
396-
Description: "Description",
402+
Description: desc,
397403
Schema: swaggerSchemaObject{
398404
schemaCore: schemaCore{
399405
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)),

0 commit comments

Comments
 (0)