-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support HttpRule with field response #712
Merged
ivucica
merged 1 commit into
grpc-ecosystem:master
from
doroginin:httprule-with-response
Aug 17, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, could you reference
Gopkg.toml
here as well? These two must be kept in sync, obviously.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really these should all reference Gopkg.toml 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!