forked from loafle/openapi-generator-original
Removed fileParams as the file content will be posted via postBody, fixed file upload issue
This commit is contained in:
@@ -104,6 +104,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("time.Time", "time");
|
||||
importMapping.put("*os.File", "os");
|
||||
importMapping.put("ioutil", "io/ioutil");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
||||
|
||||
@@ -58,7 +58,6 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
|
||||
headerParams := make(map[string]string)
|
||||
queryParams := make(map[string]string)
|
||||
formParams := make(map[string]string)
|
||||
fileParams := make(map[string]string)
|
||||
var postBody interface{}
|
||||
|
||||
{{#authMethods}}// authentication ({{name}}) required
|
||||
@@ -123,23 +122,24 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
|
||||
{{/headerParams}}{{/hasHeaderParams}}
|
||||
{{#hasFormParams}}
|
||||
{{#formParams}}
|
||||
{{#isFile}}
|
||||
fileParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}}.Name()
|
||||
{{#isFile}}fileBytes, _ := ioutil.ReadAll(file)
|
||||
postBody = fileBytes
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}}
|
||||
{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{/hasFormParams}}
|
||||
{{#hasBodyParam}}{{#bodyParams}}
|
||||
{{/hasFormParams}}{{#hasBodyParam}}{{#bodyParams}}
|
||||
// body params
|
||||
postBody = &{{paramName}}
|
||||
{{/bodyParams}}{{/hasBodyParam}}
|
||||
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
|
||||
{{#returnType}} httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams)
|
||||
{{/returnType}}
|
||||
{{^returnType}} _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams)
|
||||
{{/returnType}}
|
||||
|
||||
httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams)
|
||||
|
||||
if err != nil && httpResponse.StatusCode() != 200{
|
||||
if err != nil {
|
||||
return {{#returnType}}*successPayload, {{/returnType}}err
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,9 @@ func (c *ApiClient) CallApi(path string, method string,
|
||||
postBody interface{},
|
||||
headerParams map[string]string,
|
||||
queryParams map[string]string,
|
||||
formParams map[string]string,
|
||||
fileParams map[string]string) (*resty.Response, error) {
|
||||
formParams map[string]string) (*resty.Response, error) {
|
||||
|
||||
request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams)
|
||||
request := prepareRequest(postBody, headerParams, queryParams, formParams)
|
||||
|
||||
switch strings.ToUpper(method) {
|
||||
case "GET":
|
||||
@@ -77,7 +76,7 @@ func (c *ApiClient) CallApi(path string, method string,
|
||||
func (c *ApiClient) ParameterToString (obj interface{}) string {
|
||||
if reflect.TypeOf(obj).String() == "[]string" {
|
||||
return strings.Join(obj.([]string), ",")
|
||||
} else{
|
||||
} else {
|
||||
return obj.(string)
|
||||
}
|
||||
}
|
||||
@@ -85,8 +84,7 @@ func (c *ApiClient) ParameterToString (obj interface{}) string {
|
||||
func prepareRequest(postBody interface{},
|
||||
headerParams map[string]string,
|
||||
queryParams map[string]string,
|
||||
formParams map[string]string,
|
||||
fileParams map[string]string) *resty.Request {
|
||||
formParams map[string]string) *resty.Request {
|
||||
|
||||
request := resty.R()
|
||||
|
||||
@@ -102,15 +100,5 @@ func prepareRequest(postBody interface{},
|
||||
request.SetQueryParams(queryParams)
|
||||
}
|
||||
|
||||
// add form parameter, if any
|
||||
if len(fileParams) > 0 {
|
||||
request.SetFormData(formParams)
|
||||
}
|
||||
|
||||
// add file parameter, if any
|
||||
if len(fileParams) > 0 {
|
||||
request.SetFiles(fileParams)
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
Reference in New Issue
Block a user