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

Add description, summary and tags fields in operationObject (swagger) #526

Merged
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
4 changes: 4 additions & 0 deletions examples/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ service ABitOfEverythingService {
}
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
description: "Description Echo";
summary: "Summary: Echo rpc";
tags: "echo service";
tags: "echo rpc";
external_docs: {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "Find out more Echo";
Expand Down
21 changes: 12 additions & 9 deletions examples/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
},
"/v1/example/a_bit_of_everything/echo/{value}": {
"get": {
"summary": "Echo allows posting a StringMessage value.",
"description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.",
"summary": "Summary: Echo rpc",
"description": "Description Echo",
"operationId": "Echo",
"responses": {
"200": {
Expand All @@ -71,7 +71,8 @@
}
],
"tags": [
"ABitOfEverythingService"
"echo service",
"echo rpc"
],
"externalDocs": {
"description": "Find out more Echo",
Expand Down Expand Up @@ -523,8 +524,8 @@
},
"/v2/example/echo": {
"get": {
"summary": "Echo allows posting a StringMessage value.",
"description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.",
"summary": "Summary: Echo rpc",
"description": "Description Echo",
"operationId": "Echo3",
"responses": {
"200": {
Expand All @@ -543,16 +544,17 @@
}
],
"tags": [
"ABitOfEverythingService"
"echo service",
"echo rpc"
],
"externalDocs": {
"description": "Find out more Echo",
"url": "https://github.com/grpc-ecosystem/grpc-gateway"
}
},
"post": {
"summary": "Echo allows posting a StringMessage value.",
"description": "It also exposes multiple bindings.\n\nThis makes it useful when validating that the OpenAPI v2 API\ndescription exposes documentation correctly on all paths\ndefined as additional_bindings in the proto.",
"summary": "Summary: Echo rpc",
"description": "Description Echo",
"operationId": "Echo2",
"responses": {
"200": {
Expand All @@ -573,7 +575,8 @@
}
],
"tags": [
"ABitOfEverythingService"
"echo service",
"echo rpc"
],
"externalDocs": {
"description": "Find out more Echo",
Expand Down
11 changes: 11 additions & 0 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
// TODO(ivucica): this would be better supported by looking whether the method is deprecated in the proto file
operationObject.Deprecated = opts.Deprecated

if opts.Summary != "" {
operationObject.Summary = opts.Summary
}
if opts.Description != "" {
operationObject.Description = opts.Description
}
if len(opts.Tags) > 0 {
operationObject.Tags = make([]string, len(opts.Tags))
copy(operationObject.Tags, opts.Tags)
}

// TODO(ivucica): add remaining fields of operation object
}

Expand Down