From 3118f932c86a8667eb73ec1fd6e552dc798e4da5 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sat, 16 Apr 2016 22:58:13 -0700 Subject: [PATCH 01/24] added CallApiAsync method in api_client --- .../src/main/resources/go/api_client.mustache | 57 +++++++++++++++++++ .../client/petstore/go/swagger/api_client.go | 57 +++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 06470ba06d6..def951e7c41 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -2,6 +2,8 @@ package {{packageName}} import ( "strings" + "github.com/go-resty/resty" + "errors" ) type ApiClient struct { @@ -38,4 +40,59 @@ func contains(source []string, containvalue string) bool { } } return false +} + +func CallApiAsync(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) { + + request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) + + 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, errors.New("Invalid method " + method) +} + +func prepareRequest(postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileParams map[string]string) *resty.Request { + + request := resty.R() + + request.SetBody(postBody) + + // add header parameter, if any + request.SetHeaders(headerParams) + + // add query parameter, if any + request.SetQueryParams(queryParams) + + // add form parameter, if any + request.SetFormData(formParams) + + // add file parameter, if any + request.SetFiles(fileParams) + + return request } \ No newline at end of file diff --git a/samples/client/petstore/go/swagger/api_client.go b/samples/client/petstore/go/swagger/api_client.go index 9806ccdf38d..92114983bdd 100644 --- a/samples/client/petstore/go/swagger/api_client.go +++ b/samples/client/petstore/go/swagger/api_client.go @@ -2,6 +2,8 @@ package swagger import ( "strings" + "github.com/go-resty/resty" + "errors" ) type ApiClient struct { @@ -38,4 +40,59 @@ func contains(source []string, containvalue string) bool { } } return false +} + +func CallApiAsync(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) { + + request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) + + 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, errors.New("Invalid method " + method) +} + +func prepareRequest(postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileParams map[string]string) *resty.Request { + + request := resty.R() + + request.SetBody(postBody) + + // add header parameter, if any + request.SetHeaders(headerParams) + + // add query parameter, if any + request.SetQueryParams(queryParams) + + // add form parameter, if any + request.SetFormData(formParams) + + // add file parameter, if any + request.SetFiles(fileParams) + + return request } \ No newline at end of file From c0292564eef73498e4faf2df1c087da488183ab1 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 17 Apr 2016 20:37:19 -0700 Subject: [PATCH 02/24] updated api.mustache to use the new api client --- .../src/main/resources/go/api.mustache | 12 +++++------- .../src/main/resources/go/api_client.mustache | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index f08ba380ec0..fec404786d4 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -6,7 +6,6 @@ import ( "fmt" "encoding/json" "errors" - "github.com/dghubble/sling" {{#imports}} "{{import}}" {{/imports}} ) @@ -39,6 +38,11 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { + var httpMethod = {{httpMethod}} + // create path and map variables + path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}" +{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) +{{/pathParams}} _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) @@ -68,12 +72,6 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/isOAuth}} {{/authMethods}} - // create path and map variables - path := "{{basePathWithoutHost}}{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) -{{/pathParams}} - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index def951e7c41..eec9853db37 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -42,7 +42,7 @@ func contains(source []string, containvalue string) bool { return false } -func CallApiAsync(path string, method string, +func CallApi(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, From 8b896a2353eb3b2dced0961bb0decec99cf579e3 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 17 Apr 2016 23:45:23 -0700 Subject: [PATCH 03/24] updated api.mustache to call the api client http request --- .../src/main/resources/go/api.mustache | 49 ++-- .../resources/go/api_BACKUP_59234.mustache | 169 ------------ .../main/resources/go/api_BASE_59234.mustache | 160 ----------- .../resources/go/api_LOCAL_59234.mustache | 158 ----------- .../resources/go/api_REMOTE_59234.mustache | 167 ------------ .../client/petstore/go/go-petstore/README.md | 14 +- .../petstore/go/go-petstore/api_client.go | 2 +- .../petstore/go/go-petstore/docs/PetApi.md | 16 +- .../petstore/go/go-petstore/docs/StoreApi.md | 8 +- .../petstore/go/go-petstore/docs/UserApi.md | 16 +- .../client/petstore/go/go-petstore/pet_api.go | 251 ++++++++++-------- .../petstore/go/go-petstore/store_api.go | 107 +++++--- .../petstore/go/go-petstore/user_api.go | 214 +++++++++------ 13 files changed, 400 insertions(+), 931 deletions(-) delete mode 100644 modules/swagger-codegen/src/main/resources/go/api_BACKUP_59234.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/go/api_BASE_59234.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/go/api_LOCAL_59234.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/go/api_REMOTE_59234.mustache diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index cfd5ae0296f..56f286903ac 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -39,7 +39,7 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ */ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { - var httpMethod = {{httpMethod}} + var httpMethod = "{{httpMethod}}" // create path and map variables path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}" {{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) @@ -54,30 +54,32 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/required}} {{/allParams}} - _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) {{#authMethods}}// authentication ({{name}}) required {{#isApiKey}}{{#isKeyInHeader}} // set key with prefix in header - _sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")) + headerParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") {{/isKeyInHeader}}{{#isKeyInQuery}} // set key with prefix in querystring - {{#hasKeyParamName}} type KeyQueryParams struct { - {{keyParamName}} string `url:"{{keyParamName}},omitempty"` - } - _sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") }) + {{#hasKeyParamName}} + queryParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") {{/hasKeyParamName}} {{/isKeyInQuery}}{{/isApiKey}} {{#isBasic}} // http basic authentication required if a.Configuration.Username != "" || a.Configuration.Password != ""{ - _sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString()) + headerParams["Authorization"] = "Basic " + a.Configuration.GetBasicAuthEncodedString() } {{/isBasic}} {{#isOAuth}} // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } {{/isOAuth}} {{/authMethods}} @@ -85,15 +87,14 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } -{{#hasQueryParams}} type QueryParams struct { - {{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` - {{/queryParams}} -} - _sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} }) -{{/hasQueryParams}} + {{#hasQueryParams}} + {{#queryParams}} + queryParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} + {{/queryParams}} + {{/hasQueryParams}} // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -104,7 +105,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -116,16 +117,15 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } {{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" - _sling = _sling.Set("{{baseName}}", {{paramName}}) + headerParams["{{baseName}}"] = {{paramName}} {{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} type FormParams struct { -{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` +{{#hasFormParams}} +{{#formParams}} + headerParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} {{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) {{/hasFormParams}} {{#hasBodyParam}}{{#bodyParams}}// body params _sling = _sling.BodyJSON({{paramName}}) @@ -137,7 +137,8 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) diff --git a/modules/swagger-codegen/src/main/resources/go/api_BACKUP_59234.mustache b/modules/swagger-codegen/src/main/resources/go/api_BACKUP_59234.mustache deleted file mode 100644 index 0cf4d311be4..00000000000 --- a/modules/swagger-codegen/src/main/resources/go/api_BACKUP_59234.mustache +++ /dev/null @@ -1,169 +0,0 @@ -package {{packageName}} - -{{#operations}} -import ( - "strings" - "fmt" - "encoding/json" - "errors" -{{#imports}} "{{import}}" -{{/imports}} -) - -type {{classname}} struct { - Configuration Configuration -} - -func New{{classname}}() *{{classname}}{ - configuration := NewConfiguration() - return &{{classname}} { - Configuration: *configuration, - } -} - -func New{{classname}}WithBasePath(basePath string) *{{classname}}{ - configuration := NewConfiguration() - configuration.BasePath = basePath - - return &{{classname}} { - Configuration: *configuration, - } -} - -{{#operation}} -/** - * {{summary}} - * {{notes}} -{{#allParams}} * @param {{paramName}} {{description}} -{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { -<<<<<<< HEAD - var httpMethod = {{httpMethod}} - // create path and map variables - path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) -{{/pathParams}} - -======= - {{#allParams}} - {{#required}} - // verify the required parameter '{{paramName}}' is set - if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") - } - {{/required}} - {{/allParams}} ->>>>>>> c375f2fed5138125228c6e881df7acf3a8ada17d - _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) - - {{#authMethods}}// authentication ({{name}}) required - {{#isApiKey}}{{#isKeyInHeader}} - // set key with prefix in header - _sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")) - {{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring - {{#hasKeyParamName}} type KeyQueryParams struct { - {{keyParamName}} string `url:"{{keyParamName}},omitempty"` - } - _sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") }) - {{/hasKeyParamName}} - {{/isKeyInQuery}}{{/isApiKey}} - {{#isBasic}} - // http basic authentication required - if a.Configuration.Username != "" || a.Configuration.Password != ""{ - _sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString()) - } - {{/isBasic}} - {{#isOAuth}} - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } - {{/isOAuth}} - {{/authMethods}} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - -{{#hasQueryParams}} type QueryParams struct { - {{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` - {{/queryParams}} -} - _sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} }) -{{/hasQueryParams}} - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - {{#consumes}} - "{{mediaType}}", - {{/consumes}} - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } - - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - {{#produces}} - "{{mediaType}}", - {{/produces}} - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } -{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" - _sling = _sling.Set("{{baseName}}", {{paramName}}) -{{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} type FormParams struct { -{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` -{{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) -{{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) -{{/bodyParams}}{{/hasBodyParam}} -{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return {{#returnType}}*successPayload, {{/returnType}}err -} -{{/operation}} -{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_BASE_59234.mustache b/modules/swagger-codegen/src/main/resources/go/api_BASE_59234.mustache deleted file mode 100644 index f08ba380ec0..00000000000 --- a/modules/swagger-codegen/src/main/resources/go/api_BASE_59234.mustache +++ /dev/null @@ -1,160 +0,0 @@ -package {{packageName}} - -{{#operations}} -import ( - "strings" - "fmt" - "encoding/json" - "errors" - "github.com/dghubble/sling" -{{#imports}} "{{import}}" -{{/imports}} -) - -type {{classname}} struct { - Configuration Configuration -} - -func New{{classname}}() *{{classname}}{ - configuration := NewConfiguration() - return &{{classname}} { - Configuration: *configuration, - } -} - -func New{{classname}}WithBasePath(basePath string) *{{classname}}{ - configuration := NewConfiguration() - configuration.BasePath = basePath - - return &{{classname}} { - Configuration: *configuration, - } -} - -{{#operation}} -/** - * {{summary}} - * {{notes}} -{{#allParams}} * @param {{paramName}} {{description}} -{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { - - _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) - - {{#authMethods}}// authentication ({{name}}) required - {{#isApiKey}}{{#isKeyInHeader}} - // set key with prefix in header - _sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")) - {{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring - {{#hasKeyParamName}} type KeyQueryParams struct { - {{keyParamName}} string `url:"{{keyParamName}},omitempty"` - } - _sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") }) - {{/hasKeyParamName}} - {{/isKeyInQuery}}{{/isApiKey}} - {{#isBasic}} - // http basic authentication required - if a.Configuration.Username != "" || a.Configuration.Password != ""{ - _sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString()) - } - {{/isBasic}} - {{#isOAuth}} - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } - {{/isOAuth}} - {{/authMethods}} - - // create path and map variables - path := "{{basePathWithoutHost}}{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) -{{/pathParams}} - - _sling = _sling.Path(path) - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - -{{#hasQueryParams}} type QueryParams struct { - {{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` - {{/queryParams}} -} - _sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} }) -{{/hasQueryParams}} - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - {{#consumes}} - "{{mediaType}}", - {{/consumes}} - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } - - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - {{#produces}} - "{{mediaType}}", - {{/produces}} - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } -{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" - _sling = _sling.Set("{{baseName}}", {{paramName}}) -{{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} type FormParams struct { -{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` -{{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) -{{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) -{{/bodyParams}}{{/hasBodyParam}} -{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return {{#returnType}}*successPayload, {{/returnType}}err -} -{{/operation}} -{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_LOCAL_59234.mustache b/modules/swagger-codegen/src/main/resources/go/api_LOCAL_59234.mustache deleted file mode 100644 index fec404786d4..00000000000 --- a/modules/swagger-codegen/src/main/resources/go/api_LOCAL_59234.mustache +++ /dev/null @@ -1,158 +0,0 @@ -package {{packageName}} - -{{#operations}} -import ( - "strings" - "fmt" - "encoding/json" - "errors" -{{#imports}} "{{import}}" -{{/imports}} -) - -type {{classname}} struct { - Configuration Configuration -} - -func New{{classname}}() *{{classname}}{ - configuration := NewConfiguration() - return &{{classname}} { - Configuration: *configuration, - } -} - -func New{{classname}}WithBasePath(basePath string) *{{classname}}{ - configuration := NewConfiguration() - configuration.BasePath = basePath - - return &{{classname}} { - Configuration: *configuration, - } -} - -{{#operation}} -/** - * {{summary}} - * {{notes}} -{{#allParams}} * @param {{paramName}} {{description}} -{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { - var httpMethod = {{httpMethod}} - // create path and map variables - path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) -{{/pathParams}} - - _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) - - {{#authMethods}}// authentication ({{name}}) required - {{#isApiKey}}{{#isKeyInHeader}} - // set key with prefix in header - _sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")) - {{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring - {{#hasKeyParamName}} type KeyQueryParams struct { - {{keyParamName}} string `url:"{{keyParamName}},omitempty"` - } - _sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") }) - {{/hasKeyParamName}} - {{/isKeyInQuery}}{{/isApiKey}} - {{#isBasic}} - // http basic authentication required - if a.Configuration.Username != "" || a.Configuration.Password != ""{ - _sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString()) - } - {{/isBasic}} - {{#isOAuth}} - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } - {{/isOAuth}} - {{/authMethods}} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - -{{#hasQueryParams}} type QueryParams struct { - {{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` - {{/queryParams}} -} - _sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} }) -{{/hasQueryParams}} - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - {{#consumes}} - "{{mediaType}}", - {{/consumes}} - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } - - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - {{#produces}} - "{{mediaType}}", - {{/produces}} - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } -{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" - _sling = _sling.Set("{{baseName}}", {{paramName}}) -{{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} type FormParams struct { -{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` -{{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) -{{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) -{{/bodyParams}}{{/hasBodyParam}} -{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return {{#returnType}}*successPayload, {{/returnType}}err -} -{{/operation}} -{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_REMOTE_59234.mustache b/modules/swagger-codegen/src/main/resources/go/api_REMOTE_59234.mustache deleted file mode 100644 index 35ed984929d..00000000000 --- a/modules/swagger-codegen/src/main/resources/go/api_REMOTE_59234.mustache +++ /dev/null @@ -1,167 +0,0 @@ -package {{packageName}} - -{{#operations}} -import ( - "strings" - "fmt" - "encoding/json" - "errors" - "github.com/dghubble/sling" -{{#imports}} "{{import}}" -{{/imports}} -) - -type {{classname}} struct { - Configuration Configuration -} - -func New{{classname}}() *{{classname}}{ - configuration := NewConfiguration() - return &{{classname}} { - Configuration: *configuration, - } -} - -func New{{classname}}WithBasePath(basePath string) *{{classname}}{ - configuration := NewConfiguration() - configuration.BasePath = basePath - - return &{{classname}} { - Configuration: *configuration, - } -} - -{{#operation}} -/** - * {{summary}} - * {{notes}} -{{#allParams}} * @param {{paramName}} {{description}} -{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { - {{#allParams}} - {{#required}} - // verify the required parameter '{{paramName}}' is set - if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") - } - {{/required}} - {{/allParams}} - _sling := sling.New().{{httpMethod}}(a.Configuration.BasePath) - - {{#authMethods}}// authentication ({{name}}) required - {{#isApiKey}}{{#isKeyInHeader}} - // set key with prefix in header - _sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")) - {{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring - {{#hasKeyParamName}} type KeyQueryParams struct { - {{keyParamName}} string `url:"{{keyParamName}},omitempty"` - } - _sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") }) - {{/hasKeyParamName}} - {{/isKeyInQuery}}{{/isApiKey}} - {{#isBasic}} - // http basic authentication required - if a.Configuration.Username != "" || a.Configuration.Password != ""{ - _sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString()) - } - {{/isBasic}} - {{#isOAuth}} - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } - {{/isOAuth}} - {{/authMethods}} - - // create path and map variables - path := "{{basePathWithoutHost}}{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) -{{/pathParams}} - - _sling = _sling.Path(path) - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - -{{#hasQueryParams}} type QueryParams struct { - {{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` - {{/queryParams}} -} - _sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} }) -{{/hasQueryParams}} - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - {{#consumes}} - "{{mediaType}}", - {{/consumes}} - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } - - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - {{#produces}} - "{{mediaType}}", - {{/produces}} - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } -{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" - _sling = _sling.Set("{{baseName}}", {{paramName}}) -{{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} type FormParams struct { -{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"` -{{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) -{{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) -{{/bodyParams}}{{/hasBodyParam}} -{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} - - httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } - } - - return {{#returnType}}*successPayload, {{/returnType}}err -} -{{/operation}} -{{/operations}} diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index 5890d48282a..f8e134982d8 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-04-17T16:17:52.285+08:00 +- Build date: 2016-04-17T23:42:10.705-07:00 - Build package: class io.swagger.codegen.languages.GoClientCodegen ## Installation @@ -57,12 +57,6 @@ Class | Method | HTTP request | Description ## Documentation For Authorization -## api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ## petstore_auth - **Type**: OAuth @@ -72,6 +66,12 @@ Class | Method | HTTP request | Description - **write:pets**: modify pets in your account - **read:pets**: read your pets +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ## Author diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 92114983bdd..63d5f06ad0b 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -42,7 +42,7 @@ func contains(source []string, containvalue string) bool { return false } -func CallApiAsync(path string, method string, +func CallApi(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/docs/PetApi.md b/samples/client/petstore/go/go-petstore/docs/PetApi.md index 5dad1949b04..9caa3df6865 100644 --- a/samples/client/petstore/go/go-petstore/docs/PetApi.md +++ b/samples/client/petstore/go/go-petstore/docs/PetApi.md @@ -36,7 +36,7 @@ void (empty response body) [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: application/json, application/xml - **Accept**: application/xml, application/json @@ -66,7 +66,7 @@ void (empty response body) [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -95,7 +95,7 @@ Name | Type | Description | Notes [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -124,7 +124,7 @@ Name | Type | Description | Notes [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -153,7 +153,7 @@ Name | Type | Description | Notes [api_key](../README.md#api_key) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -182,7 +182,7 @@ void (empty response body) [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: application/json, application/xml - **Accept**: application/xml, application/json @@ -213,7 +213,7 @@ void (empty response body) [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: application/x-www-form-urlencoded - **Accept**: application/xml, application/json @@ -244,7 +244,7 @@ Name | Type | Description | Notes [petstore_auth](../README.md#petstore_auth) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: multipart/form-data - **Accept**: application/json diff --git a/samples/client/petstore/go/go-petstore/docs/StoreApi.md b/samples/client/petstore/go/go-petstore/docs/StoreApi.md index 11939c1edba..1ee858d2e30 100644 --- a/samples/client/petstore/go/go-petstore/docs/StoreApi.md +++ b/samples/client/petstore/go/go-petstore/docs/StoreApi.md @@ -32,7 +32,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -58,7 +58,7 @@ This endpoint does not need any parameter. [api_key](../README.md#api_key) -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json @@ -87,7 +87,7 @@ Name | Type | Description | Notes No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -116,7 +116,7 @@ Name | Type | Description | Notes No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json diff --git a/samples/client/petstore/go/go-petstore/docs/UserApi.md b/samples/client/petstore/go/go-petstore/docs/UserApi.md index 79ee5175bbd..4950105ca86 100644 --- a/samples/client/petstore/go/go-petstore/docs/UserApi.md +++ b/samples/client/petstore/go/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -65,7 +65,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -94,7 +94,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -123,7 +123,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -152,7 +152,7 @@ Name | Type | Description | Notes No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -182,7 +182,7 @@ Name | Type | Description | Notes No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -208,7 +208,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json @@ -238,7 +238,7 @@ void (empty response body) No authorization required -### HTTP reuqest headers +### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 461df7449f3..0b82f7d703e 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "github.com/dghubble/sling" "os" ) @@ -36,27 +35,33 @@ func NewPetApiWithBasePath(basePath string) *PetApi{ * @return void */ func (a PetApi) AddPet (body Pet) (error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet" + // verify the required parameter 'body' is set if &body == nil { return errors.New("Missing required parameter 'body' when calling PetApi->AddPet") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -68,7 +73,7 @@ func (a PetApi) AddPet (body Pet) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -79,7 +84,7 @@ func (a PetApi) AddPet (body Pet) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -92,7 +97,8 @@ func (a PetApi) AddPet (body Pet) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -127,28 +133,34 @@ func (a PetApi) AddPet (body Pet) (error) { * @return void */ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { + + var httpMethod = "Delete" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + // verify the required parameter 'petId' is set if &petId == nil { return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") } - _sling := sling.New().Delete(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -158,7 +170,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -169,10 +181,10 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // header params "api_key" - _sling = _sling.Set("api_key", apiKey) + headerParams["api_key"] = apiKey @@ -182,7 +194,8 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -216,33 +229,36 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { * @return []Pet */ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/findByStatus" + // verify the required parameter 'status' is set if &status == nil { return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet/findByStatus" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } - type QueryParams struct { - Status []string `url:"status,omitempty"` -} - _sling = _sling.QueryStruct(&QueryParams{ Status: status }) + queryParams["Status"] = status // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -250,7 +266,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -261,7 +277,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -272,7 +288,8 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -306,33 +323,36 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { * @return []Pet */ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/findByTags" + // verify the required parameter 'tags' is set if &tags == nil { return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet/findByTags" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } - type QueryParams struct { - Tags []string `url:"tags,omitempty"` -} - _sling = _sling.QueryStruct(&QueryParams{ Tags: tags }) + queryParams["Tags"] = tags // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -340,7 +360,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -351,7 +371,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -362,7 +382,8 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -396,27 +417,33 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { * @return Pet */ func (a PetApi) GetPetById (petId int64) (Pet, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + // verify the required parameter 'petId' is set if &petId == nil { return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (api_key) required // set key with prefix in header - _sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")) + headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - // create path and map variables - path := "/v2/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -426,7 +453,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -437,7 +464,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -448,7 +475,8 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -482,27 +510,33 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { * @return void */ func (a PetApi) UpdatePet (body Pet) (error) { + + var httpMethod = "Put" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet" + // verify the required parameter 'body' is set if &body == nil { return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") } - _sling := sling.New().Put(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -514,7 +548,7 @@ func (a PetApi) UpdatePet (body Pet) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -525,7 +559,7 @@ func (a PetApi) UpdatePet (body Pet) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -538,7 +572,8 @@ func (a PetApi) UpdatePet (body Pet) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -574,28 +609,34 @@ func (a PetApi) UpdatePet (body Pet) (error) { * @return void */ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + // verify the required parameter 'petId' is set if &petId == nil { return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -606,7 +647,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -617,14 +658,11 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } - type FormParams struct { - Name string `url:"name,omitempty"` - Status string `url:"status,omitempty"` - } - _sling = _sling.BodyForm(&FormParams{ Name: name,Status: status }) + headerParams["Name"] = name + headerParams["Status"] = status @@ -633,7 +671,8 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -669,28 +708,34 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err * @return ApiResponse */ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/pet/{petId}/uploadImage" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + // verify the required parameter 'petId' is set if &petId == nil { return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (petstore_auth) required // oauth required if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // create path and map variables - path := "/v2/pet/{petId}/uploadImage" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -701,7 +746,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -711,14 +756,11 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } - type FormParams struct { - AdditionalMetadata string `url:"additionalMetadata,omitempty"` - File *os.File `url:"file,omitempty"` - } - _sling = _sling.BodyForm(&FormParams{ AdditionalMetadata: additionalMetadata,File: file }) + headerParams["AdditionalMetadata"] = additionalMetadata + headerParams["File"] = file var successPayload = new(ApiResponse) @@ -727,7 +769,8 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 2fa59c1efd1..5672babce9b 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "github.com/dghubble/sling" ) type StoreApi struct { @@ -35,22 +34,28 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{ * @return void */ func (a StoreApi) DeleteOrder (orderId string) (error) { + + var httpMethod = "Delete" + // create path and map variables + path := c.Configuration.BasePath + "/v2/store/order/{orderId}" + path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + // verify the required parameter 'orderId' is set if &orderId == nil { return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") } - _sling := sling.New().Delete(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -60,7 +65,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -71,7 +76,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -82,7 +87,8 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -115,22 +121,28 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { * @return map[string]int32 */ func (a StoreApi) GetInventory () (map[string]int32, error) { - _sling := sling.New().Get(a.Configuration.BasePath) + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/store/inventory" + + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) // authentication (api_key) required // set key with prefix in header - _sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")) + headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - // create path and map variables - path := "/v2/store/inventory" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -140,7 +152,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -150,7 +162,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -161,7 +173,8 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -195,22 +208,28 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { * @return Order */ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/store/order/{orderId}" + path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + // verify the required parameter 'orderId' is set if &orderId == nil { return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -220,7 +239,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -231,7 +250,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -242,7 +261,8 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -276,21 +296,27 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { * @return Order */ func (a StoreApi) PlaceOrder (body Order) (Order, error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/store/order" + // verify the required parameter 'body' is set if &body == nil { return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/store/order" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -300,7 +326,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -311,7 +337,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -324,7 +350,8 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index b6639d9e65f..e406e4f87e6 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "github.com/dghubble/sling" ) type UserApi struct { @@ -35,21 +34,27 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ * @return void */ func (a UserApi) CreateUser (body User) (error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user" + // verify the required parameter 'body' is set if &body == nil { return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -59,7 +64,7 @@ func (a UserApi) CreateUser (body User) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -70,7 +75,7 @@ func (a UserApi) CreateUser (body User) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -83,7 +88,8 @@ func (a UserApi) CreateUser (body User) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -117,21 +123,27 @@ func (a UserApi) CreateUser (body User) (error) { * @return void */ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/createWithArray" + // verify the required parameter 'body' is set if &body == nil { return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/createWithArray" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -141,7 +153,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -152,7 +164,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -165,7 +177,8 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -199,21 +212,27 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { * @return void */ func (a UserApi) CreateUsersWithListInput (body []User) (error) { + + var httpMethod = "Post" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/createWithList" + // verify the required parameter 'body' is set if &body == nil { return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") } - _sling := sling.New().Post(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/createWithList" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -223,7 +242,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -234,7 +253,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -247,7 +266,8 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -281,22 +301,28 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { * @return void */ func (a UserApi) DeleteUser (username string) (error) { + + var httpMethod = "Delete" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/{username}" + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + // verify the required parameter 'username' is set if &username == nil { return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") } - _sling := sling.New().Delete(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -306,7 +332,7 @@ func (a UserApi) DeleteUser (username string) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -317,7 +343,7 @@ func (a UserApi) DeleteUser (username string) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -328,7 +354,8 @@ func (a UserApi) DeleteUser (username string) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -362,22 +389,28 @@ func (a UserApi) DeleteUser (username string) (error) { * @return User */ func (a UserApi) GetUserByName (username string) (User, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/{username}" + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + // verify the required parameter 'username' is set if &username == nil { return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -387,7 +420,7 @@ func (a UserApi) GetUserByName (username string) (User, error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -398,7 +431,7 @@ func (a UserApi) GetUserByName (username string) (User, error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -409,7 +442,8 @@ func (a UserApi) GetUserByName (username string) (User, error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -444,6 +478,11 @@ func (a UserApi) GetUserByName (username string) (User, error) { * @return string */ func (a UserApi) LoginUser (username string, password string) (string, error) { + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/login" + // verify the required parameter 'username' is set if &username == nil { return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") @@ -452,24 +491,22 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { if &password == nil { return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") } - _sling := sling.New().Get(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/login" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } - type QueryParams struct { - Username string `url:"username,omitempty"` -Password string `url:"password,omitempty"` -} - _sling = _sling.QueryStruct(&QueryParams{ Username: username,Password: password }) + queryParams["Username"] = username + queryParams["Password"] = password // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -477,7 +514,7 @@ Password string `url:"password,omitempty"` //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -488,7 +525,7 @@ Password string `url:"password,omitempty"` //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -499,7 +536,8 @@ Password string `url:"password,omitempty"` // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(successPayload, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(successPayload, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -532,17 +570,23 @@ Password string `url:"password,omitempty"` * @return void */ func (a UserApi) LogoutUser () (error) { - _sling := sling.New().Get(a.Configuration.BasePath) + + var httpMethod = "Get" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/logout" + + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/logout" - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -552,7 +596,7 @@ func (a UserApi) LogoutUser () (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -563,7 +607,7 @@ func (a UserApi) LogoutUser () (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } @@ -574,7 +618,8 @@ func (a UserApi) LogoutUser () (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) @@ -609,6 +654,12 @@ func (a UserApi) LogoutUser () (error) { * @return void */ func (a UserApi) UpdateUser (username string, body User) (error) { + + var httpMethod = "Put" + // create path and map variables + path := c.Configuration.BasePath + "/v2/user/{username}" + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + // verify the required parameter 'username' is set if &username == nil { return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") @@ -617,18 +668,18 @@ func (a UserApi) UpdateUser (username string, body User) (error) { if &body == nil { return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") } - _sling := sling.New().Put(a.Configuration.BasePath) + + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + fileParams := make(map[string]string) + formBody := make(interface{}) - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - - _sling = _sling.Path(path) // add default headers if any for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + headerParams[key] = a.Configuration.DefaultHeader[key] } @@ -638,7 +689,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) { //set Content-Type header localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) + headerParams["Content-Type"] = localVarHttpContentType } // to determine the Accept header @@ -649,7 +700,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) { //set Accept header localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) + headerParams["Accept"] = localVarHttpHeaderAccept } // body params @@ -662,7 +713,8 @@ func (a UserApi) UpdateUser (username string, body User) (error) { // response (error) models, which needs to be implemented at some point. var failurePayload map[string]interface{} - httpResponse, err := _sling.Receive(nil, &failurePayload) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) + //httpResponse, err := _sling.Receive(nil, &failurePayload) if err == nil { // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) From 36219a00e9a6c0ea0232901a4624b618a98da604 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 14:38:11 -0700 Subject: [PATCH 04/24] fix go build errors after upgrading to the new api client --- .../src/main/resources/go/api.mustache | 52 +-- .../src/main/resources/go/api_client.mustache | 16 +- .../petstore/go/go-petstore/api_client.go | 16 +- .../client/petstore/go/go-petstore/pet_api.go | 327 ++++-------------- .../petstore/go/go-petstore/store_api.go | 160 ++------- .../petstore/go/go-petstore/user_api.go | 325 ++++------------- 6 files changed, 204 insertions(+), 692 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 56f286903ac..0edb1a7d5c9 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -6,6 +6,7 @@ import ( "fmt" "encoding/json" "errors" + "bytes" {{#imports}} "{{import}}" {{/imports}} ) @@ -41,7 +42,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ var httpMethod = "{{httpMethod}}" // create path and map variables - path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}" + path := a.Configuration.BasePath + "{{path}}" {{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) {{/pathParams}} @@ -58,7 +59,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} {{#authMethods}}// authentication ({{name}}) required {{#isApiKey}}{{#isKeyInHeader}} @@ -84,7 +85,6 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/isOAuth}} {{/authMethods}} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -92,7 +92,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasQueryParams}} {{#queryParams}} - queryParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} + queryParams["{{vendorExtensions.x-exportParamName}}"] = strings.Join({{paramName}}, ",") {{/queryParams}} {{/hasQueryParams}} @@ -107,7 +107,6 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { {{#produces}} @@ -124,45 +123,26 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/headerParams}}{{/hasHeaderParams}} {{#hasFormParams}} {{#formParams}} - headerParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} + formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} {{/formParams}} {{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) +{{#hasBodyParam}}{{#bodyParams}} + // body params + postBody = &{{paramName}} {{/bodyParams}}{{/hasBodyParam}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return {{#returnType}}*successPayload, {{/returnType}}err } +{{#returnType}} + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) +{{/returnType}} + return {{#returnType}}*successPayload, {{/returnType}}err } {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index eec9853db37..5ff56a31cfc 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -42,16 +42,16 @@ func contains(source []string, containvalue string) bool { return false } -func CallApi(path string, method string, +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) { + verb := strings.ToUpper(method) + request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams) - request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) - - switch strings.ToUpper(method) { + switch verb { case "GET": response, err := request.Get(path) return response, err @@ -72,7 +72,7 @@ func CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func prepareRequest(postBody interface{}, +func prepareRequest(verb string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, @@ -92,7 +92,9 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) // add file parameter, if any - request.SetFiles(fileParams) - + if verb != "GET"{ + request.SetFiles(fileParams) + } + return request } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 63d5f06ad0b..f178cbddcff 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -42,16 +42,16 @@ func contains(source []string, containvalue string) bool { return false } -func CallApi(path string, method string, +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) { + verb := strings.ToUpper(method) + request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams) - request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) - - switch strings.ToUpper(method) { + switch verb { case "GET": response, err := request.Get(path) return response, err @@ -72,7 +72,7 @@ func CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func prepareRequest(postBody interface{}, +func prepareRequest(verb string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, @@ -92,7 +92,9 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) // add file parameter, if any - request.SetFiles(fileParams) - + if verb != "GET"{ + request.SetFiles(fileParams) + } + return request } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 0b82f7d703e..af0c05e45b7 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -5,6 +5,7 @@ import ( "fmt" "encoding/json" "errors" + "bytes" "os" ) @@ -38,7 +39,7 @@ func (a PetApi) AddPet (body Pet) (error) { var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet" + path := a.Configuration.BasePath + "/pet" // verify the required parameter 'body' is set if &body == nil { @@ -49,7 +50,7 @@ func (a PetApi) AddPet (body Pet) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -58,7 +59,6 @@ func (a PetApi) AddPet (body Pet) (error) { headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -87,42 +87,19 @@ func (a PetApi) AddPet (body Pet) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 0{ + return err } + return err } /** @@ -136,7 +113,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { var httpMethod = "Delete" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/{petId}" + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set @@ -148,7 +125,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -157,7 +134,6 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -189,37 +165,13 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -232,7 +184,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/findByStatus" + path := a.Configuration.BasePath + "/pet/findByStatus" // verify the required parameter 'status' is set if &status == nil { @@ -243,7 +195,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -252,13 +204,12 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Status"] = status + queryParams["Status"] = strings.Join(status, ",") // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -283,37 +234,15 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { var successPayload = new([]Pet) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -326,7 +255,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/findByTags" + path := a.Configuration.BasePath + "/pet/findByTags" // verify the required parameter 'tags' is set if &tags == nil { @@ -337,7 +266,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -346,13 +275,12 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Tags"] = tags + queryParams["Tags"] = strings.Join(tags, ",") // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -377,37 +305,15 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { var successPayload = new([]Pet) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -420,7 +326,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/{petId}" + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set @@ -432,7 +338,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (api_key) required @@ -440,7 +346,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -470,37 +375,15 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { var successPayload = new(Pet) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -513,7 +396,7 @@ func (a PetApi) UpdatePet (body Pet) (error) { var httpMethod = "Put" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet" + path := a.Configuration.BasePath + "/pet" // verify the required parameter 'body' is set if &body == nil { @@ -524,7 +407,7 @@ func (a PetApi) UpdatePet (body Pet) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -533,7 +416,6 @@ func (a PetApi) UpdatePet (body Pet) (error) { headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -562,42 +444,19 @@ func (a PetApi) UpdatePet (body Pet) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -612,7 +471,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/{petId}" + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set @@ -624,7 +483,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -633,7 +492,6 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -661,42 +519,18 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams["Accept"] = localVarHttpHeaderAccept } - headerParams["Name"] = name - headerParams["Status"] = status + formParams["Name"] = name + formParams["Status"] = status - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -711,7 +545,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/pet/{petId}/uploadImage" + path := a.Configuration.BasePath + "/pet/{petId}/uploadImage" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set @@ -723,7 +557,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (petstore_auth) required @@ -732,7 +566,6 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken } - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -759,41 +592,19 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams["Accept"] = localVarHttpHeaderAccept } - headerParams["AdditionalMetadata"] = additionalMetadata - headerParams["File"] = file + formParams["AdditionalMetadata"] = additionalMetadata + formParams["File"] = file var successPayload = new(ApiResponse) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 5672babce9b..0166b084f79 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -5,6 +5,7 @@ import ( "fmt" "encoding/json" "errors" + "bytes" ) type StoreApi struct { @@ -37,7 +38,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { var httpMethod = "Delete" // create path and map variables - path := c.Configuration.BasePath + "/v2/store/order/{orderId}" + path := a.Configuration.BasePath + "/store/order/{orderId}" path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) // verify the required parameter 'orderId' is set @@ -49,10 +50,9 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -82,37 +82,13 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -124,14 +100,14 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/store/inventory" + path := a.Configuration.BasePath + "/store/inventory" headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} // authentication (api_key) required @@ -139,7 +115,6 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -168,37 +143,15 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { var successPayload = new(map[string]int32) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -211,7 +164,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/store/order/{orderId}" + path := a.Configuration.BasePath + "/store/order/{orderId}" path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) // verify the required parameter 'orderId' is set @@ -223,10 +176,9 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -256,37 +208,15 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { var successPayload = new(Order) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -299,7 +229,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/store/order" + path := a.Configuration.BasePath + "/store/order" // verify the required parameter 'body' is set if &body == nil { @@ -310,10 +240,9 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -340,41 +269,20 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body var successPayload = new(Order) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index e406e4f87e6..6729a5cd265 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -5,6 +5,7 @@ import ( "fmt" "encoding/json" "errors" + "bytes" ) type UserApi struct { @@ -37,7 +38,7 @@ func (a UserApi) CreateUser (body User) (error) { var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/user" + path := a.Configuration.BasePath + "/user" // verify the required parameter 'body' is set if &body == nil { @@ -48,10 +49,9 @@ func (a UserApi) CreateUser (body User) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -78,42 +78,19 @@ func (a UserApi) CreateUser (body User) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -126,7 +103,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/createWithArray" + path := a.Configuration.BasePath + "/user/createWithArray" // verify the required parameter 'body' is set if &body == nil { @@ -137,10 +114,9 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -167,42 +143,19 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -215,7 +168,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { var httpMethod = "Post" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/createWithList" + path := a.Configuration.BasePath + "/user/createWithList" // verify the required parameter 'body' is set if &body == nil { @@ -226,10 +179,9 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -256,42 +208,19 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -304,7 +233,7 @@ func (a UserApi) DeleteUser (username string) (error) { var httpMethod = "Delete" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/{username}" + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set @@ -316,10 +245,9 @@ func (a UserApi) DeleteUser (username string) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -349,37 +277,13 @@ func (a UserApi) DeleteUser (username string) (error) { - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -392,7 +296,7 @@ func (a UserApi) GetUserByName (username string) (User, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/{username}" + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set @@ -404,10 +308,9 @@ func (a UserApi) GetUserByName (username string) (User, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -437,37 +340,15 @@ func (a UserApi) GetUserByName (username string) (User, error) { var successPayload = new(User) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -481,7 +362,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/login" + path := a.Configuration.BasePath + "/user/login" // verify the required parameter 'username' is set if &username == nil { @@ -496,17 +377,16 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Username"] = username - queryParams["Password"] = password + queryParams["Username"] = strings.Join(username, ",") + queryParams["Password"] = strings.Join(password, ",") // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -531,37 +411,15 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { var successPayload = new(string) - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(successPayload, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return *successPayload, err } + decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) + err = decoder.Decode(&successPayload) + return *successPayload, err } /** @@ -573,17 +431,16 @@ func (a UserApi) LogoutUser () (error) { var httpMethod = "Get" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/logout" + path := a.Configuration.BasePath + "/user/logout" headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -613,37 +470,13 @@ func (a UserApi) LogoutUser () (error) { - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } /** @@ -657,7 +490,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) { var httpMethod = "Put" // create path and map variables - path := c.Configuration.BasePath + "/v2/user/{username}" + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set @@ -673,10 +506,9 @@ func (a UserApi) UpdateUser (username string, body User) (error) { queryParams := make(map[string]string) formParams := make(map[string]string) fileParams := make(map[string]string) - formBody := make(interface{}) + var postBody interface{} - // add default headers if any for key := range a.Configuration.DefaultHeader { headerParams[key] = a.Configuration.DefaultHeader[key] @@ -703,41 +535,18 @@ func (a UserApi) UpdateUser (username string, body User) (error) { headerParams["Accept"] = localVarHttpHeaderAccept } -// body params - _sling = _sling.BodyJSON(body) + + // body params + postBody = &body - // We use this map (below) so that any arbitrary error JSON can be handled. - // FIXME: This is in the absence of this Go generator honoring the non-2xx - // response (error) models, which needs to be implemented at some point. - var failurePayload map[string]interface{} + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams) - //httpResponse, err := _sling.Receive(nil, &failurePayload) - - if err == nil { - // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error) - if failurePayload != nil { - // If the failurePayload is present, there likely was some kind of non-2xx status - // returned (and a JSON payload error present) - var str []byte - str, err = json.Marshal(failurePayload) - if err == nil { // For safety, check for an error marshalling... probably superfluous - // This will return the JSON error body as a string - err = errors.New(string(str)) - } - } else { - // So, there was no network-type error, and nothing in the failure payload, - // but we should still check the status code - if httpResponse == nil { - // This should never happen... - err = errors.New("No HTTP Response received.") - } else if code := httpResponse.StatusCode; 200 > code || code > 299 { - err = errors.New("HTTP Error: " + string(httpResponse.StatusCode)) - } - } + if err != nil && httpResponse.StatusCode() != 200{ + return err } + return err } From af19a70f723a551778e86e6ab5d1697f45698f54 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 17:09:47 -0700 Subject: [PATCH 05/24] updated api_client.go to ensure there is value before setting the request --- .../src/main/resources/go/api_client.mustache | 25 ++++++++++++------- .../petstore/go/go-petstore/api_client.go | 25 ++++++++++++------- .../client/petstore/go/go-petstore/pet_api.go | 10 +------- .../petstore/go/go-petstore/store_api.go | 4 --- .../petstore/go/go-petstore/user_api.go | 8 ------ 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 5ff56a31cfc..a4f06b30828 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool { return false } + 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) { - verb := strings.ToUpper(method) - request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams) - switch verb { + request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) + + switch strings.ToUpper(method) { case "GET": response, err := request.Get(path) return response, err @@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func prepareRequest(verb string, postBody interface{}, +func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, @@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{}, request.SetBody(postBody) // add header parameter, if any - request.SetHeaders(headerParams) - + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + // add query parameter, if any - request.SetQueryParams(queryParams) + if len(queryParams) > 0 { + request.SetQueryParams(queryParams) + } // add form parameter, if any - request.SetFormData(formParams) + if len(fileParams) > 0 { + request.SetFormData(formParams) + } // add file parameter, if any - if verb != "GET"{ + if len(fileParams) > 0 { request.SetFiles(fileParams) } diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index f178cbddcff..e8bc409811d 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool { return false } + 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) { - verb := strings.ToUpper(method) - request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams) - switch verb { + request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams) + + switch strings.ToUpper(method) { case "GET": response, err := request.Get(path) return response, err @@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func prepareRequest(verb string, postBody interface{}, +func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, @@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{}, request.SetBody(postBody) // add header parameter, if any - request.SetHeaders(headerParams) - + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + // add query parameter, if any - request.SetQueryParams(queryParams) + if len(queryParams) > 0 { + request.SetQueryParams(queryParams) + } // add form parameter, if any - request.SetFormData(formParams) + if len(fileParams) > 0 { + request.SetFormData(formParams) + } // add file parameter, if any - if verb != "GET"{ + if len(fileParams) > 0 { request.SetFiles(fileParams) } diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index af0c05e45b7..9b0debc95ac 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -75,7 +75,6 @@ func (a PetApi) AddPet (body Pet) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -95,7 +94,7 @@ func (a PetApi) AddPet (body Pet) (error) { httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - if err != nil && httpResponse.StatusCode() != 0{ + if err != nil && httpResponse.StatusCode() != 200{ return err } @@ -148,7 +147,6 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -219,7 +217,6 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -290,7 +287,6 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -360,7 +356,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -432,7 +427,6 @@ func (a PetApi) UpdatePet (body Pet) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -507,7 +501,6 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -581,7 +574,6 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/json", diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 0166b084f79..5f4694cd9db 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -67,7 +67,6 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -129,7 +128,6 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/json", @@ -193,7 +191,6 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -257,7 +254,6 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 6729a5cd265..a53788439f1 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -66,7 +66,6 @@ func (a UserApi) CreateUser (body User) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -131,7 +130,6 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -196,7 +194,6 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -262,7 +259,6 @@ func (a UserApi) DeleteUser (username string) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -325,7 +321,6 @@ func (a UserApi) GetUserByName (username string) (User, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -396,7 +391,6 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -455,7 +449,6 @@ func (a UserApi) LogoutUser () (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", @@ -523,7 +516,6 @@ func (a UserApi) UpdateUser (username string, body User) (error) { if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header localVarHttpHeaderAccepts := []string { "application/xml", From 2fcda964adc0b5b1ce526dc9e75ae2f70525983a Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 23:06:18 -0700 Subject: [PATCH 06/24] added ParameterToString method to handle string array issue --- .../swagger-codegen/src/main/resources/go/api.mustache | 2 +- .../src/main/resources/go/api_client.mustache | 9 +++++++++ samples/client/petstore/go/go-petstore/api_client.go | 9 +++++++++ samples/client/petstore/go/go-petstore/pet_api.go | 6 +++--- samples/client/petstore/go/go-petstore/user_api.go | 4 ++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 0edb1a7d5c9..14106c25ddf 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -92,7 +92,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasQueryParams}} {{#queryParams}} - queryParams["{{vendorExtensions.x-exportParamName}}"] = strings.Join({{paramName}}, ",") + queryParams["{{vendorExtensions.x-exportParamName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) {{/queryParams}} {{/hasQueryParams}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index a4f06b30828..ad2d148e052 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -4,6 +4,7 @@ import ( "strings" "github.com/go-resty/resty" "errors" + "reflect" ) type ApiClient struct { @@ -73,6 +74,14 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } +func (c *ApiClient) ParameterToString (obj interface{}) string { + if reflect.TypeOf(obj).Len() > 0 { + return strings.Join(obj.([]string), ",") + } else{ + return obj.(string) + } +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index e8bc409811d..3440a83a9fd 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/go-resty/resty" "errors" + "reflect" ) type ApiClient struct { @@ -73,6 +74,14 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } +func (c *ApiClient) ParameterToString (obj interface{}) string { + if reflect.TypeOf(obj).Len() > 0 { + return strings.Join(obj.([]string), ",") + } else{ + return obj.(string) + } +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 9b0debc95ac..63a2c6a3627 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -207,7 +207,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Status"] = strings.Join(status, ",") + queryParams["Status"] = a.Configuration.ApiClient.ParameterToString(status) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -277,7 +277,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Tags"] = strings.Join(tags, ",") + queryParams["Tags"] = a.Configuration.ApiClient.ParameterToString(tags) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -585,7 +585,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil } formParams["AdditionalMetadata"] = additionalMetadata - formParams["File"] = file + formParams["File"] = file.Name() var successPayload = new(ApiResponse) diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index a53788439f1..2d5dc5fb8d5 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -380,8 +380,8 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Username"] = strings.Join(username, ",") - queryParams["Password"] = strings.Join(password, ",") + queryParams["Username"] = a.Configuration.ApiClient.ParameterToString(username) + queryParams["Password"] = a.Configuration.ApiClient.ParameterToString(password) // to determine the Content-Type header localVarHttpContentTypes := []string { From b57d27d3fc74abf54dbad1e51b291a5ba0a1d379 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 23:15:26 -0700 Subject: [PATCH 07/24] added isFile logic to generate file parameters --- modules/swagger-codegen/src/main/resources/go/api.mustache | 5 +++++ samples/client/petstore/go/go-petstore/pet_api.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 14106c25ddf..f1657ab3bd1 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -123,7 +123,12 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/headerParams}}{{/hasHeaderParams}} {{#hasFormParams}} {{#formParams}} + {{#isFile}} + fileParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}}.Name() + {{/isFile}} + {{^isFile}} formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} + {{/isFile}} {{/formParams}} {{/hasFormParams}} {{#hasBodyParam}}{{#bodyParams}} diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 63a2c6a3627..b69816a72ba 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -585,7 +585,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil } formParams["AdditionalMetadata"] = additionalMetadata - formParams["File"] = file.Name() + fileParams["File"] = file.Name() var successPayload = new(ApiResponse) From d0123f40b75e1fea17604652e336af84a9c5c2cf Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 18 Apr 2016 23:30:30 -0700 Subject: [PATCH 08/24] fixed go reflection type checking issue --- .../swagger-codegen/src/main/resources/go/api_client.mustache | 2 +- samples/client/petstore/go/go-petstore/api_client.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index ad2d148e052..b5656eaabf2 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -75,7 +75,7 @@ func (c *ApiClient) CallApi(path string, method string, } func (c *ApiClient) ParameterToString (obj interface{}) string { - if reflect.TypeOf(obj).Len() > 0 { + if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else{ return obj.(string) diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 3440a83a9fd..e530c1d1777 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -75,7 +75,7 @@ func (c *ApiClient) CallApi(path string, method string, } func (c *ApiClient) ParameterToString (obj interface{}) string { - if reflect.TypeOf(obj).Len() > 0 { + if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else{ return obj.(string) From fe1afc35e6f5516f2d7e64fc40beed7095b3a88d Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 19 Apr 2016 11:46:57 -0700 Subject: [PATCH 09/24] Removed fileParams as the file content will be posted via postBody, fixed file upload issue --- .../codegen/languages/GoClientCodegen.java | 1 + .../src/main/resources/go/api.mustache | 16 ++--- .../src/main/resources/go/api_client.mustache | 20 ++---- .../petstore/go/go-petstore/api_client.go | 20 ++---- .../client/petstore/go/go-petstore/pet_api.go | 66 +++++++------------ .../petstore/go/go-petstore/store_api.go | 28 +++----- .../petstore/go/go-petstore/user_api.go | 56 +++++----------- 7 files changed, 63 insertions(+), 144 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index 93144cf7afc..b23ab32163e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -104,6 +104,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { importMapping = new HashMap(); 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).") diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index f1657ab3bd1..cf548d7950c 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -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 } diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index b5656eaabf2..60281c98249 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -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 } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index e530c1d1777..9c8eb12b2be 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -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 } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index b69816a72ba..9ea228d6624 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -7,6 +7,7 @@ import ( "errors" "bytes" "os" + "io/ioutil" ) type PetApi struct { @@ -49,7 +50,6 @@ func (a PetApi) AddPet (body Pet) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -91,10 +91,8 @@ func (a PetApi) AddPet (body Pet) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -123,7 +121,6 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -162,10 +159,8 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -192,7 +187,6 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -230,10 +224,8 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { var successPayload = new([]Pet) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -262,7 +254,6 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -300,10 +291,8 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { var successPayload = new([]Pet) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -333,7 +322,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (api_key) required @@ -369,10 +357,8 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { var successPayload = new(Pet) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -401,7 +387,6 @@ func (a PetApi) UpdatePet (body Pet) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -443,10 +428,8 @@ func (a PetApi) UpdatePet (body Pet) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -476,7 +459,6 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -512,14 +494,12 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["Name"] = name - formParams["Status"] = status + formParams["Name"] = name + formParams["Status"] = status - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -549,7 +529,6 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (petstore_auth) required @@ -584,14 +563,13 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["AdditionalMetadata"] = additionalMetadata - fileParams["File"] = file.Name() + formParams["AdditionalMetadata"] = additionalMetadata + fileBytes, _ := ioutil.ReadAll(file) + postBody = fileBytes var successPayload = new(ApiResponse) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 5f4694cd9db..cf96d4a80ce 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -49,7 +49,6 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -80,10 +79,8 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -105,7 +102,6 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} // authentication (api_key) required @@ -140,10 +136,8 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { var successPayload = new(map[string]int32) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -173,7 +167,6 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -204,10 +197,8 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { var successPayload = new(Order) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -236,7 +227,6 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -270,10 +260,8 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { postBody = &body var successPayload = new(Order) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 2d5dc5fb8d5..c3f28579f6a 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -48,7 +48,6 @@ func (a UserApi) CreateUser (body User) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -82,10 +81,8 @@ func (a UserApi) CreateUser (body User) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -112,7 +109,6 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -146,10 +142,8 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -176,7 +170,6 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -210,10 +203,8 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -241,7 +232,6 @@ func (a UserApi) DeleteUser (username string) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -272,10 +262,8 @@ func (a UserApi) DeleteUser (username string) (error) { - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -303,7 +291,6 @@ func (a UserApi) GetUserByName (username string) (User, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -334,10 +321,8 @@ func (a UserApi) GetUserByName (username string) (User, error) { var successPayload = new(User) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -371,7 +356,6 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -404,10 +388,8 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { var successPayload = new(string) - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -431,7 +413,6 @@ func (a UserApi) LogoutUser () (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -462,10 +443,8 @@ func (a UserApi) LogoutUser () (error) { - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -498,7 +477,6 @@ func (a UserApi) UpdateUser (username string, body User) (error) { headerParams := make(map[string]string) queryParams := make(map[string]string) formParams := make(map[string]string) - fileParams := make(map[string]string) var postBody interface{} @@ -532,10 +510,8 @@ func (a UserApi) UpdateUser (username string, body User) (error) { postBody = &body - - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams) - - if err != nil && httpResponse.StatusCode() != 200{ +_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } From 611b711a7ebc8575090e111ef3b902601d7df8a4 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 19 Apr 2016 12:52:51 -0700 Subject: [PATCH 10/24] clean up generated code, added delete pet test --- .../client/petstore/go/go-petstore/pet_api.go | 16 +++++++++++---- .../petstore/go/go-petstore/store_api.go | 6 +++++- .../petstore/go/go-petstore/user_api.go | 20 +++++++++++++------ samples/client/petstore/go/pet_api_test.go | 10 ++++++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 9ea228d6624..bb8a28c8526 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -91,7 +91,8 @@ func (a PetApi) AddPet (body Pet) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -159,7 +160,8 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -225,6 +227,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { var successPayload = new([]Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -292,6 +295,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { var successPayload = new([]Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -358,6 +362,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { var successPayload = new(Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -428,7 +433,8 @@ func (a PetApi) UpdatePet (body Pet) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -498,7 +504,8 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err formParams["Status"] = status -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -569,6 +576,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil var successPayload = new(ApiResponse) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index cf96d4a80ce..5d65a70781b 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -79,7 +79,8 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -137,6 +138,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { var successPayload = new(map[string]int32) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -198,6 +200,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { var successPayload = new(Order) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -261,6 +264,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { var successPayload = new(Order) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index c3f28579f6a..9af3197d755 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -81,7 +81,8 @@ func (a UserApi) CreateUser (body User) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -142,7 +143,8 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -203,7 +205,8 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -262,7 +265,8 @@ func (a UserApi) DeleteUser (username string) (error) { -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -322,6 +326,7 @@ func (a UserApi) GetUserByName (username string) (User, error) { var successPayload = new(User) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -389,6 +394,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { var successPayload = new(string) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return *successPayload, err } @@ -443,7 +449,8 @@ func (a UserApi) LogoutUser () (error) { -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } @@ -510,7 +517,8 @@ func (a UserApi) UpdateUser (username string, body User) (error) { postBody = &body -_, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { return err } diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 8ac7dc1a77a..8b86bf880be 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -45,3 +45,13 @@ func TestUpdatePetWithForm(t *testing.T) { t.Log(err) } } + +func TestDeletePet(t *testing.T) { + s := sw.NewPetApi() + err := s.DeletePet(12830, "") + + if err != nil { + t.Errorf("Error while deleting pet by id") + t.Log(err) + } +} From 9cf6eb4d8be50e3eb3fc965831a1654bd76f898d Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 19 Apr 2016 15:18:13 -0700 Subject: [PATCH 11/24] added ApiResponse to all api calls --- .../src/main/resources/go/api.mustache | 176 ++-- .../src/main/resources/go/api_client.mustache | 23 + .../petstore/go/go-petstore/api_client.go | 23 + .../client/petstore/go/go-petstore/pet_api.go | 803 +++++++++--------- .../petstore/go/go-petstore/store_api.go | 332 ++++---- .../petstore/go/go-petstore/user_api.go | 745 ++++++++-------- samples/client/petstore/go/pet_api_test.go | 41 +- samples/client/petstore/go/test.go | 4 +- 8 files changed, 1105 insertions(+), 1042 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index cf548d7950c..48b504134fc 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -6,7 +6,6 @@ import ( "fmt" "encoding/json" "errors" - "bytes" {{#imports}} "{{import}}" {{/imports}} ) @@ -38,117 +37,112 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) { +func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error, ApiResponse) { - var httpMethod = "{{httpMethod}}" - // create path and map variables - path := a.Configuration.BasePath + "{{path}}" + var httpMethod = "{{httpMethod}}" + // create path and map variables + path := a.Configuration.BasePath + "{{path}}" {{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) {{/pathParams}} - {{#allParams}} - {{#required}} - // verify the required parameter '{{paramName}}' is set - if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") - } - {{/required}} - {{/allParams}} + {{#allParams}} + {{#required}} + // verify the required parameter '{{paramName}}' is set + if &{{paramName}} == nil { + return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } + {{/required}} + {{/allParams}} - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - {{#authMethods}}// authentication ({{name}}) required - {{#isApiKey}}{{#isKeyInHeader}} - // set key with prefix in header - headerParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") - {{/isKeyInHeader}}{{#isKeyInQuery}} - // set key with prefix in querystring - {{#hasKeyParamName}} - queryParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") - {{/hasKeyParamName}} - {{/isKeyInQuery}}{{/isApiKey}} - {{#isBasic}} - // http basic authentication required - if a.Configuration.Username != "" || a.Configuration.Password != ""{ - headerParams["Authorization"] = "Basic " + a.Configuration.GetBasicAuthEncodedString() - } - {{/isBasic}} - {{#isOAuth}} - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } - {{/isOAuth}} - {{/authMethods}} + {{#authMethods}}// authentication ({{name}}) required + {{#isApiKey}}{{#isKeyInHeader}} + // set key with prefix in header + headerParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") + {{/isKeyInHeader}}{{#isKeyInQuery}} + // set key with prefix in querystring + {{#hasKeyParamName}} + queryParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") + {{/hasKeyParamName}} + {{/isKeyInQuery}}{{/isApiKey}} + {{#isBasic}} + // http basic authentication required + if a.Configuration.Username != "" || a.Configuration.Password != ""{ + headerParams["Authorization"] = "Basic " + a.Configuration.GetBasicAuthEncodedString() + } + {{/isBasic}} + {{#isOAuth}} + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } + {{/isOAuth}} + {{/authMethods}} - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - {{#hasQueryParams}} - {{#queryParams}} - queryParams["{{vendorExtensions.x-exportParamName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) - {{/queryParams}} - {{/hasQueryParams}} + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + {{#hasQueryParams}} + {{#queryParams}} + queryParams["{{vendorExtensions.x-exportParamName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) + {{/queryParams}} + {{/hasQueryParams}} - // to determine the Content-Type header - localVarHttpContentTypes := []string { - {{#consumes}} - "{{mediaType}}", - {{/consumes}} - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - {{#produces}} - "{{mediaType}}", - {{/produces}} - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + {{#consumes}} + "{{mediaType}}", + {{/consumes}} + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + {{#produces}} + "{{mediaType}}", + {{/produces}} + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } {{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}" headerParams["{{baseName}}"] = {{paramName}} {{/headerParams}}{{/hasHeaderParams}} -{{#hasFormParams}} +{{#hasFormParams}} {{#formParams}} - {{#isFile}}fileBytes, _ := ioutil.ReadAll(file) - postBody = fileBytes - {{/isFile}} - {{^isFile}} - formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} - {{/isFile}} + {{#isFile}} fileBytes, _ := ioutil.ReadAll(file) + postBody = fileBytes + {{/isFile}} + {{^isFile}} formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} + {{/isFile}} {{/formParams}} -{{/hasFormParams}}{{#hasBodyParam}}{{#bodyParams}} - // body params - postBody = &{{paramName}} +{{/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) + if err != nil { - return {{#returnType}}*successPayload, {{/returnType}}err + return {{#returnType}}*successPayload, {{/returnType}}err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - {{#returnType}} - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + + err = json.Unmarshal(httpResponse.Body(), &successPayload) {{/returnType}} - return {{#returnType}}*successPayload, {{/returnType}}err + return {{#returnType}}*successPayload, {{/returnType}}err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } {{/operation}} {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 60281c98249..f06dc87d20d 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -100,5 +100,28 @@ func prepareRequest(postBody interface{}, request.SetQueryParams(queryParams) } + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + return request +} + +func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ + httpResponse := httpResp.(*resty.Response) + apiResponse := new(ApiResponse) + apiResponse.Code = int32(httpResponse.StatusCode()) + apiResponse.Message = httpResponse.Status() + + return apiResponse +} + +func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ + + apiResponse := new(ApiResponse) + apiResponse.Code = int32(400) + apiResponse.Message = errorMessage + + return apiResponse } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 9c8eb12b2be..245e046556f 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -100,5 +100,28 @@ func prepareRequest(postBody interface{}, request.SetQueryParams(queryParams) } + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + return request +} + +func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ + httpResponse := httpResp.(*resty.Response) + apiResponse := new(ApiResponse) + apiResponse.Code = int32(httpResponse.StatusCode()) + apiResponse.Message = httpResponse.Status() + + return apiResponse +} + +func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ + + apiResponse := new(ApiResponse) + apiResponse.Code = int32(400) + apiResponse.Message = errorMessage + + return apiResponse } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index bb8a28c8526..683c2061591 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "bytes" "os" "io/ioutil" ) @@ -36,69 +35,68 @@ func NewPetApiWithBasePath(basePath string) *PetApi{ * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) AddPet (body Pet) (error) { +func (a PetApi) AddPet (body Pet) (error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/pet" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/pet" - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling PetApi->AddPet") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "application/json", - "application/xml", - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling PetApi->AddPet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + "application/json", + "application/xml", + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Deletes a pet @@ -107,67 +105,67 @@ func (a PetApi) AddPet (body Pet) (error) { * @param apiKey * @return void */ -func (a PetApi) DeletePet (petId int64, apiKey string) (error) { +func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { - var httpMethod = "Delete" - // create path and map variables - path := a.Configuration.BasePath + "/pet/{petId}" + var httpMethod = "Delete" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // verify the required parameter 'petId' is set - if &petId == nil { - return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") - } + // verify the required parameter 'petId' is set + if &petId == nil { + return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } // header params "api_key" headerParams["api_key"] = apiKey - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return err + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - - return err + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Finds Pets by status @@ -175,67 +173,67 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { * @param status Status values that need to be considered for filter * @return []Pet */ -func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { +func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/pet/findByStatus" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/findByStatus" - // verify the required parameter 'status' is set - if &status == nil { - return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") - } + // verify the required parameter 'status' is set + if &status == nil { + return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - queryParams["Status"] = a.Configuration.ApiClient.ParameterToString(status) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + queryParams["Status"] = a.Configuration.ApiClient.ParameterToString(status) - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new([]Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Finds Pets by tags @@ -243,67 +241,67 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { * @param tags Tags to filter by * @return []Pet */ -func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { +func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/pet/findByTags" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/findByTags" - // verify the required parameter 'tags' is set - if &tags == nil { - return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") - } + // verify the required parameter 'tags' is set + if &tags == nil { + return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - queryParams["Tags"] = a.Configuration.ApiClient.ParameterToString(tags) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + queryParams["Tags"] = a.Configuration.ApiClient.ParameterToString(tags) - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new([]Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Find pet by ID @@ -311,66 +309,66 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { * @param petId ID of pet to return * @return Pet */ -func (a PetApi) GetPetById (petId int64) (Pet, error) { +func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/pet/{petId}" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // verify the required parameter 'petId' is set - if &petId == nil { - return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") - } + // verify the required parameter 'petId' is set + if &petId == nil { + return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (api_key) required - - // set key with prefix in header - headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - + // authentication (api_key) required + + // set key with prefix in header + headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") + - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new(Pet) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Update an existing pet @@ -378,69 +376,68 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) UpdatePet (body Pet) (error) { +func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { - var httpMethod = "Put" - // create path and map variables - path := a.Configuration.BasePath + "/pet" + var httpMethod = "Put" + // create path and map variables + path := a.Configuration.BasePath + "/pet" - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "application/json", - "application/xml", - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + "application/json", + "application/xml", + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Updates a pet in the store with form data @@ -450,68 +447,68 @@ func (a PetApi) UpdatePet (body Pet) (error) { * @param status Updated status of the pet * @return void */ -func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error) { +func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/pet/{petId}" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // verify the required parameter 'petId' is set - if &petId == nil { - return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "application/x-www-form-urlencoded", - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - formParams["Name"] = name - formParams["Status"] = status - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'petId' is set + if &petId == nil { + return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + "application/x-www-form-urlencoded", + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + formParams["Name"] = name + formParams["Status"] = status + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * uploads an image @@ -521,68 +518,68 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err * @param file file to upload * @return ApiResponse */ -func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error) { +func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/pet/{petId}/uploadImage" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}/uploadImage" path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // verify the required parameter 'petId' is set - if &petId == nil { - return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") - } + // verify the required parameter 'petId' is set + if &petId == nil { + return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken - } + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "multipart/form-data", - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - formParams["AdditionalMetadata"] = additionalMetadata - fileBytes, _ := ioutil.ReadAll(file) - postBody = fileBytes + // to determine the Content-Type header + localVarHttpContentTypes := []string { + "multipart/form-data", + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + formParams["AdditionalMetadata"] = additionalMetadata + fileBytes, _ := ioutil.ReadAll(file) + postBody = fileBytes + var successPayload = new(ApiResponse) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 5d65a70781b..b16720b5efd 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "bytes" ) type StoreApi struct { @@ -34,119 +33,119 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{ * @param orderId ID of the order that needs to be deleted * @return void */ -func (a StoreApi) DeleteOrder (orderId string) (error) { +func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { - var httpMethod = "Delete" - // create path and map variables - path := a.Configuration.BasePath + "/store/order/{orderId}" + var httpMethod = "Delete" + // create path and map variables + path := a.Configuration.BasePath + "/store/order/{orderId}" path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) - // verify the required parameter 'orderId' is set - if &orderId == nil { - return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") - } + // verify the required parameter 'orderId' is set + if &orderId == nil { + return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept } - return err + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Returns pet inventories by status * Returns a map of status codes to quantities * @return map[string]int32 */ -func (a StoreApi) GetInventory () (map[string]int32, error) { +func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/store/inventory" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/store/inventory" - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - // authentication (api_key) required - - // set key with prefix in header - headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") - + // authentication (api_key) required + + // set key with prefix in header + headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") + - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new(map[string]int32) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Find purchase order by ID @@ -154,61 +153,61 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { * @param orderId ID of pet that needs to be fetched * @return Order */ -func (a StoreApi) GetOrderById (orderId int64) (Order, error) { +func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/store/order/{orderId}" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/store/order/{orderId}" path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) - // verify the required parameter 'orderId' is set - if &orderId == nil { - return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") - } + // verify the required parameter 'orderId' is set + if &orderId == nil { + return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new(Order) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Place an order for a pet @@ -216,61 +215,60 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { * @param body order placed for purchasing the pet * @return Order */ -func (a StoreApi) PlaceOrder (body Order) (Order, error) { +func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/store/order" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/store/order" - // verify the required parameter 'body' is set - if &body == nil { - return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") - } + // verify the required parameter 'body' is set + if &body == nil { + return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } - - // body params - postBody = &body + // body params + postBody = &body var successPayload = new(Order) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 9af3197d755..f4aceb58ac8 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -5,7 +5,6 @@ import ( "fmt" "encoding/json" "errors" - "bytes" ) type UserApi struct { @@ -34,61 +33,60 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ * @param body Created user object * @return void */ -func (a UserApi) CreateUser (body User) (error) { +func (a UserApi) CreateUser (body User) (error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/user" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/user" - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Creates list of users with given input array @@ -96,61 +94,60 @@ func (a UserApi) CreateUser (body User) (error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { +func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/user/createWithArray" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/user/createWithArray" - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Creates list of users with given input array @@ -158,61 +155,60 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithListInput (body []User) (error) { +func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { - var httpMethod = "Post" - // create path and map variables - path := a.Configuration.BasePath + "/user/createWithList" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/user/createWithList" - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Delete user @@ -220,59 +216,59 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { * @param username The name that needs to be deleted * @return void */ -func (a UserApi) DeleteUser (username string) (error) { +func (a UserApi) DeleteUser (username string) (error, ApiResponse) { - var httpMethod = "Delete" - // create path and map variables - path := a.Configuration.BasePath + "/user/{username}" + var httpMethod = "Delete" + // create path and map variables + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - // verify the required parameter 'username' is set - if &username == nil { - return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") - } + // verify the required parameter 'username' is set + if &username == nil { + return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept } - return err + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Get user by user name @@ -280,61 +276,61 @@ func (a UserApi) DeleteUser (username string) (error) { * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ -func (a UserApi) GetUserByName (username string) (User, error) { +func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/user/{username}" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - // verify the required parameter 'username' is set - if &username == nil { - return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") - } + // verify the required parameter 'username' is set + if &username == nil { + return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new(User) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Logs user into the system @@ -343,120 +339,120 @@ func (a UserApi) GetUserByName (username string) (User, error) { * @param password The password for login in clear text * @return string */ -func (a UserApi) LoginUser (username string, password string) (string, error) { +func (a UserApi) LoginUser (username string, password string) (string, error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/user/login" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/user/login" - // verify the required parameter 'username' is set - if &username == nil { - return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") - } - // verify the required parameter 'password' is set - if &password == nil { - return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") - } + // verify the required parameter 'username' is set + if &username == nil { + return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } + // verify the required parameter 'password' is set + if &password == nil { + return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - queryParams["Username"] = a.Configuration.ApiClient.ParameterToString(username) - queryParams["Password"] = a.Configuration.ApiClient.ParameterToString(password) + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + queryParams["Username"] = a.Configuration.ApiClient.ParameterToString(username) + queryParams["Password"] = a.Configuration.ApiClient.ParameterToString(password) - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } var successPayload = new(string) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + if err != nil { - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } - decoder := json.NewDecoder(bytes.NewReader(httpResponse.Body())) - err = decoder.Decode(&successPayload) + err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err + return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Logs out current logged in user session * * @return void */ -func (a UserApi) LogoutUser () (error) { +func (a UserApi) LogoutUser () (error, ApiResponse) { - var httpMethod = "Get" - // create path and map variables - path := a.Configuration.BasePath + "/user/logout" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/user/logout" - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept } - return err + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } /** * Updated user @@ -465,64 +461,63 @@ func (a UserApi) LogoutUser () (error) { * @param body Updated user object * @return void */ -func (a UserApi) UpdateUser (username string, body User) (error) { +func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { - var httpMethod = "Put" - // create path and map variables - path := a.Configuration.BasePath + "/user/{username}" + var httpMethod = "Put" + // create path and map variables + path := a.Configuration.BasePath + "/user/{username}" path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - // verify the required parameter 'username' is set - if &username == nil { - return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") - } - // verify the required parameter 'body' is set - if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") - } - - headerParams := make(map[string]string) - queryParams := make(map[string]string) - formParams := make(map[string]string) - var postBody interface{} - - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - headerParams[key] = a.Configuration.DefaultHeader[key] - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - headerParams["Content-Type"] = localVarHttpContentType - } - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - headerParams["Accept"] = localVarHttpHeaderAccept - } - - - // body params - postBody = &body - - - _, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) - - if err != nil { - return err + // verify the required parameter 'username' is set + if &username == nil { + return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + } + // verify the required parameter 'body' is set + if &body == nil { + return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") } + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} - return err + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + + // to determine the Content-Type header + localVarHttpContentTypes := []string { + } + //set Content-Type header + localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + headerParams["Content-Type"] = localVarHttpContentType + } + // to determine the Accept header + localVarHttpHeaderAccepts := []string { + "application/xml", + "application/json", + } + //set Accept header + localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + headerParams["Accept"] = localVarHttpHeaderAccept + } + + // body params + postBody = &body + + + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + + + if err != nil { + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + } + + return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) } diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 8b86bf880be..9978092725b 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -11,11 +11,12 @@ func TestAddPet(t *testing.T) { newPet := (sw.Pet{Id: 12830, Name: "gopher", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}) - err := s.AddPet(newPet) + err, apiResponse := s.AddPet(newPet) if err != nil { t.Errorf("Error while adding pet") t.Log(err) + t.Log(apiResponse) } } @@ -23,10 +24,11 @@ func TestGetPetById(t *testing.T) { assert := assert.New(t) s := sw.NewPetApi() - resp, err := s.GetPetById(12830) + resp, err, apiResponse := s.GetPetById(12830) if err != nil { t.Errorf("Error while getting pet by id") t.Log(err) + t.Log(apiResponse) } else { assert.Equal(resp.Id, int64(12830), "Pet id should be equal") assert.Equal(resp.Name, "gopher", "Pet name should be gopher") @@ -36,22 +38,53 @@ func TestGetPetById(t *testing.T) { } } +func TestGetPetByIdWithInvalidID(t *testing.T) { + s := sw.NewPetApi() + resp, err, apiResponse := s.GetPetById(999999999) + if err != nil { + t.Errorf("Error while getting pet by invalid id") + t.Log(err) + t.Log(apiResponse) + } else { + + t.Log(resp) + } +} + func TestUpdatePetWithForm(t *testing.T) { s := sw.NewPetApi() - err := s.UpdatePetWithForm(12830, "golang", "available") + err, apiResponse := s.UpdatePetWithForm(12830, "golang", "available") if err != nil { t.Errorf("Error while updating pet by id") t.Log(err) + t.Log(apiResponse) + } +} + +func TestFindPetsByStatus(t *testing.T) { + s := sw.NewPetApi() + resp, err, apiResponse := s.FindPetsByStatus([]string {"pending"}) + if err != nil { + t.Errorf("Error while getting pet by id") + t.Log(err) + t.Log(apiResponse) + } else { + t.Log(apiResponse) + if len(resp) == 0 { + t.Errorf("Error no pets returned") + } + t.Log(resp) } } func TestDeletePet(t *testing.T) { s := sw.NewPetApi() - err := s.DeletePet(12830, "") + err, apiResponse := s.DeletePet(12830, "") if err != nil { t.Errorf("Error while deleting pet by id") t.Log(err) + t.Log(apiResponse) } } diff --git a/samples/client/petstore/go/test.go b/samples/client/petstore/go/test.go index f73d4e338ca..2dcd385212e 100644 --- a/samples/client/petstore/go/test.go +++ b/samples/client/petstore/go/test.go @@ -22,7 +22,7 @@ func main() { s.UpdatePetWithForm(12830, "golang", "available") // test GET - resp, err := s.GetPetById(12830) - fmt.Println("GetPetById: ", resp, err) + resp, err, apiResponse := s.GetPetById(12830) + fmt.Println("GetPetById: ", resp, err, apiResponse) } From 0e3bb2c23e4bc14e1078223fe055a0972716b453 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 19 Apr 2016 15:48:34 -0700 Subject: [PATCH 12/24] added more tests functions, clean up generated code --- .../src/main/resources/go/api.mustache | 4 +- .../client/petstore/go/go-petstore/pet_api.go | 10 ++--- samples/client/petstore/go/pet_api_test.go | 37 +++++++++++++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 48b504134fc..b56ccee2aab 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -121,10 +121,10 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/headerParams}}{{/hasHeaderParams}} {{#hasFormParams}} {{#formParams}} - {{#isFile}} fileBytes, _ := ioutil.ReadAll(file) + {{#isFile}}fileBytes, _ := ioutil.ReadAll(file) postBody = fileBytes {{/isFile}} - {{^isFile}} formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} +{{^isFile}}formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} {{/isFile}} {{/formParams}} {{/hasFormParams}}{{#hasBodyParam}}{{#bodyParams}} // body params diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 683c2061591..ce7fcf1cf2f 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -497,8 +497,8 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["Name"] = name - formParams["Status"] = status + formParams["Name"] = name + formParams["Status"] = status httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) @@ -567,10 +567,10 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["AdditionalMetadata"] = additionalMetadata - fileBytes, _ := ioutil.ReadAll(file) + formParams["AdditionalMetadata"] = additionalMetadata + fileBytes, _ := ioutil.ReadAll(file) postBody = fileBytes - + var successPayload = new(ApiResponse) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 9978092725b..2b831f58588 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -4,6 +4,7 @@ import ( sw "./go-petstore" "github.com/stretchr/testify/assert" "testing" + "os" ) func TestAddPet(t *testing.T) { @@ -16,8 +17,10 @@ func TestAddPet(t *testing.T) { if err != nil { t.Errorf("Error while adding pet") t.Log(err) - t.Log(apiResponse) } + if apiResponse.Code != 200 { + t.Log(apiResponse) + } } func TestGetPetById(t *testing.T) { @@ -28,7 +31,6 @@ func TestGetPetById(t *testing.T) { if err != nil { t.Errorf("Error while getting pet by id") t.Log(err) - t.Log(apiResponse) } else { assert.Equal(resp.Id, int64(12830), "Pet id should be equal") assert.Equal(resp.Name, "gopher", "Pet name should be gopher") @@ -36,6 +38,9 @@ func TestGetPetById(t *testing.T) { //t.Log(resp) } + if apiResponse.Code != 200 { + t.Log(apiResponse) + } } func TestGetPetByIdWithInvalidID(t *testing.T) { @@ -49,6 +54,9 @@ func TestGetPetByIdWithInvalidID(t *testing.T) { t.Log(resp) } + if apiResponse.Code != 200 { + t.Log(apiResponse) + } } func TestUpdatePetWithForm(t *testing.T) { @@ -60,6 +68,9 @@ func TestUpdatePetWithForm(t *testing.T) { t.Log(err) t.Log(apiResponse) } + if apiResponse.Code != 200 { + t.Log(apiResponse) + } } func TestFindPetsByStatus(t *testing.T) { @@ -74,7 +85,25 @@ func TestFindPetsByStatus(t *testing.T) { if len(resp) == 0 { t.Errorf("Error no pets returned") } - t.Log(resp) + + if apiResponse.Code != 200 { + t.Log(apiResponse) + } + } +} + +func TestUploadFile(t *testing.T) { + s := sw.NewPetApi() + file, _ := os.Open("../python/testfiles/foo.png") + + _, err, apiResponse := s.UploadFile(12830, "golang", file) + + if err != nil { + t.Errorf("Error while uploading file") + t.Log(err) + } + if apiResponse.Code != 200 { + t.Log(apiResponse) } } @@ -85,6 +114,8 @@ func TestDeletePet(t *testing.T) { if err != nil { t.Errorf("Error while deleting pet by id") t.Log(err) + } + if apiResponse.Code != 200 { t.Log(apiResponse) } } From edfc4f88e184b50a07232414e235b168cedd82f9 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 19 Apr 2016 21:02:22 -0700 Subject: [PATCH 13/24] formatted api_client code, grouped public function --- .../src/main/resources/go/api_client.mustache | 38 +++++++++---------- .../petstore/go/go-petstore/api_client.go | 38 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index f06dc87d20d..2b8f6f57aed 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -73,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func (c *ApiClient) ParameterToString (obj interface{}) string { +func (c *ApiClient) ParameterToString(obj interface{}) string { if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else { @@ -81,6 +81,24 @@ func (c *ApiClient) ParameterToString (obj interface{}) string { } } +func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ + httpResponse := httpResp.(*resty.Response) + apiResponse := new(ApiResponse) + apiResponse.Code = int32(httpResponse.StatusCode()) + apiResponse.Message = httpResponse.Status() + + return apiResponse +} + +func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ + + apiResponse := new(ApiResponse) + apiResponse.Code = int32(400) + apiResponse.Message = errorMessage + + return apiResponse +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, @@ -107,21 +125,3 @@ func prepareRequest(postBody interface{}, return request } - -func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ - httpResponse := httpResp.(*resty.Response) - apiResponse := new(ApiResponse) - apiResponse.Code = int32(httpResponse.StatusCode()) - apiResponse.Message = httpResponse.Status() - - return apiResponse -} - -func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ - - apiResponse := new(ApiResponse) - apiResponse.Code = int32(400) - apiResponse.Message = errorMessage - - return apiResponse -} \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 245e046556f..d5cec88a330 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -73,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string, return nil, errors.New("Invalid method " + method) } -func (c *ApiClient) ParameterToString (obj interface{}) string { +func (c *ApiClient) ParameterToString(obj interface{}) string { if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else { @@ -81,6 +81,24 @@ func (c *ApiClient) ParameterToString (obj interface{}) string { } } +func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ + httpResponse := httpResp.(*resty.Response) + apiResponse := new(ApiResponse) + apiResponse.Code = int32(httpResponse.StatusCode()) + apiResponse.Message = httpResponse.Status() + + return apiResponse +} + +func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ + + apiResponse := new(ApiResponse) + apiResponse.Code = int32(400) + apiResponse.Message = errorMessage + + return apiResponse +} + func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, @@ -107,21 +125,3 @@ func prepareRequest(postBody interface{}, return request } - -func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ - httpResponse := httpResp.(*resty.Response) - apiResponse := new(ApiResponse) - apiResponse.Code = int32(httpResponse.StatusCode()) - apiResponse.Message = httpResponse.Status() - - return apiResponse -} - -func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ - - apiResponse := new(ApiResponse) - apiResponse.Code = int32(400) - apiResponse.Message = errorMessage - - return apiResponse -} \ No newline at end of file From 287f3ff20b3c26348cbf027a1d5406128146b346 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Wed, 20 Apr 2016 12:27:22 -0700 Subject: [PATCH 14/24] fixed io/ioutil import issue, fixed param casing issue --- .../src/main/resources/go/api.mustache | 13 +++++++++++-- samples/client/petstore/go/go-petstore/pet_api.go | 12 ++++++------ samples/client/petstore/go/go-petstore/user_api.go | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index b56ccee2aab..558e54a0653 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -6,6 +6,15 @@ import ( "fmt" "encoding/json" "errors" + {{#operation}} + {{#hasFormParams}} + {{#formParams}} + {{#isFile}} + "io/ioutil" + {{/isFile}} + {{/formParams}} + {{/hasFormParams}} + {{/operation}} {{#imports}} "{{import}}" {{/imports}} ) @@ -90,7 +99,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasQueryParams}} {{#queryParams}} - queryParams["{{vendorExtensions.x-exportParamName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) + queryParams["{{paramName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) {{/queryParams}} {{/hasQueryParams}} @@ -124,7 +133,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#isFile}}fileBytes, _ := ioutil.ReadAll(file) postBody = fileBytes {{/isFile}} -{{^isFile}}formParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}} +{{^isFile}}formParams["{{paramName}}"] = {{paramName}} {{/isFile}} {{/formParams}} {{/hasFormParams}}{{#hasBodyParam}}{{#bodyParams}} // body params diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index ce7fcf1cf2f..65d9416ecd3 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -5,8 +5,8 @@ import ( "fmt" "encoding/json" "errors" - "os" "io/ioutil" + "os" ) type PetApi struct { @@ -201,7 +201,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Status"] = a.Configuration.ApiClient.ParameterToString(status) + queryParams["status"] = a.Configuration.ApiClient.ParameterToString(status) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -269,7 +269,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Tags"] = a.Configuration.ApiClient.ParameterToString(tags) + queryParams["tags"] = a.Configuration.ApiClient.ParameterToString(tags) // to determine the Content-Type header localVarHttpContentTypes := []string { @@ -497,8 +497,8 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["Name"] = name - formParams["Status"] = status + formParams["name"] = name + formParams["status"] = status httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) @@ -567,7 +567,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil headerParams["Accept"] = localVarHttpHeaderAccept } - formParams["AdditionalMetadata"] = additionalMetadata + formParams["additionalMetadata"] = additionalMetadata fileBytes, _ := ioutil.ReadAll(file) postBody = fileBytes diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index f4aceb58ac8..877dad2cb0f 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -365,8 +365,8 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["Username"] = a.Configuration.ApiClient.ParameterToString(username) - queryParams["Password"] = a.Configuration.ApiClient.ParameterToString(password) + queryParams["username"] = a.Configuration.ApiClient.ParameterToString(username) + queryParams["password"] = a.Configuration.ApiClient.ParameterToString(password) // to determine the Content-Type header localVarHttpContentTypes := []string { From 10c7c41e82e90a868720d5375b7e20da1f34a6ef Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Wed, 20 Apr 2016 12:54:05 -0700 Subject: [PATCH 15/24] added config to allow client to see debug log --- .../swagger-codegen/src/main/resources/go/api_client.mustache | 4 ++++ samples/client/petstore/go/go-petstore/api_client.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 2b8f6f57aed..c6fb8867158 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -50,6 +50,10 @@ func (c *ApiClient) CallApi(path string, method string, queryParams map[string]string, formParams map[string]string) (*resty.Response, error) { + //set debug flag + configuration := NewConfiguration() + resty.SetDebug(configuration.Debug) + request := prepareRequest(postBody, headerParams, queryParams, formParams) switch strings.ToUpper(method) { diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index d5cec88a330..97a6c9a8f02 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -50,6 +50,10 @@ func (c *ApiClient) CallApi(path string, method string, queryParams map[string]string, formParams map[string]string) (*resty.Response, error) { + //set debug flag + configuration := NewConfiguration() + resty.SetDebug(configuration.Debug) + request := prepareRequest(postBody, headerParams, queryParams, formParams) switch strings.ToUpper(method) { From 7636a772c61ac307c0ff47e8dfc0d4b2cd2f78d8 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Wed, 20 Apr 2016 13:49:02 -0700 Subject: [PATCH 16/24] fixed file upload issue --- .../src/main/resources/go/api.mustache | 7 +++-- .../src/main/resources/go/api_client.mustache | 14 +++++++--- .../petstore/go/go-petstore/api_client.go | 14 +++++++--- .../client/petstore/go/go-petstore/pet_api.go | 28 ++++++++++++------- .../petstore/go/go-petstore/store_api.go | 12 +++++--- .../petstore/go/go-petstore/user_api.go | 24 ++++++++++------ 6 files changed, 66 insertions(+), 33 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 558e54a0653..bd727a02910 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -67,6 +67,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte {{#authMethods}}// authentication ({{name}}) required {{#isApiKey}}{{#isKeyInHeader}} @@ -130,8 +131,8 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/headerParams}}{{/hasHeaderParams}} {{#hasFormParams}} {{#formParams}} - {{#isFile}}fileBytes, _ := ioutil.ReadAll(file) - postBody = fileBytes + {{#isFile}}fbs, _ := ioutil.ReadAll(file) + fileBytes = fbs {{/isFile}} {{^isFile}}formParams["{{paramName}}"] = {{paramName}} {{/isFile}} @@ -140,7 +141,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ postBody = &{{paramName}} {{/bodyParams}}{{/hasBodyParam}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index c6fb8867158..04f082a466c 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -5,6 +5,7 @@ import ( "github.com/go-resty/resty" "errors" "reflect" + "bytes" ) type ApiClient struct { @@ -48,13 +49,14 @@ func (c *ApiClient) CallApi(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string) (*resty.Response, error) { + formParams map[string]string, + file []byte) (*resty.Response, error) { //set debug flag configuration := NewConfiguration() resty.SetDebug(configuration.Debug) - - request := prepareRequest(postBody, headerParams, queryParams, formParams) + + request := prepareRequest(postBody, headerParams, queryParams, formParams,file) switch strings.ToUpper(method) { case "GET": @@ -106,7 +108,8 @@ func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string) *resty.Request { + formParams map[string]string, + file []byte) *resty.Request { request := resty.R() @@ -127,5 +130,8 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) } + if len(file) > 0 { + request.SetFileReader("file", "test-img.png", bytes.NewReader(file)) + } return request } diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 97a6c9a8f02..3bec2e26bf8 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -5,6 +5,7 @@ import ( "github.com/go-resty/resty" "errors" "reflect" + "bytes" ) type ApiClient struct { @@ -48,13 +49,14 @@ func (c *ApiClient) CallApi(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string) (*resty.Response, error) { + formParams map[string]string, + file []byte) (*resty.Response, error) { //set debug flag configuration := NewConfiguration() resty.SetDebug(configuration.Debug) - - request := prepareRequest(postBody, headerParams, queryParams, formParams) + + request := prepareRequest(postBody, headerParams, queryParams, formParams,file) switch strings.ToUpper(method) { case "GET": @@ -106,7 +108,8 @@ func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string) *resty.Request { + formParams map[string]string, + file []byte) *resty.Request { request := resty.R() @@ -127,5 +130,8 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) } + if len(file) > 0 { + request.SetFileReader("file", "test-img.png", bytes.NewReader(file)) + } return request } diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 65d9416ecd3..f089d87c677 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -50,6 +50,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -89,7 +90,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -121,6 +122,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -158,7 +160,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -188,6 +190,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -224,7 +227,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -256,6 +259,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -292,7 +296,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -325,6 +329,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (api_key) required @@ -359,7 +364,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { var successPayload = new(Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -391,6 +396,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -430,7 +436,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -463,6 +469,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -501,7 +508,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err formParams["status"] = status - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -534,6 +541,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (petstore_auth) required @@ -568,11 +576,11 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil } formParams["additionalMetadata"] = additionalMetadata - fileBytes, _ := ioutil.ReadAll(file) - postBody = fileBytes + fbs, _ := ioutil.ReadAll(file) + fileBytes = fbs var successPayload = new(ApiResponse) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index b16720b5efd..59f9d2bd083 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -49,6 +49,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -78,7 +79,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -103,6 +104,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // authentication (api_key) required @@ -136,7 +138,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { var successPayload = new(map[string]int32) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -169,6 +171,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -198,7 +201,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -230,6 +233,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -261,7 +265,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { postBody = &body var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 877dad2cb0f..3a845817216 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -48,6 +48,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -79,7 +80,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -109,6 +110,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -140,7 +142,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -170,6 +172,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -201,7 +204,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -232,6 +235,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -261,7 +265,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -292,6 +296,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -321,7 +326,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { var successPayload = new(User) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -358,6 +363,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -389,7 +395,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap var successPayload = new(string) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -416,6 +422,7 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -445,7 +452,7 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { @@ -481,6 +488,7 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileBytes []byte // add default headers if any @@ -512,7 +520,7 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) if err != nil { From a2002d9148fcb2d226e6176a96a471146aca975b Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Wed, 20 Apr 2016 21:30:05 -0700 Subject: [PATCH 17/24] added fileName parameter for upload method --- .../src/main/resources/go/api.mustache | 8 +-- .../src/main/resources/go/api_client.mustache | 16 +++--- .../petstore/go/go-petstore/api_client.go | 16 +++--- .../client/petstore/go/go-petstore/pet_api.go | 49 +++++++++++-------- .../petstore/go/go-petstore/store_api.go | 24 +++++---- .../petstore/go/go-petstore/user_api.go | 46 ++++++++++------- 6 files changed, 95 insertions(+), 64 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index bd727a02910..5b6b9d30ab6 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -49,9 +49,9 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error, ApiResponse) { var httpMethod = "{{httpMethod}}" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "{{path}}" -{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) +{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1) {{/pathParams}} {{#allParams}} @@ -67,6 +67,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte {{#authMethods}}// authentication ({{name}}) required @@ -133,6 +134,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#formParams}} {{#isFile}}fbs, _ := ioutil.ReadAll(file) fileBytes = fbs + fileName = file.Name() {{/isFile}} {{^isFile}}formParams["{{paramName}}"] = {{paramName}} {{/isFile}} @@ -141,7 +143,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ postBody = &{{paramName}} {{/bodyParams}}{{/hasBodyParam}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 04f082a466c..ce6de7017e0 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -6,6 +6,7 @@ import ( "errors" "reflect" "bytes" + "path/filepath" ) type ApiClient struct { @@ -50,13 +51,14 @@ func (c *ApiClient) CallApi(path string, method string, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, - file []byte) (*resty.Response, error) { + fileName string, + fileBytes []byte) (*resty.Response, error) { //set debug flag configuration := NewConfiguration() resty.SetDebug(configuration.Debug) - request := prepareRequest(postBody, headerParams, queryParams, formParams,file) + request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) switch strings.ToUpper(method) { case "GET": @@ -108,8 +110,9 @@ func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string, - file []byte) *resty.Request { + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { request := resty.R() @@ -130,8 +133,9 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) } - if len(file) > 0 { - request.SetFileReader("file", "test-img.png", bytes.NewReader(file)) + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) } return request } diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 3bec2e26bf8..77ec4ef3994 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -6,6 +6,7 @@ import ( "errors" "reflect" "bytes" + "path/filepath" ) type ApiClient struct { @@ -50,13 +51,14 @@ func (c *ApiClient) CallApi(path string, method string, headerParams map[string]string, queryParams map[string]string, formParams map[string]string, - file []byte) (*resty.Response, error) { + fileName string, + fileBytes []byte) (*resty.Response, error) { //set debug flag configuration := NewConfiguration() resty.SetDebug(configuration.Debug) - request := prepareRequest(postBody, headerParams, queryParams, formParams,file) + request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) switch strings.ToUpper(method) { case "GET": @@ -108,8 +110,9 @@ func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, - formParams map[string]string, - file []byte) *resty.Request { + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { request := resty.R() @@ -130,8 +133,9 @@ func prepareRequest(postBody interface{}, request.SetFormData(formParams) } - if len(file) > 0 { - request.SetFileReader("file", "test-img.png", bytes.NewReader(file)) + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) } return request } diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index f089d87c677..22df273324c 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -38,7 +38,7 @@ func NewPetApiWithBasePath(basePath string) *PetApi{ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet" // verify the required parameter 'body' is set @@ -50,6 +50,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -90,7 +91,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -109,9 +110,9 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { var httpMethod = "Delete" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set if &petId == nil { @@ -122,6 +123,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -160,7 +162,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -178,7 +180,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/findByStatus" // verify the required parameter 'status' is set @@ -190,6 +192,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -227,7 +230,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -247,7 +250,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/findByTags" // verify the required parameter 'tags' is set @@ -259,6 +262,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -296,7 +300,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -316,9 +320,9 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set if &petId == nil { @@ -329,6 +333,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (api_key) required @@ -364,7 +369,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { var successPayload = new(Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -384,7 +389,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { var httpMethod = "Put" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet" // verify the required parameter 'body' is set @@ -396,6 +401,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -436,7 +442,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -456,9 +462,9 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/{petId}" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set if &petId == nil { @@ -469,6 +475,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -508,7 +515,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err formParams["status"] = status - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -528,9 +535,9 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/pet/{petId}/uploadImage" - path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) // verify the required parameter 'petId' is set if &petId == nil { @@ -541,6 +548,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (petstore_auth) required @@ -578,9 +586,10 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil formParams["additionalMetadata"] = additionalMetadata fbs, _ := ioutil.ReadAll(file) fileBytes = fbs + fileName = file.Name() var successPayload = new(ApiResponse) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 59f9d2bd083..c1904d3dc6b 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -36,9 +36,9 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { var httpMethod = "Delete" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) // verify the required parameter 'orderId' is set if &orderId == nil { @@ -49,6 +49,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -79,7 +80,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -96,7 +97,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/store/inventory" @@ -104,6 +105,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte // authentication (api_key) required @@ -138,7 +140,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { var successPayload = new(map[string]int32) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -158,9 +160,9 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) // verify the required parameter 'orderId' is set if &orderId == nil { @@ -171,6 +173,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -201,7 +204,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -221,7 +224,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/store/order" // verify the required parameter 'body' is set @@ -233,6 +236,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -265,7 +269,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { postBody = &body var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 3a845817216..4e3cf387bc0 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -36,7 +36,7 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ func (a UserApi) CreateUser (body User) (error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user" // verify the required parameter 'body' is set @@ -48,6 +48,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -80,7 +81,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -98,7 +99,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/createWithArray" // verify the required parameter 'body' is set @@ -110,6 +111,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -142,7 +144,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -160,7 +162,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { var httpMethod = "Post" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/createWithList" // verify the required parameter 'body' is set @@ -172,6 +174,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -204,7 +207,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -222,9 +225,9 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { func (a UserApi) DeleteUser (username string) (error, ApiResponse) { var httpMethod = "Delete" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set if &username == nil { @@ -235,6 +238,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -265,7 +269,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -283,9 +287,9 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set if &username == nil { @@ -296,6 +300,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -326,7 +331,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { var successPayload = new(User) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -347,7 +352,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { func (a UserApi) LoginUser (username string, password string) (string, error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/login" // verify the required parameter 'username' is set @@ -363,6 +368,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -395,7 +401,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap var successPayload = new(string) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -414,7 +420,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap func (a UserApi) LogoutUser () (error, ApiResponse) { var httpMethod = "Get" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/logout" @@ -422,6 +428,7 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -452,7 +459,7 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { @@ -471,9 +478,9 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { var httpMethod = "Put" - // create path and map variables + // create path and map variables path := a.Configuration.BasePath + "/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) // verify the required parameter 'username' is set if &username == nil { @@ -488,6 +495,7 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { queryParams := make(map[string]string) formParams := make(map[string]string) var postBody interface{} + var fileName string var fileBytes []byte @@ -520,7 +528,7 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileBytes) + httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { From e555b3ad34cc8e285c1c4713604e8255dd0eec2b Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Wed, 20 Apr 2016 22:36:32 -0700 Subject: [PATCH 18/24] added debug setter and getter in Go configuration --- .../src/main/resources/go/api_client.mustache | 2 +- .../src/main/resources/go/configuration.mustache | 12 ++++++++++-- samples/client/petstore/go/go-petstore/api_client.go | 4 ++-- .../client/petstore/go/go-petstore/configuration.go | 12 ++++++++++-- samples/client/petstore/go/test.go | 2 ++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index ce6de7017e0..9143f33b504 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -56,7 +56,7 @@ func (c *ApiClient) CallApi(path string, method string, //set debug flag configuration := NewConfiguration() - resty.SetDebug(configuration.Debug) + resty.SetDebug(configuration.GetDebug()) request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) diff --git a/modules/swagger-codegen/src/main/resources/go/configuration.mustache b/modules/swagger-codegen/src/main/resources/go/configuration.mustache index 154ceb9ffc6..e5f05a63c12 100644 --- a/modules/swagger-codegen/src/main/resources/go/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/go/configuration.mustache @@ -9,7 +9,7 @@ type Configuration struct { Password string `json:"password,omitempty"` ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` ApiKey map[string] string `json:"apiKey,omitempty"` - Debug bool `json:"debug,omitempty"` + debug bool `json:"debug,omitempty"` DebugFile string `json:"debugFile,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"` Timeout int `json:"timeout,omitempty"` @@ -26,7 +26,7 @@ func NewConfiguration() *Configuration { return &Configuration{ BasePath: "{{basePath}}", UserName: "", - Debug: false, + debug: false, DefaultHeader: make(map[string]string), ApiKey: make(map[string]string), ApiKeyPrefix: make(map[string]string), @@ -48,4 +48,12 @@ func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string { } return c.ApiKey[apiKeyIdentifier] +} + +func (c *Configuration) SetDebug(enable bool){ + c.debug = enable +} + +func (c *Configuration) GetDebug() bool { + return c.debug } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 77ec4ef3994..33451139a97 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -56,7 +56,7 @@ func (c *ApiClient) CallApi(path string, method string, //set debug flag configuration := NewConfiguration() - resty.SetDebug(configuration.Debug) + resty.SetDebug(configuration.GetDebug()) request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) @@ -134,7 +134,7 @@ func prepareRequest(postBody interface{}, } if len(fileBytes) > 0 && fileName != "" { - _, fileNm := filepath.Split(fileName) + _, fileNm := filepath.Split(fileName) request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) } return request diff --git a/samples/client/petstore/go/go-petstore/configuration.go b/samples/client/petstore/go/go-petstore/configuration.go index e8a00bccaf5..3fe94d36c26 100644 --- a/samples/client/petstore/go/go-petstore/configuration.go +++ b/samples/client/petstore/go/go-petstore/configuration.go @@ -9,7 +9,7 @@ type Configuration struct { Password string `json:"password,omitempty"` ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` ApiKey map[string] string `json:"apiKey,omitempty"` - Debug bool `json:"debug,omitempty"` + debug bool `json:"debug,omitempty"` DebugFile string `json:"debugFile,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"` Timeout int `json:"timeout,omitempty"` @@ -26,7 +26,7 @@ func NewConfiguration() *Configuration { return &Configuration{ BasePath: "http://petstore.swagger.io/v2", UserName: "", - Debug: false, + debug: false, DefaultHeader: make(map[string]string), ApiKey: make(map[string]string), ApiKeyPrefix: make(map[string]string), @@ -48,4 +48,12 @@ func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string { } return c.ApiKey[apiKeyIdentifier] +} + +func (c *Configuration) SetDebug(enable bool){ + c.debug = enable +} + +func (c *Configuration) GetDebug() bool { + return c.debug } \ No newline at end of file diff --git a/samples/client/petstore/go/test.go b/samples/client/petstore/go/test.go index 2dcd385212e..6a50c9bbc8e 100644 --- a/samples/client/petstore/go/test.go +++ b/samples/client/petstore/go/test.go @@ -25,4 +25,6 @@ func main() { resp, err, apiResponse := s.GetPetById(12830) fmt.Println("GetPetById: ", resp, err, apiResponse) + err2, apiResponse2 := s.DeletePet(12830, "") + fmt.Println("DeletePet: ", err2, apiResponse2) } From e7df5f95515c55fb72040a800c8e8d91f19b6b4c Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sat, 23 Apr 2016 09:52:17 -0700 Subject: [PATCH 19/24] fixed multiple import mapping issue --- .../codegen/languages/GoClientCodegen.java | 39 ++++++++++++++++++- .../src/main/resources/go/api.mustache | 9 ----- .../client/petstore/go/go-petstore/pet_api.go | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index b23ab32163e..37c485ea888 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -104,7 +104,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { importMapping = new HashMap(); importMapping.put("time.Time", "time"); importMapping.put("*os.File", "os"); - importMapping.put("ioutil", "io/ioutil"); + importMapping.put("os", "io/ioutil"); cliOptions.clear(); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).") @@ -375,6 +375,23 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { iterator.remove(); } + // recursivly add import for mapping one type to multipe imports + List> recursiveImports = (List>) objs.get("imports"); + if (recursiveImports == null) + return objs; + + ListIterator> listIterator = imports.listIterator(); + while (listIterator.hasNext()) { + String _import = listIterator.next().get("import"); + // if the import package happens to be found in the importMapping (key) + // add the corresponding import package to the list + if (importMapping.containsKey(_import)) { + Map newImportMap= new HashMap(); + newImportMap.put("import", importMapping.get(_import)); + listIterator.add(newImportMap); + } + } + return objs; } @@ -389,6 +406,24 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { if (_import.startsWith(prefix)) iterator.remove(); } + + // recursivly add import for mapping one type to multipe imports + List> recursiveImports = (List>) objs.get("imports"); + if (recursiveImports == null) + return objs; + + ListIterator> listIterator = imports.listIterator(); + while (listIterator.hasNext()) { + String _import = listIterator.next().get("import"); + // if the import package happens to be found in the importMapping (key) + // add the corresponding import package to the list + if (importMapping.containsKey(_import)) { + Map newImportMap= new HashMap(); + newImportMap.put("import", importMapping.get(_import)); + listIterator.add(newImportMap); + } + } + return objs; } @@ -405,4 +440,4 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { public void setPackageVersion(String packageVersion) { this.packageVersion = packageVersion; } -} +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 5b6b9d30ab6..d9302ae4126 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -6,15 +6,6 @@ import ( "fmt" "encoding/json" "errors" - {{#operation}} - {{#hasFormParams}} - {{#formParams}} - {{#isFile}} - "io/ioutil" - {{/isFile}} - {{/formParams}} - {{/hasFormParams}} - {{/operation}} {{#imports}} "{{import}}" {{/imports}} ) diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 22df273324c..49ca502151c 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -5,8 +5,8 @@ import ( "fmt" "encoding/json" "errors" - "io/ioutil" "os" + "io/ioutil" ) type PetApi struct { From 7df5c8ffbfeb6b2b0e7dd507b3e28978b1a4d704 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sat, 23 Apr 2016 16:41:14 -0700 Subject: [PATCH 20/24] added model ApiResponse, moved ApiResponse parameter --- .../codegen/languages/GoClientCodegen.java | 5 +- .../src/main/resources/go/api.mustache | 8 +-- .../client/petstore/go/go-petstore/README.md | 4 +- .../petstore/go/go-petstore/docs/PetApi.md | 4 +- .../client/petstore/go/go-petstore/pet_api.go | 68 +++++++++---------- .../petstore/go/go-petstore/store_api.go | 30 ++++---- .../petstore/go/go-petstore/user_api.go | 66 +++++++++--------- samples/client/petstore/go/pet_api_test.go | 14 ++-- 8 files changed, 100 insertions(+), 99 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index 37c485ea888..ef0ea2e5142 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -51,7 +51,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { "case", "defer", "go", "map", "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", - "continue", "for", "import", "return", "var", "error") + "continue", "for", "import", "return", "var", "error", "ApiResponse") // Added "error" as it's used so frequently that it may as well be a keyword ); @@ -145,6 +145,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go")); supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go")); + supportingFiles.add(new SupportingFile("api_response.mustache", "", "api_response.go")); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); } @@ -324,7 +325,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { return swaggerType; } - return camelize(swaggerType, false); + return toModelName(swaggerType); } @Override diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index d9302ae4126..5313732906a 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -37,7 +37,7 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error, ApiResponse) { +func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}ApiResponse, error) { var httpMethod = "{{httpMethod}}" // create path and map variables @@ -49,7 +49,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#required}} // verify the required parameter '{{paramName}}' is set if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return {{#returnType}}*new({{{returnType}}}), {{/returnType}}*a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") } {{/required}} {{/allParams}} @@ -138,14 +138,14 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ if err != nil { - return {{#returnType}}*successPayload, {{/returnType}}err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return {{#returnType}}*successPayload, {{/returnType}}*a.Configuration.ApiClient.GetApiResponse(httpResponse), err } {{#returnType}} err = json.Unmarshal(httpResponse.Body(), &successPayload) {{/returnType}} - return {{#returnType}}*successPayload, {{/returnType}}err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return {{#returnType}}*successPayload, {{/returnType}}*a.Configuration.ApiClient.GetApiResponse(httpResponse), err } {{/operation}} {{/operations}} diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index f8e134982d8..c93a245e10e 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-04-17T23:42:10.705-07:00 +- Build date: 2016-04-23T15:46:19.755-07:00 - Build package: class io.swagger.codegen.languages.GoClientCodegen ## Installation @@ -46,8 +46,8 @@ Class | Method | HTTP request | Description ## Documentation For Models - - [ApiResponse](docs/ApiResponse.md) - [Category](docs/Category.md) + - [ModelApiResponse](docs/ModelApiResponse.md) - [Order](docs/Order.md) - [Pet](docs/Pet.md) - [Tag](docs/Tag.md) diff --git a/samples/client/petstore/go/go-petstore/docs/PetApi.md b/samples/client/petstore/go/go-petstore/docs/PetApi.md index 9caa3df6865..e96bdc1a15e 100644 --- a/samples/client/petstore/go/go-petstore/docs/PetApi.md +++ b/samples/client/petstore/go/go-petstore/docs/PetApi.md @@ -221,7 +221,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **UploadFile** -> ApiResponse UploadFile($petId, $additionalMetadata, $file) +> ModelApiResponse UploadFile($petId, $additionalMetadata, $file) uploads an image @@ -238,7 +238,7 @@ Name | Type | Description | Notes ### Return type -[**ApiResponse**](ApiResponse.md) +[**ModelApiResponse**](ApiResponse.md) ### Authorization diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 49ca502151c..25cd57a490c 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -35,7 +35,7 @@ func NewPetApiWithBasePath(basePath string) *PetApi{ * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) AddPet (body Pet) (error, ApiResponse) { +func (a PetApi) AddPet (body Pet) (ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -43,7 +43,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling PetApi->AddPet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->AddPet") } headerParams := make(map[string]string) @@ -95,10 +95,10 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Deletes a pet @@ -107,7 +107,7 @@ func (a PetApi) AddPet (body Pet) (error, ApiResponse) { * @param apiKey * @return void */ -func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { +func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -116,7 +116,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { // verify the required parameter 'petId' is set if &petId == nil { - return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") } headerParams := make(map[string]string) @@ -166,10 +166,10 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Finds Pets by status @@ -177,7 +177,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error, ApiResponse) { * @param status Status values that need to be considered for filter * @return []Pet */ -func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { +func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -185,7 +185,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { // verify the required parameter 'status' is set if &status == nil { - return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new([]Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") } headerParams := make(map[string]string) @@ -234,12 +234,12 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Finds Pets by tags @@ -247,7 +247,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error, ApiResponse) { * @param tags Tags to filter by * @return []Pet */ -func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { +func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -255,7 +255,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { // verify the required parameter 'tags' is set if &tags == nil { - return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new([]Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") } headerParams := make(map[string]string) @@ -304,12 +304,12 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Find pet by ID @@ -317,7 +317,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error, ApiResponse) { * @param petId ID of pet to return * @return Pet */ -func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { +func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -326,7 +326,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { // verify the required parameter 'petId' is set if &petId == nil { - return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") } headerParams := make(map[string]string) @@ -373,12 +373,12 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Update an existing pet @@ -386,7 +386,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error, ApiResponse) { * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { +func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { var httpMethod = "Put" // create path and map variables @@ -394,7 +394,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") } headerParams := make(map[string]string) @@ -446,10 +446,10 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Updates a pet in the store with form data @@ -459,7 +459,7 @@ func (a PetApi) UpdatePet (body Pet) (error, ApiResponse) { * @param status Updated status of the pet * @return void */ -func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error, ApiResponse) { +func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -468,7 +468,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err // verify the required parameter 'petId' is set if &petId == nil { - return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") } headerParams := make(map[string]string) @@ -519,10 +519,10 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * uploads an image @@ -530,9 +530,9 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - * @return ApiResponse + * @return ModelApiResponse */ -func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error, ApiResponse) { +func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ModelApiResponse, ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -541,7 +541,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil // verify the required parameter 'petId' is set if &petId == nil { - return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(ModelApiResponse), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") } headerParams := make(map[string]string) @@ -588,15 +588,15 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil fileBytes = fbs fileName = file.Name() - var successPayload = new(ApiResponse) + var successPayload = new(ModelApiResponse) httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index c1904d3dc6b..e70886e1984 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -33,7 +33,7 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{ * @param orderId ID of the order that needs to be deleted * @return void */ -func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { +func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -42,7 +42,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { // verify the required parameter 'orderId' is set if &orderId == nil { - return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") } headerParams := make(map[string]string) @@ -84,17 +84,17 @@ func (a StoreApi) DeleteOrder (orderId string) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Returns pet inventories by status * Returns a map of status codes to quantities * @return map[string]int32 */ -func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { +func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -144,12 +144,12 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Find purchase order by ID @@ -157,7 +157,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error, ApiResponse) { * @param orderId ID of pet that needs to be fetched * @return Order */ -func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { +func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -166,7 +166,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { // verify the required parameter 'orderId' is set if &orderId == nil { - return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(Order), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") } headerParams := make(map[string]string) @@ -208,12 +208,12 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Place an order for a pet @@ -221,7 +221,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error, ApiResponse) { * @param body order placed for purchasing the pet * @return Order */ -func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { +func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -229,7 +229,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(Order), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") } headerParams := make(map[string]string) @@ -273,10 +273,10 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 4e3cf387bc0..810756df9f1 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -33,7 +33,7 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ * @param body Created user object * @return void */ -func (a UserApi) CreateUser (body User) (error, ApiResponse) { +func (a UserApi) CreateUser (body User) (ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -41,7 +41,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") } headerParams := make(map[string]string) @@ -85,10 +85,10 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Creates list of users with given input array @@ -96,7 +96,7 @@ func (a UserApi) CreateUser (body User) (error, ApiResponse) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { +func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -104,7 +104,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") } headerParams := make(map[string]string) @@ -148,10 +148,10 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Creates list of users with given input array @@ -159,7 +159,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error, ApiResponse) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { +func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { var httpMethod = "Post" // create path and map variables @@ -167,7 +167,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") } headerParams := make(map[string]string) @@ -211,10 +211,10 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Delete user @@ -222,7 +222,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error, ApiResponse) { * @param username The name that needs to be deleted * @return void */ -func (a UserApi) DeleteUser (username string) (error, ApiResponse) { +func (a UserApi) DeleteUser (username string) (ApiResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -231,7 +231,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { // verify the required parameter 'username' is set if &username == nil { - return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") } headerParams := make(map[string]string) @@ -273,10 +273,10 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Get user by user name @@ -284,7 +284,7 @@ func (a UserApi) DeleteUser (username string) (error, ApiResponse) { * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ -func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { +func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -293,7 +293,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { // verify the required parameter 'username' is set if &username == nil { - return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(User), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") } headerParams := make(map[string]string) @@ -335,12 +335,12 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Logs user into the system @@ -349,7 +349,7 @@ func (a UserApi) GetUserByName (username string) (User, error, ApiResponse) { * @param password The password for login in clear text * @return string */ -func (a UserApi) LoginUser (username string, password string) (string, error, ApiResponse) { +func (a UserApi) LoginUser (username string, password string) (string, ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -357,11 +357,11 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap // verify the required parameter 'username' is set if &username == nil { - return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(string), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") } // verify the required parameter 'password' is set if &password == nil { - return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *new(string), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") } headerParams := make(map[string]string) @@ -405,19 +405,19 @@ func (a UserApi) LoginUser (username string, password string) (string, error, Ap if err != nil { - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Logs out current logged in user session * * @return void */ -func (a UserApi) LogoutUser () (error, ApiResponse) { +func (a UserApi) LogoutUser () (ApiResponse, error) { var httpMethod = "Get" // create path and map variables @@ -463,10 +463,10 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } /** * Updated user @@ -475,7 +475,7 @@ func (a UserApi) LogoutUser () (error, ApiResponse) { * @param body Updated user object * @return void */ -func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { +func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { var httpMethod = "Put" // create path and map variables @@ -484,11 +484,11 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { // verify the required parameter 'username' is set if &username == nil { - return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") } // verify the required parameter 'body' is set if &body == nil { - return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser"), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request") + return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") } headerParams := make(map[string]string) @@ -532,8 +532,8 @@ func (a UserApi) UpdateUser (username string, body User) (error, ApiResponse) { if err != nil { - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } - return err, *a.Configuration.ApiClient.GetApiResponse(httpResponse) + return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err } diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 2b831f58588..4174ff2de4b 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -12,7 +12,7 @@ func TestAddPet(t *testing.T) { newPet := (sw.Pet{Id: 12830, Name: "gopher", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}) - err, apiResponse := s.AddPet(newPet) + apiResponse, err := s.AddPet(newPet) if err != nil { t.Errorf("Error while adding pet") @@ -27,7 +27,7 @@ func TestGetPetById(t *testing.T) { assert := assert.New(t) s := sw.NewPetApi() - resp, err, apiResponse := s.GetPetById(12830) + resp, apiResponse, err := s.GetPetById(12830) if err != nil { t.Errorf("Error while getting pet by id") t.Log(err) @@ -45,7 +45,7 @@ func TestGetPetById(t *testing.T) { func TestGetPetByIdWithInvalidID(t *testing.T) { s := sw.NewPetApi() - resp, err, apiResponse := s.GetPetById(999999999) + resp, apiResponse, err := s.GetPetById(999999999) if err != nil { t.Errorf("Error while getting pet by invalid id") t.Log(err) @@ -61,7 +61,7 @@ func TestGetPetByIdWithInvalidID(t *testing.T) { func TestUpdatePetWithForm(t *testing.T) { s := sw.NewPetApi() - err, apiResponse := s.UpdatePetWithForm(12830, "golang", "available") + apiResponse, err := s.UpdatePetWithForm(12830, "golang", "available") if err != nil { t.Errorf("Error while updating pet by id") @@ -75,7 +75,7 @@ func TestUpdatePetWithForm(t *testing.T) { func TestFindPetsByStatus(t *testing.T) { s := sw.NewPetApi() - resp, err, apiResponse := s.FindPetsByStatus([]string {"pending"}) + resp, apiResponse, err := s.FindPetsByStatus([]string {"pending"}) if err != nil { t.Errorf("Error while getting pet by id") t.Log(err) @@ -96,7 +96,7 @@ func TestUploadFile(t *testing.T) { s := sw.NewPetApi() file, _ := os.Open("../python/testfiles/foo.png") - _, err, apiResponse := s.UploadFile(12830, "golang", file) + _, apiResponse, err := s.UploadFile(12830, "golang", file) if err != nil { t.Errorf("Error while uploading file") @@ -109,7 +109,7 @@ func TestUploadFile(t *testing.T) { func TestDeletePet(t *testing.T) { s := sw.NewPetApi() - err, apiResponse := s.DeletePet(12830, "") + apiResponse, err := s.DeletePet(12830, "") if err != nil { t.Errorf("Error while deleting pet by id") From 1de18eb074b0240c85aec4df626c55e4bb004469 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sat, 23 Apr 2016 17:50:17 -0700 Subject: [PATCH 21/24] added implementation of the new ApiResponse struct --- .../src/main/resources/go/api.mustache | 6 +-- .../src/main/resources/go/api_client.mustache | 18 ------- .../client/petstore/go/go-petstore/README.md | 2 +- .../petstore/go/go-petstore/api_client.go | 18 ------- .../petstore/go/go-petstore/api_response.go | 22 +++++--- .../client/petstore/go/go-petstore/pet_api.go | 48 +++++++++--------- .../petstore/go/go-petstore/store_api.go | 22 ++++---- .../petstore/go/go-petstore/user_api.go | 50 +++++++++---------- samples/client/petstore/go/pet_api_test.go | 41 +++++++++------ 9 files changed, 107 insertions(+), 120 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 5313732906a..852e70bd447 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -49,7 +49,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#required}} // verify the required parameter '{{paramName}}' is set if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}*a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") + return {{#returnType}}*new({{{returnType}}}), {{/returnType}}*NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") } {{/required}} {{/allParams}} @@ -138,14 +138,14 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ if err != nil { - return {{#returnType}}*successPayload, {{/returnType}}*a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return {{#returnType}}*successPayload, {{/returnType}}*NewApiResponse(httpResponse.RawResponse), err } {{#returnType}} err = json.Unmarshal(httpResponse.Body(), &successPayload) {{/returnType}} - return {{#returnType}}*successPayload, {{/returnType}}*a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return {{#returnType}}*successPayload, {{/returnType}}*NewApiResponse(httpResponse.RawResponse), err } {{/operation}} {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 9143f33b504..91a84551700 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -89,24 +89,6 @@ func (c *ApiClient) ParameterToString(obj interface{}) string { } } -func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ - httpResponse := httpResp.(*resty.Response) - apiResponse := new(ApiResponse) - apiResponse.Code = int32(httpResponse.StatusCode()) - apiResponse.Message = httpResponse.Status() - - return apiResponse -} - -func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ - - apiResponse := new(ApiResponse) - apiResponse.Code = int32(400) - apiResponse.Message = errorMessage - - return apiResponse -} - func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index c93a245e10e..910888030a1 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-04-23T15:46:19.755-07:00 +- Build date: 2016-04-23T17:00:49.475-07:00 - Build package: class io.swagger.codegen.languages.GoClientCodegen ## Installation diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 33451139a97..1c04e52fdc4 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -89,24 +89,6 @@ func (c *ApiClient) ParameterToString(obj interface{}) string { } } -func (c *ApiClient) GetApiResponse(httpResp interface{}) *ApiResponse{ - httpResponse := httpResp.(*resty.Response) - apiResponse := new(ApiResponse) - apiResponse.Code = int32(httpResponse.StatusCode()) - apiResponse.Message = httpResponse.Status() - - return apiResponse -} - -func (c *ApiClient) SetErrorApiResponse(errorMessage string) *ApiResponse{ - - apiResponse := new(ApiResponse) - apiResponse.Code = int32(400) - apiResponse.Message = errorMessage - - return apiResponse -} - func prepareRequest(postBody interface{}, headerParams map[string]string, queryParams map[string]string, diff --git a/samples/client/petstore/go/go-petstore/api_response.go b/samples/client/petstore/go/go-petstore/api_response.go index abb7971189d..b9110bd9eda 100644 --- a/samples/client/petstore/go/go-petstore/api_response.go +++ b/samples/client/petstore/go/go-petstore/api_response.go @@ -1,14 +1,24 @@ package swagger import ( + "net/http" ) type ApiResponse struct { - - Code int32 `json:"code,omitempty"` - - Type_ string `json:"type,omitempty"` - - Message string `json:"message,omitempty"` + *http.Response + + Message string `json:"message,omitempty"` } + +func NewApiResponse(r *http.Response) *ApiResponse { + response := &ApiResponse{Response: r} + + return response +} + +func NewApiResponseWithError(errorMessage string) *ApiResponse { + response := &ApiResponse{Message: errorMessage} + + return response +} \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 25cd57a490c..e9ebdf44de4 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -43,7 +43,7 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->AddPet") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->AddPet") } headerParams := make(map[string]string) @@ -95,10 +95,10 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Deletes a pet @@ -116,7 +116,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { // verify the required parameter 'petId' is set if &petId == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") } headerParams := make(map[string]string) @@ -166,10 +166,10 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Finds Pets by status @@ -185,7 +185,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { // verify the required parameter 'status' is set if &status == nil { - return *new([]Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") + return *new([]Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") } headerParams := make(map[string]string) @@ -234,12 +234,12 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Finds Pets by tags @@ -255,7 +255,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { // verify the required parameter 'tags' is set if &tags == nil { - return *new([]Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") + return *new([]Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") } headerParams := make(map[string]string) @@ -304,12 +304,12 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Find pet by ID @@ -326,7 +326,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { // verify the required parameter 'petId' is set if &petId == nil { - return *new(Pet), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") + return *new(Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") } headerParams := make(map[string]string) @@ -373,12 +373,12 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Update an existing pet @@ -394,7 +394,7 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") } headerParams := make(map[string]string) @@ -446,10 +446,10 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Updates a pet in the store with form data @@ -468,7 +468,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api // verify the required parameter 'petId' is set if &petId == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") } headerParams := make(map[string]string) @@ -519,10 +519,10 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * uploads an image @@ -541,7 +541,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil // verify the required parameter 'petId' is set if &petId == nil { - return *new(ModelApiResponse), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") + return *new(ModelApiResponse), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") } headerParams := make(map[string]string) @@ -593,10 +593,10 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index e70886e1984..5da713a7d95 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -42,7 +42,7 @@ func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { // verify the required parameter 'orderId' is set if &orderId == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") } headerParams := make(map[string]string) @@ -84,10 +84,10 @@ func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Returns pet inventories by status @@ -144,12 +144,12 @@ func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Find purchase order by ID @@ -166,7 +166,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { // verify the required parameter 'orderId' is set if &orderId == nil { - return *new(Order), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") + return *new(Order), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") } headerParams := make(map[string]string) @@ -208,12 +208,12 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Place an order for a pet @@ -229,7 +229,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *new(Order), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") + return *new(Order), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") } headerParams := make(map[string]string) @@ -273,10 +273,10 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 810756df9f1..6a6188074b3 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -41,7 +41,7 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") } headerParams := make(map[string]string) @@ -85,10 +85,10 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -104,7 +104,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") } headerParams := make(map[string]string) @@ -148,10 +148,10 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -167,7 +167,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") } headerParams := make(map[string]string) @@ -211,10 +211,10 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Delete user @@ -231,7 +231,7 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") } headerParams := make(map[string]string) @@ -273,10 +273,10 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Get user by user name @@ -293,7 +293,7 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *new(User), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") + return *new(User), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") } headerParams := make(map[string]string) @@ -335,12 +335,12 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Logs user into the system @@ -357,11 +357,11 @@ func (a UserApi) LoginUser (username string, password string) (string, ApiRespon // verify the required parameter 'username' is set if &username == nil { - return *new(string), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") + return *new(string), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") } // verify the required parameter 'password' is set if &password == nil { - return *new(string), *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") + return *new(string), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") } headerParams := make(map[string]string) @@ -405,12 +405,12 @@ func (a UserApi) LoginUser (username string, password string) (string, ApiRespon if err != nil { - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *successPayload, *NewApiResponse(httpResponse.RawResponse), err } /** * Logs out current logged in user session @@ -463,10 +463,10 @@ func (a UserApi) LogoutUser () (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } /** * Updated user @@ -484,11 +484,11 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") } // verify the required parameter 'body' is set if &body == nil { - return *a.Configuration.ApiClient.SetErrorApiResponse("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") + return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") } headerParams := make(map[string]string) @@ -532,8 +532,8 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { if err != nil { - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } - return *a.Configuration.ApiClient.GetApiResponse(httpResponse), err + return *NewApiResponse(httpResponse.RawResponse), err } diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 4174ff2de4b..5b18e3a7675 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -18,7 +18,21 @@ func TestAddPet(t *testing.T) { t.Errorf("Error while adding pet") t.Log(err) } - if apiResponse.Code != 200 { + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } +} + +func TestFindPetsByStatusWithMissingParam(t *testing.T) { + s := sw.NewPetApi() + + _, apiResponse, err := s.FindPetsByStatus(nil) + + if err != nil { + t.Errorf("Error while testing TestFindPetsByStatusWithMissingParam") + t.Log(err) + } + if apiResponse.Response.StatusCode != 200 { t.Log(apiResponse) } } @@ -38,8 +52,8 @@ func TestGetPetById(t *testing.T) { //t.Log(resp) } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } @@ -51,11 +65,10 @@ func TestGetPetByIdWithInvalidID(t *testing.T) { t.Log(err) t.Log(apiResponse) } else { - t.Log(resp) } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } @@ -68,8 +81,8 @@ func TestUpdatePetWithForm(t *testing.T) { t.Log(err) t.Log(apiResponse) } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } @@ -86,8 +99,8 @@ func TestFindPetsByStatus(t *testing.T) { t.Errorf("Error no pets returned") } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } } @@ -102,8 +115,8 @@ func TestUploadFile(t *testing.T) { t.Errorf("Error while uploading file") t.Log(err) } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } @@ -115,7 +128,7 @@ func TestDeletePet(t *testing.T) { t.Errorf("Error while deleting pet by id") t.Log(err) } - if apiResponse.Code != 200 { - t.Log(apiResponse) + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } From ea445c1e2884a7acff014254dd9bbe2e784f86b1 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 24 Apr 2016 15:44:52 -0700 Subject: [PATCH 22/24] added missing file --- .../main/resources/go/api_response.mustache | 24 +++++++++++++++++++ .../go/go-petstore/model_api_response.go | 14 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 modules/swagger-codegen/src/main/resources/go/api_response.mustache create mode 100644 samples/client/petstore/go/go-petstore/model_api_response.go diff --git a/modules/swagger-codegen/src/main/resources/go/api_response.mustache b/modules/swagger-codegen/src/main/resources/go/api_response.mustache new file mode 100644 index 00000000000..b9110bd9eda --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go/api_response.mustache @@ -0,0 +1,24 @@ +package swagger + +import ( + "net/http" +) + + +type ApiResponse struct { + *http.Response + + Message string `json:"message,omitempty"` +} + +func NewApiResponse(r *http.Response) *ApiResponse { + response := &ApiResponse{Response: r} + + return response +} + +func NewApiResponseWithError(errorMessage string) *ApiResponse { + response := &ApiResponse{Message: errorMessage} + + return response +} \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/model_api_response.go b/samples/client/petstore/go/go-petstore/model_api_response.go new file mode 100644 index 00000000000..0905f55cf01 --- /dev/null +++ b/samples/client/petstore/go/go-petstore/model_api_response.go @@ -0,0 +1,14 @@ +package swagger + +import ( +) + + +type ModelApiResponse struct { + + Code int32 `json:"code,omitempty"` + + Type_ string `json:"type,omitempty"` + + Message string `json:"message,omitempty"` +} From 9f0ac5df82492004fcbeb51007cb935a61a3a430 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 24 Apr 2016 15:52:26 -0700 Subject: [PATCH 23/24] added missing model api response md --- .../petstore/go/go-petstore/docs/ModelApiResponse.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 samples/client/petstore/go/go-petstore/docs/ModelApiResponse.md diff --git a/samples/client/petstore/go/go-petstore/docs/ModelApiResponse.md b/samples/client/petstore/go/go-petstore/docs/ModelApiResponse.md new file mode 100644 index 00000000000..f4af2146829 --- /dev/null +++ b/samples/client/petstore/go/go-petstore/docs/ModelApiResponse.md @@ -0,0 +1,12 @@ +# ModelApiResponse + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Code** | **int32** | | [optional] [default to null] +**Type_** | **string** | | [optional] [default to null] +**Message** | **string** | | [optional] [default to null] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + From 7599dcb112cfa3bfe66fe2ef8e825d7b094d585a Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 24 Apr 2016 21:10:32 -0700 Subject: [PATCH 24/24] changed Api to API based on golang's convention --- .../src/main/resources/go/api.mustache | 20 +-- .../src/main/resources/go/api_client.mustache | 14 +-- .../main/resources/go/api_response.mustache | 10 +- .../main/resources/go/configuration.mustache | 18 +-- .../petstore/go/go-petstore/api_client.go | 14 +-- .../petstore/go/go-petstore/api_response.go | 10 +- .../petstore/go/go-petstore/configuration.go | 18 +-- .../client/petstore/go/go-petstore/pet_api.go | 118 +++++++++--------- .../petstore/go/go-petstore/store_api.go | 56 ++++----- .../petstore/go/go-petstore/user_api.go | 118 +++++++++--------- 10 files changed, 198 insertions(+), 198 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 852e70bd447..6e540d3f876 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -37,7 +37,7 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{ {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ -func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}ApiResponse, error) { +func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}APIResponse, error) { var httpMethod = "{{httpMethod}}" // create path and map variables @@ -49,7 +49,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#required}} // verify the required parameter '{{paramName}}' is set if &{{paramName}} == nil { - return {{#returnType}}*new({{{returnType}}}), {{/returnType}}*NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") + return {{#returnType}}*new({{{returnType}}}), {{/returnType}}*NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") } {{/required}} {{/allParams}} @@ -64,11 +64,11 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#authMethods}}// authentication ({{name}}) required {{#isApiKey}}{{#isKeyInHeader}} // set key with prefix in header - headerParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") + headerParams["{{keyParamName}}"] = a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}") {{/isKeyInHeader}}{{#isKeyInQuery}} // set key with prefix in querystring {{#hasKeyParamName}} - queryParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") + queryParams["{{keyParamName}}"] = a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}") {{/hasKeyParamName}} {{/isKeyInQuery}}{{/isApiKey}} {{#isBasic}} @@ -92,7 +92,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{#hasQueryParams}} {{#queryParams}} - queryParams["{{paramName}}"] = a.Configuration.ApiClient.ParameterToString({{paramName}}) + queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}) {{/queryParams}} {{/hasQueryParams}} @@ -103,7 +103,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/consumes}} } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -114,7 +114,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ {{/produces}} } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -134,18 +134,18 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ postBody = &{{paramName}} {{/bodyParams}}{{/hasBodyParam}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}} - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return {{#returnType}}*successPayload, {{/returnType}}*NewApiResponse(httpResponse.RawResponse), err + return {{#returnType}}*successPayload, {{/returnType}}*NewAPIResponse(httpResponse.RawResponse), err } {{#returnType}} err = json.Unmarshal(httpResponse.Body(), &successPayload) {{/returnType}} - return {{#returnType}}*successPayload, {{/returnType}}*NewApiResponse(httpResponse.RawResponse), err + return {{#returnType}}*successPayload, {{/returnType}}*NewAPIResponse(httpResponse.RawResponse), err } {{/operation}} {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/go/api_client.mustache b/modules/swagger-codegen/src/main/resources/go/api_client.mustache index 91a84551700..a88445656d7 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -3,17 +3,17 @@ package {{packageName}} import ( "strings" "github.com/go-resty/resty" - "errors" + "fmt" "reflect" "bytes" "path/filepath" ) -type ApiClient struct { +type APIClient struct { } -func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string { +func (c *APIClient) SelectHeaderContentType(contentTypes []string) string { if (len(contentTypes) == 0){ return "" } @@ -24,7 +24,7 @@ func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string { return contentTypes[0] // use the first content type specified in 'consumes' } -func (c *ApiClient) SelectHeaderAccept(accepts []string) string { +func (c *APIClient) SelectHeaderAccept(accepts []string) string { if (len(accepts) == 0){ return "" } @@ -46,7 +46,7 @@ func contains(source []string, containvalue string) bool { } -func (c *ApiClient) CallApi(path string, method string, +func (c *APIClient) CallAPI(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, @@ -78,10 +78,10 @@ func (c *ApiClient) CallApi(path string, method string, return response, err } - return nil, errors.New("Invalid method " + method) + return nil, fmt.Errorf("invalid method %v", method) } -func (c *ApiClient) ParameterToString(obj interface{}) string { +func (c *APIClient) ParameterToString(obj interface{}) string { if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else { diff --git a/modules/swagger-codegen/src/main/resources/go/api_response.mustache b/modules/swagger-codegen/src/main/resources/go/api_response.mustache index b9110bd9eda..2a34a8cf35a 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_response.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_response.mustache @@ -5,20 +5,20 @@ import ( ) -type ApiResponse struct { +type APIResponse struct { *http.Response Message string `json:"message,omitempty"` } -func NewApiResponse(r *http.Response) *ApiResponse { - response := &ApiResponse{Response: r} +func NewAPIResponse(r *http.Response) *APIResponse { + response := &APIResponse{Response: r} return response } -func NewApiResponseWithError(errorMessage string) *ApiResponse { - response := &ApiResponse{Message: errorMessage} +func NewAPIResponseWithError(errorMessage string) *APIResponse { + response := &APIResponse{Message: errorMessage} return response } \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go/configuration.mustache b/modules/swagger-codegen/src/main/resources/go/configuration.mustache index e5f05a63c12..d971bf0373b 100644 --- a/modules/swagger-codegen/src/main/resources/go/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/go/configuration.mustache @@ -7,8 +7,8 @@ import ( type Configuration struct { UserName string `json:"userName,omitempty"` Password string `json:"password,omitempty"` - ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` - ApiKey map[string] string `json:"apiKey,omitempty"` + APIKeyPrefix map[string] string `json:"APIKeyPrefix,omitempty"` + APIKey map[string] string `json:"APIKey,omitempty"` debug bool `json:"debug,omitempty"` DebugFile string `json:"debugFile,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"` @@ -19,7 +19,7 @@ type Configuration struct { AccessToken string `json:"accessToken,omitempty"` DefaultHeader map[string]string `json:"defaultHeader,omitempty"` UserAgent string `json:"userAgent,omitempty"` - ApiClient ApiClient `json:"apiClient,omitempty"` + APIClient APIClient `json:"APIClient,omitempty"` } func NewConfiguration() *Configuration { @@ -28,8 +28,8 @@ func NewConfiguration() *Configuration { UserName: "", debug: false, DefaultHeader: make(map[string]string), - ApiKey: make(map[string]string), - ApiKeyPrefix: make(map[string]string), + APIKey: make(map[string]string), + APIKeyPrefix: make(map[string]string), UserAgent: "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{packageVersion}}}/go{{/httpUserAgent}}", } } @@ -42,12 +42,12 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { c.DefaultHeader[key] = value } -func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string { - if c.ApiKeyPrefix[apiKeyIdentifier] != ""{ - return c.ApiKeyPrefix[apiKeyIdentifier] + " " + c.ApiKey[apiKeyIdentifier] +func (c *Configuration) GetAPIKeyWithPrefix(APIKeyIdentifier string) string { + if c.APIKeyPrefix[APIKeyIdentifier] != ""{ + return c.APIKeyPrefix[APIKeyIdentifier] + " " + c.APIKey[APIKeyIdentifier] } - return c.ApiKey[apiKeyIdentifier] + return c.APIKey[APIKeyIdentifier] } func (c *Configuration) SetDebug(enable bool){ diff --git a/samples/client/petstore/go/go-petstore/api_client.go b/samples/client/petstore/go/go-petstore/api_client.go index 1c04e52fdc4..d4b53512c68 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -3,17 +3,17 @@ package swagger import ( "strings" "github.com/go-resty/resty" - "errors" + "fmt" "reflect" "bytes" "path/filepath" ) -type ApiClient struct { +type APIClient struct { } -func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string { +func (c *APIClient) SelectHeaderContentType(contentTypes []string) string { if (len(contentTypes) == 0){ return "" } @@ -24,7 +24,7 @@ func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string { return contentTypes[0] // use the first content type specified in 'consumes' } -func (c *ApiClient) SelectHeaderAccept(accepts []string) string { +func (c *APIClient) SelectHeaderAccept(accepts []string) string { if (len(accepts) == 0){ return "" } @@ -46,7 +46,7 @@ func contains(source []string, containvalue string) bool { } -func (c *ApiClient) CallApi(path string, method string, +func (c *APIClient) CallAPI(path string, method string, postBody interface{}, headerParams map[string]string, queryParams map[string]string, @@ -78,10 +78,10 @@ func (c *ApiClient) CallApi(path string, method string, return response, err } - return nil, errors.New("Invalid method " + method) + return nil, fmt.Errorf("invalid method %v", method) } -func (c *ApiClient) ParameterToString(obj interface{}) string { +func (c *APIClient) ParameterToString(obj interface{}) string { if reflect.TypeOf(obj).String() == "[]string" { return strings.Join(obj.([]string), ",") } else { diff --git a/samples/client/petstore/go/go-petstore/api_response.go b/samples/client/petstore/go/go-petstore/api_response.go index b9110bd9eda..2a34a8cf35a 100644 --- a/samples/client/petstore/go/go-petstore/api_response.go +++ b/samples/client/petstore/go/go-petstore/api_response.go @@ -5,20 +5,20 @@ import ( ) -type ApiResponse struct { +type APIResponse struct { *http.Response Message string `json:"message,omitempty"` } -func NewApiResponse(r *http.Response) *ApiResponse { - response := &ApiResponse{Response: r} +func NewAPIResponse(r *http.Response) *APIResponse { + response := &APIResponse{Response: r} return response } -func NewApiResponseWithError(errorMessage string) *ApiResponse { - response := &ApiResponse{Message: errorMessage} +func NewAPIResponseWithError(errorMessage string) *APIResponse { + response := &APIResponse{Message: errorMessage} return response } \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/configuration.go b/samples/client/petstore/go/go-petstore/configuration.go index 3fe94d36c26..2a1b4096399 100644 --- a/samples/client/petstore/go/go-petstore/configuration.go +++ b/samples/client/petstore/go/go-petstore/configuration.go @@ -7,8 +7,8 @@ import ( type Configuration struct { UserName string `json:"userName,omitempty"` Password string `json:"password,omitempty"` - ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` - ApiKey map[string] string `json:"apiKey,omitempty"` + APIKeyPrefix map[string] string `json:"APIKeyPrefix,omitempty"` + APIKey map[string] string `json:"APIKey,omitempty"` debug bool `json:"debug,omitempty"` DebugFile string `json:"debugFile,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"` @@ -19,7 +19,7 @@ type Configuration struct { AccessToken string `json:"accessToken,omitempty"` DefaultHeader map[string]string `json:"defaultHeader,omitempty"` UserAgent string `json:"userAgent,omitempty"` - ApiClient ApiClient `json:"apiClient,omitempty"` + APIClient APIClient `json:"APIClient,omitempty"` } func NewConfiguration() *Configuration { @@ -28,8 +28,8 @@ func NewConfiguration() *Configuration { UserName: "", debug: false, DefaultHeader: make(map[string]string), - ApiKey: make(map[string]string), - ApiKeyPrefix: make(map[string]string), + APIKey: make(map[string]string), + APIKeyPrefix: make(map[string]string), UserAgent: "Swagger-Codegen/1.0.0/go", } } @@ -42,12 +42,12 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { c.DefaultHeader[key] = value } -func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string { - if c.ApiKeyPrefix[apiKeyIdentifier] != ""{ - return c.ApiKeyPrefix[apiKeyIdentifier] + " " + c.ApiKey[apiKeyIdentifier] +func (c *Configuration) GetAPIKeyWithPrefix(APIKeyIdentifier string) string { + if c.APIKeyPrefix[APIKeyIdentifier] != ""{ + return c.APIKeyPrefix[APIKeyIdentifier] + " " + c.APIKey[APIKeyIdentifier] } - return c.ApiKey[apiKeyIdentifier] + return c.APIKey[APIKeyIdentifier] } func (c *Configuration) SetDebug(enable bool){ diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index e9ebdf44de4..423e8a795a7 100644 --- a/samples/client/petstore/go/go-petstore/pet_api.go +++ b/samples/client/petstore/go/go-petstore/pet_api.go @@ -35,7 +35,7 @@ func NewPetApiWithBasePath(basePath string) *PetApi{ * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) AddPet (body Pet) (ApiResponse, error) { +func (a PetApi) AddPet (body Pet) (APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -43,7 +43,7 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->AddPet") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->AddPet") } headerParams := make(map[string]string) @@ -72,7 +72,7 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { "application/xml", } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -82,7 +82,7 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -91,14 +91,14 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Deletes a pet @@ -107,7 +107,7 @@ func (a PetApi) AddPet (body Pet) (ApiResponse, error) { * @param apiKey * @return void */ -func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { +func (a PetApi) DeletePet (petId int64, apiKey string) (APIResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -116,7 +116,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { // verify the required parameter 'petId' is set if &petId == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet") } headerParams := make(map[string]string) @@ -143,7 +143,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -153,7 +153,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -162,14 +162,14 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Finds Pets by status @@ -177,7 +177,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (ApiResponse, error) { * @param status Status values that need to be considered for filter * @return []Pet */ -func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { +func (a PetApi) FindPetsByStatus (status []string) ([]Pet, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -185,7 +185,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { // verify the required parameter 'status' is set if &status == nil { - return *new([]Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") + return *new([]Pet), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") } headerParams := make(map[string]string) @@ -207,13 +207,13 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["status"] = a.Configuration.ApiClient.ParameterToString(status) + queryParams["status"] = a.Configuration.APIClient.ParameterToString(status) // to determine the Content-Type header localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -223,23 +223,23 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Finds Pets by tags @@ -247,7 +247,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, ApiResponse, error) { * @param tags Tags to filter by * @return []Pet */ -func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { +func (a PetApi) FindPetsByTags (tags []string) ([]Pet, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -255,7 +255,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { // verify the required parameter 'tags' is set if &tags == nil { - return *new([]Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") + return *new([]Pet), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") } headerParams := make(map[string]string) @@ -277,13 +277,13 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["tags"] = a.Configuration.ApiClient.ParameterToString(tags) + queryParams["tags"] = a.Configuration.APIClient.ParameterToString(tags) // to determine the Content-Type header localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -293,23 +293,23 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new([]Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Find pet by ID @@ -317,7 +317,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, ApiResponse, error) { * @param petId ID of pet to return * @return Pet */ -func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { +func (a PetApi) GetPetById (petId int64) (Pet, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -326,7 +326,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { // verify the required parameter 'petId' is set if &petId == nil { - return *new(Pet), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") + return *new(Pet), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") } headerParams := make(map[string]string) @@ -339,7 +339,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { // authentication (api_key) required // set key with prefix in header - headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") + headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") // add default headers if any @@ -352,7 +352,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -362,23 +362,23 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new(Pet) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Update an existing pet @@ -386,7 +386,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, ApiResponse, error) { * @param body Pet object that needs to be added to the store * @return void */ -func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { +func (a PetApi) UpdatePet (body Pet) (APIResponse, error) { var httpMethod = "Put" // create path and map variables @@ -394,7 +394,7 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet") } headerParams := make(map[string]string) @@ -423,7 +423,7 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { "application/xml", } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -433,7 +433,7 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -442,14 +442,14 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Updates a pet in the store with form data @@ -459,7 +459,7 @@ func (a PetApi) UpdatePet (body Pet) (ApiResponse, error) { * @param status Updated status of the pet * @return void */ -func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (ApiResponse, error) { +func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -468,7 +468,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api // verify the required parameter 'petId' is set if &petId == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm") } headerParams := make(map[string]string) @@ -496,7 +496,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api "application/x-www-form-urlencoded", } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -506,7 +506,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -515,14 +515,14 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api formParams["status"] = status - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * uploads an image @@ -532,7 +532,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (Api * @param file file to upload * @return ModelApiResponse */ -func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ModelApiResponse, ApiResponse, error) { +func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ModelApiResponse, APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -541,7 +541,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil // verify the required parameter 'petId' is set if &petId == nil { - return *new(ModelApiResponse), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") + return *new(ModelApiResponse), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile") } headerParams := make(map[string]string) @@ -569,7 +569,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil "multipart/form-data", } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -578,7 +578,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -589,14 +589,14 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil fileName = file.Name() var successPayload = new(ModelApiResponse) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } diff --git a/samples/client/petstore/go/go-petstore/store_api.go b/samples/client/petstore/go/go-petstore/store_api.go index 5da713a7d95..a8b48f63b39 100644 --- a/samples/client/petstore/go/go-petstore/store_api.go +++ b/samples/client/petstore/go/go-petstore/store_api.go @@ -33,7 +33,7 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{ * @param orderId ID of the order that needs to be deleted * @return void */ -func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { +func (a StoreApi) DeleteOrder (orderId string) (APIResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -42,7 +42,7 @@ func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { // verify the required parameter 'orderId' is set if &orderId == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder") } headerParams := make(map[string]string) @@ -63,7 +63,7 @@ func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -73,28 +73,28 @@ func (a StoreApi) DeleteOrder (orderId string) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Returns pet inventories by status * Returns a map of status codes to quantities * @return map[string]int32 */ -func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { +func (a StoreApi) GetInventory () (map[string]int32, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -111,7 +111,7 @@ func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { // authentication (api_key) required // set key with prefix in header - headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key") + headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") // add default headers if any @@ -124,7 +124,7 @@ func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -133,23 +133,23 @@ func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new(map[string]int32) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Find purchase order by ID @@ -157,7 +157,7 @@ func (a StoreApi) GetInventory () (map[string]int32, ApiResponse, error) { * @param orderId ID of pet that needs to be fetched * @return Order */ -func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { +func (a StoreApi) GetOrderById (orderId int64) (Order, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -166,7 +166,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { // verify the required parameter 'orderId' is set if &orderId == nil { - return *new(Order), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") + return *new(Order), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById") } headerParams := make(map[string]string) @@ -187,7 +187,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -197,23 +197,23 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Place an order for a pet @@ -221,7 +221,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, ApiResponse, error) { * @param body order placed for purchasing the pet * @return Order */ -func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { +func (a StoreApi) PlaceOrder (body Order) (Order, APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -229,7 +229,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *new(Order), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") + return *new(Order), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder") } headerParams := make(map[string]string) @@ -250,7 +250,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -260,7 +260,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -269,14 +269,14 @@ func (a StoreApi) PlaceOrder (body Order) (Order, ApiResponse, error) { postBody = &body var successPayload = new(Order) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } diff --git a/samples/client/petstore/go/go-petstore/user_api.go b/samples/client/petstore/go/go-petstore/user_api.go index 6a6188074b3..228c8d3f9bd 100644 --- a/samples/client/petstore/go/go-petstore/user_api.go +++ b/samples/client/petstore/go/go-petstore/user_api.go @@ -33,7 +33,7 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ * @param body Created user object * @return void */ -func (a UserApi) CreateUser (body User) (ApiResponse, error) { +func (a UserApi) CreateUser (body User) (APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -41,7 +41,7 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUser") } headerParams := make(map[string]string) @@ -62,7 +62,7 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -72,7 +72,7 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -81,14 +81,14 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -96,7 +96,7 @@ func (a UserApi) CreateUser (body User) (ApiResponse, error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { +func (a UserApi) CreateUsersWithArrayInput (body []User) (APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -104,7 +104,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput") } headerParams := make(map[string]string) @@ -125,7 +125,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -135,7 +135,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -144,14 +144,14 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -159,7 +159,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (ApiResponse, error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { +func (a UserApi) CreateUsersWithListInput (body []User) (APIResponse, error) { var httpMethod = "Post" // create path and map variables @@ -167,7 +167,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput") } headerParams := make(map[string]string) @@ -188,7 +188,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -198,7 +198,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -207,14 +207,14 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Delete user @@ -222,7 +222,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (ApiResponse, error) { * @param username The name that needs to be deleted * @return void */ -func (a UserApi) DeleteUser (username string) (ApiResponse, error) { +func (a UserApi) DeleteUser (username string) (APIResponse, error) { var httpMethod = "Delete" // create path and map variables @@ -231,7 +231,7 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser") } headerParams := make(map[string]string) @@ -252,7 +252,7 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -262,21 +262,21 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Get user by user name @@ -284,7 +284,7 @@ func (a UserApi) DeleteUser (username string) (ApiResponse, error) { * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ -func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { +func (a UserApi) GetUserByName (username string) (User, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -293,7 +293,7 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *new(User), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") + return *new(User), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName") } headerParams := make(map[string]string) @@ -314,7 +314,7 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -324,23 +324,23 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new(User) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Logs user into the system @@ -349,7 +349,7 @@ func (a UserApi) GetUserByName (username string) (User, ApiResponse, error) { * @param password The password for login in clear text * @return string */ -func (a UserApi) LoginUser (username string, password string) (string, ApiResponse, error) { +func (a UserApi) LoginUser (username string, password string) (string, APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -357,11 +357,11 @@ func (a UserApi) LoginUser (username string, password string) (string, ApiRespon // verify the required parameter 'username' is set if &username == nil { - return *new(string), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") + return *new(string), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser") } // verify the required parameter 'password' is set if &password == nil { - return *new(string), *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") + return *new(string), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser") } headerParams := make(map[string]string) @@ -377,14 +377,14 @@ func (a UserApi) LoginUser (username string, password string) (string, ApiRespon headerParams[key] = a.Configuration.DefaultHeader[key] } - queryParams["username"] = a.Configuration.ApiClient.ParameterToString(username) - queryParams["password"] = a.Configuration.ApiClient.ParameterToString(password) + queryParams["username"] = a.Configuration.APIClient.ParameterToString(username) + queryParams["password"] = a.Configuration.APIClient.ParameterToString(password) // to determine the Content-Type header localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -394,30 +394,30 @@ func (a UserApi) LoginUser (username string, password string) (string, ApiRespon "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } var successPayload = new(string) - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } err = json.Unmarshal(httpResponse.Body(), &successPayload) - return *successPayload, *NewApiResponse(httpResponse.RawResponse), err + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Logs out current logged in user session * * @return void */ -func (a UserApi) LogoutUser () (ApiResponse, error) { +func (a UserApi) LogoutUser () (APIResponse, error) { var httpMethod = "Get" // create path and map variables @@ -442,7 +442,7 @@ func (a UserApi) LogoutUser () (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -452,21 +452,21 @@ func (a UserApi) LogoutUser () (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Updated user @@ -475,7 +475,7 @@ func (a UserApi) LogoutUser () (ApiResponse, error) { * @param body Updated user object * @return void */ -func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { +func (a UserApi) UpdateUser (username string, body User) (APIResponse, error) { var httpMethod = "Put" // create path and map variables @@ -484,11 +484,11 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { // verify the required parameter 'username' is set if &username == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser") } // verify the required parameter 'body' is set if &body == nil { - return *NewApiResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") + return *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser") } headerParams := make(map[string]string) @@ -509,7 +509,7 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { localVarHttpContentTypes := []string { } //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) + localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes) if localVarHttpContentType != "" { headerParams["Content-Type"] = localVarHttpContentType } @@ -519,7 +519,7 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { "application/json", } //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) + localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { headerParams["Accept"] = localVarHttpHeaderAccept } @@ -528,12 +528,12 @@ func (a UserApi) UpdateUser (username string, body User) (ApiResponse, error) { postBody = &body - httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) if err != nil { - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err } - return *NewApiResponse(httpResponse.RawResponse), err + return *NewAPIResponse(httpResponse.RawResponse), err }