forked from grpc-ecosystem/grpc-gateway
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…pc-ecosystem#712) Also: * add flag `allow_repeated_fields_in_body` in `protoc-gen-grpc-gateway` * add flag `json_names_for_fields` in `protoc-gen-swagger`
- Loading branch information
Showing
43 changed files
with
1,351 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Swagger Codegen Ignore | ||
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* examples/proto/examplepb/response_body_service.proto | ||
* | ||
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | ||
* | ||
* OpenAPI spec version: version not set | ||
* | ||
* Generated by: https://github.com/swagger-api/swagger-codegen.git | ||
*/ | ||
|
||
package responsebody | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"net/url" | ||
"io/ioutil" | ||
"github.com/go-resty/resty" | ||
) | ||
|
||
type APIClient struct { | ||
config *Configuration | ||
} | ||
|
||
func (c *APIClient) SelectHeaderContentType(contentTypes []string) string { | ||
|
||
if len(contentTypes) == 0 { | ||
return "" | ||
} | ||
if contains(contentTypes, "application/json") { | ||
return "application/json" | ||
} | ||
return contentTypes[0] // use the first content type specified in 'consumes' | ||
} | ||
|
||
func (c *APIClient) SelectHeaderAccept(accepts []string) string { | ||
|
||
if len(accepts) == 0 { | ||
return "" | ||
} | ||
if contains(accepts, "application/json") { | ||
return "application/json" | ||
} | ||
return strings.Join(accepts, ",") | ||
} | ||
|
||
func contains(haystack []string, needle string) bool { | ||
for _, a := range haystack { | ||
if strings.ToLower(a) == strings.ToLower(needle) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (c *APIClient) CallAPI(path string, method string, | ||
postBody interface{}, | ||
headerParams map[string]string, | ||
queryParams url.Values, | ||
formParams map[string]string, | ||
fileName string, | ||
fileBytes []byte) (*resty.Response, error) { | ||
|
||
rClient := c.prepareClient() | ||
request := c.prepareRequest(rClient, postBody, headerParams, queryParams, formParams, fileName, fileBytes) | ||
|
||
switch strings.ToUpper(method) { | ||
case "GET": | ||
response, err := request.Get(path) | ||
return response, err | ||
case "POST": | ||
response, err := request.Post(path) | ||
return response, err | ||
case "PUT": | ||
response, err := request.Put(path) | ||
return response, err | ||
case "PATCH": | ||
response, err := request.Patch(path) | ||
return response, err | ||
case "DELETE": | ||
response, err := request.Delete(path) | ||
return response, err | ||
} | ||
|
||
return nil, fmt.Errorf("invalid method %v", method) | ||
} | ||
|
||
func (c *APIClient) ParameterToString(obj interface{}, collectionFormat string) string { | ||
delimiter := "" | ||
switch collectionFormat { | ||
case "pipes": | ||
delimiter = "|" | ||
case "ssv": | ||
delimiter = " " | ||
case "tsv": | ||
delimiter = "\t" | ||
case "csv": | ||
delimiter = "," | ||
} | ||
|
||
if reflect.TypeOf(obj).Kind() == reflect.Slice { | ||
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") | ||
} | ||
|
||
return fmt.Sprintf("%v", obj) | ||
} | ||
|
||
func (c *APIClient) prepareClient() *resty.Client { | ||
|
||
rClient := resty.New() | ||
|
||
rClient.SetDebug(c.config.Debug) | ||
if c.config.Transport != nil { | ||
rClient.SetTransport(c.config.Transport) | ||
} | ||
|
||
if c.config.Timeout != nil { | ||
rClient.SetTimeout(*c.config.Timeout) | ||
} | ||
rClient.SetLogger(ioutil.Discard) | ||
return rClient | ||
} | ||
|
||
func (c *APIClient) prepareRequest( | ||
rClient *resty.Client, | ||
postBody interface{}, | ||
headerParams map[string]string, | ||
queryParams url.Values, | ||
formParams map[string]string, | ||
fileName string, | ||
fileBytes []byte) *resty.Request { | ||
|
||
|
||
request := rClient.R() | ||
request.SetBody(postBody) | ||
|
||
if c.config.UserAgent != "" { | ||
request.SetHeader("User-Agent", c.config.UserAgent) | ||
} | ||
|
||
// add header parameter, if any | ||
if len(headerParams) > 0 { | ||
request.SetHeaders(headerParams) | ||
} | ||
|
||
// add query parameter, if any | ||
if len(queryParams) > 0 { | ||
request.SetMultiValueQueryParams(queryParams) | ||
} | ||
|
||
// add form parameter, if any | ||
if len(formParams) > 0 { | ||
request.SetFormData(formParams) | ||
} | ||
|
||
if len(fileBytes) > 0 && fileName != "" { | ||
_, fileNm := filepath.Split(fileName) | ||
request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) | ||
} | ||
return request | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* examples/proto/examplepb/response_body_service.proto | ||
* | ||
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | ||
* | ||
* OpenAPI spec version: version not set | ||
* | ||
* Generated by: https://github.com/swagger-api/swagger-codegen.git | ||
*/ | ||
|
||
package responsebody | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type APIResponse struct { | ||
*http.Response `json:"-"` | ||
Message string `json:"message,omitempty"` | ||
// Operation is the name of the swagger operation. | ||
Operation string `json:"operation,omitempty"` | ||
// RequestURL is the request URL. This value is always available, even if the | ||
// embedded *http.Response is nil. | ||
RequestURL string `json:"url,omitempty"` | ||
// Method is the HTTP method used for the request. This value is always | ||
// available, even if the embedded *http.Response is nil. | ||
Method string `json:"method,omitempty"` | ||
// Payload holds the contents of the response body (which may be nil or empty). | ||
// This is provided here as the raw response.Body() reader will have already | ||
// been drained. | ||
Payload []byte `json:"-"` | ||
} | ||
|
||
func NewAPIResponse(r *http.Response) *APIResponse { | ||
|
||
response := &APIResponse{Response: r} | ||
return response | ||
} | ||
|
||
func NewAPIResponseWithError(errorMessage string) *APIResponse { | ||
|
||
response := &APIResponse{Message: errorMessage} | ||
return response | ||
} |
Oops, something went wrong.