Skip to content

Commit

Permalink
Add operationId to Swagger output.
Browse files Browse the repository at this point in the history
Swagger uses the operationId as the "nickname" for the method generated
for your service.
  • Loading branch information
achew22 committed Jan 14, 2016
1 parent 96f971a commit 6e9bc39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/examplepb/echo_service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"/v1/example/echo/{id}": {
"post": {
"summary": "EchoService.Echo",
"operationId": "Echo",
"responses": {
"default": {
"description": "Description",
Expand All @@ -40,6 +41,7 @@
"/v1/example/echo_body": {
"post": {
"summary": "EchoService.EchoBody",
"operationId": "EchoBody",
"responses": {
"default": {
"description": "Description",
Expand Down
6 changes: 6 additions & 0 deletions examples/examplepb/streamless_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"/v1/example/a_bit_of_everything": {
"get": {
"summary": "ABitOfEverythingService.List",
"operationId": "List",
"responses": {
"default": {
"description": "Description",
Expand All @@ -31,6 +32,7 @@
"/v1/example/a_bit_of_everything/bulk": {
"post": {
"summary": "ABitOfEverythingService.BulkCreate",
"operationId": "BulkCreate",
"responses": {
"default": {
"description": "Description",
Expand All @@ -54,6 +56,7 @@
"/v1/example/a_bit_of_everything/echo": {
"post": {
"summary": "ABitOfEverythingService.BulkEcho",
"operationId": "BulkEcho",
"responses": {
"default": {
"description": "Description",
Expand All @@ -77,6 +80,7 @@
"/v1/example/a_bit_of_everything/echo/{value}": {
"get": {
"summary": "ABitOfEverythingService.Echo",
"operationId": "Echo",
"responses": {
"default": {
"description": "Description",
Expand All @@ -99,6 +103,7 @@
"/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}": {
"post": {
"summary": "ABitOfEverythingService.Create",
"operationId": "Create",
"responses": {
"default": {
"description": "Description",
Expand Down Expand Up @@ -212,6 +217,7 @@
"/v1/example/a_bit_of_everything/{uuid}": {
"delete": {
"summary": "ABitOfEverythingService.Delete",
"operationId": "Delete",
"responses": {
"default": {
"description": "Description",
Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,9 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject) er

pathItemObject := swaggerPathItemObject{}
operationObject := &swaggerOperationObject{
Summary: fmt.Sprintf("%s.%s", svc.GetName(), meth.GetName()),
Parameters: parameters,
Summary: fmt.Sprintf("%s.%s", svc.GetName(), meth.GetName()),
OperationId: fmt.Sprintf("%s", meth.GetName()),
Parameters: parameters,
Responses: swaggerResponsesObject{
"default": swaggerResponseObject{
Description: "Description",
Expand Down
7 changes: 4 additions & 3 deletions protoc-gen-swagger/genswagger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ type swaggerPathItemObject struct {

// http://swagger.io/specification/#operationObject
type swaggerOperationObject struct {
Summary string `json:"summary"`
Responses swaggerResponsesObject `json:"responses"`
Parameters swaggerParametersObject `json:"parameters,omitempty"`
Summary string `json:"summary"`
OperationId string `json:"operationId"`
Responses swaggerResponsesObject `json:"responses"`
Parameters swaggerParametersObject `json:"parameters,omitempty"`
}

type swaggerParametersObject []swaggerParameterObject
Expand Down

0 comments on commit 6e9bc39

Please sign in to comment.