Skip to content

Commit

Permalink
Support delete method in swagger generator (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackdahila authored and achew22 committed Apr 26, 2018
1 parent 739cd2d commit 544e349
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 6 deletions.
62 changes: 62 additions & 0 deletions examples/clients/echo/echo_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,65 @@ func (a EchoServiceApi) EchoBody(body ExamplepbSimpleMessage) (*ExamplepbSimpleM
return successPayload, localVarAPIResponse, err
}

/**
* EchoDelete method receives a simple message and returns it.
*
* @param id Id represents the message identifier.
* @param num
* @return *ExamplepbSimpleMessage
*/
func (a EchoServiceApi) EchoDelete(id string, num string) (*ExamplepbSimpleMessage, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Delete")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/v1/example/echo_delete"

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := make(map[string]string)
var localVarPostBody interface{}
var localVarFileName string
var localVarFileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("id", a.Configuration.APIClient.ParameterToString(id, ""))
localVarQueryParams.Add("num", a.Configuration.APIClient.ParameterToString(num, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }

// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
}

// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ExamplepbSimpleMessage)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
localVarURL.RawQuery = localVarQueryParams.Encode()
var localVarAPIResponse = &APIResponse{Operation: "EchoDelete", Method: localVarHttpMethod, RequestURL: localVarURL.String()}
if localVarHttpResponse != nil {
localVarAPIResponse.Response = localVarHttpResponse.RawResponse
localVarAPIResponse.Payload = localVarHttpResponse.Body()
}

if err != nil {
return successPayload, localVarAPIResponse, err
}
err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload)
return successPayload, localVarAPIResponse, err
}

46 changes: 41 additions & 5 deletions examples/proto/examplepb/echo_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions examples/proto/examplepb/echo_service.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/proto/examplepb/echo_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ service EchoService {
body: "*"
};
}
// EchoDelete method receives a simple message and returns it.
rpc EchoDelete(SimpleMessage) returns (SimpleMessage) {
option (google.api.http) = {
delete: "/v1/example/echo_delete"
};
}
}
33 changes: 33 additions & 0 deletions examples/proto/examplepb/echo_service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@
"EchoService"
]
}
},
"/v1/example/echo_delete": {
"delete": {
"summary": "EchoDelete method receives a simple message and returns it.",
"operationId": "EchoDelete",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/examplepbSimpleMessage"
}
}
},
"parameters": [
{
"name": "id",
"description": "Id represents the message identifier.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "num",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
}
],
"tags": [
"EchoService"
]
}
}
},
"definitions": {
Expand Down
5 changes: 5 additions & 0 deletions examples/server/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ func (s *echoServer) EchoBody(ctx context.Context, msg *examples.SimpleMessage)
}))
return msg, nil
}

func (s *echoServer) EchoDelete(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
glog.Info(msg)
return msg, nil
}
2 changes: 1 addition & 1 deletion protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
Required: true,
Schema: &schema,
})
} else if b.HTTPMethod == "GET" {
} else if b.HTTPMethod == "GET" || b.HTTPMethod == "DELETE" {
// add the parameters to the query string
queryParams, err := messageToQueryParameters(meth.RequestType, reg, b.PathParams)
if err != nil {
Expand Down

0 comments on commit 544e349

Please sign in to comment.