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..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 ); @@ -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("os", "io/ioutil"); cliOptions.clear(); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).") @@ -144,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")); } @@ -323,7 +325,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { return swaggerType; } - return camelize(swaggerType, false); + return toModelName(swaggerType); } @Override @@ -374,6 +376,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; } @@ -388,6 +407,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; } @@ -404,4 +441,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 35ed984929d..6e540d3f876 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}} ) @@ -38,130 +37,115 @@ 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) { - {{#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) +func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}APIResponse, error) { - {{#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) + 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}} - _sling = _sling.Path(path) + {{#allParams}} + {{#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}}") + } + {{/required}} + {{/allParams}} - // 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}} + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // 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) - } + {{#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}} - // 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) - } + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + + {{#hasQueryParams}} + {{#queryParams}} + queryParams["{{paramName}}"] = 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 + } {{#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}} + {{#isFile}}fbs, _ := ioutil.ReadAll(file) + fileBytes = fbs + fileName = file.Name() + {{/isFile}} +{{^isFile}}formParams["{{paramName}}"] = {{paramName}} + {{/isFile}} {{/formParams}} - } - _sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} }) -{{/hasFormParams}} -{{#hasBodyParam}}{{#bodyParams}}// body params - _sling = _sling.BodyJSON({{paramName}}) +{{/hasFormParams}}{{#hasBodyParam}}{{#bodyParams}} // body params + postBody = &{{paramName}} {{/bodyParams}}{{/hasBodyParam}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}} + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) - // 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)) - } - } + if err != nil { + return {{#returnType}}*successPayload, {{/returnType}}*NewAPIResponse(httpResponse.RawResponse), err } +{{#returnType}} - return {{#returnType}}*successPayload, {{/returnType}}err + err = json.Unmarshal(httpResponse.Body(), &successPayload) +{{/returnType}} + + 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 06470ba06d6..a88445656d7 100644 --- a/modules/swagger-codegen/src/main/resources/go/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api_client.mustache @@ -2,13 +2,18 @@ package {{packageName}} import ( "strings" + "github.com/go-resty/resty" + "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 "" } @@ -19,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 "" } @@ -38,4 +43,81 @@ func contains(source []string, containvalue string) bool { } } return false -} \ No newline at end of file +} + + +func (c *APIClient) CallAPI(path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileName string, + fileBytes []byte) (*resty.Response, error) { + + //set debug flag + configuration := NewConfiguration() + resty.SetDebug(configuration.GetDebug()) + + request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) + + switch strings.ToUpper(method) { + case "GET": + response, err := request.Get(path) + return response, err + case "POST": + response, err := request.Post(path) + return response, err + case "PUT": + response, err := request.Put(path) + return response, err + case "PATCH": + response, err := request.Patch(path) + return response, err + case "DELETE": + response, err := request.Delete(path) + return response, err + } + + return nil, fmt.Errorf("invalid method %v", method) +} + +func (c *APIClient) ParameterToString(obj interface{}) string { + if reflect.TypeOf(obj).String() == "[]string" { + return strings.Join(obj.([]string), ",") + } else { + return obj.(string) + } +} + +func prepareRequest(postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { + + request := resty.R() + + request.SetBody(postBody) + + // add header parameter, if any + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + + // add query parameter, if any + if len(queryParams) > 0 { + request.SetQueryParams(queryParams) + } + + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) + } + return request +} 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..2a34a8cf35a --- /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/modules/swagger-codegen/src/main/resources/go/configuration.mustache b/modules/swagger-codegen/src/main/resources/go/configuration.mustache index 154ceb9ffc6..d971bf0373b 100644 --- a/modules/swagger-codegen/src/main/resources/go/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/go/configuration.mustache @@ -7,9 +7,9 @@ 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"` - Debug bool `json:"debug,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"` Timeout int `json:"timeout,omitempty"` @@ -19,17 +19,17 @@ 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 { return &Configuration{ BasePath: "{{basePath}}", UserName: "", - Debug: false, + 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,10 +42,18 @@ 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){ + 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/README.md b/samples/client/petstore/go/go-petstore/README.md index 5890d48282a..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-17T16:17:52.285+08:00 +- Build date: 2016-04-23T17:00:49.475-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) @@ -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 9806ccdf38d..d4b53512c68 100644 --- a/samples/client/petstore/go/go-petstore/api_client.go +++ b/samples/client/petstore/go/go-petstore/api_client.go @@ -2,13 +2,18 @@ package swagger import ( "strings" + "github.com/go-resty/resty" + "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 "" } @@ -19,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 "" } @@ -38,4 +43,81 @@ func contains(source []string, containvalue string) bool { } } return false -} \ No newline at end of file +} + + +func (c *APIClient) CallAPI(path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileName string, + fileBytes []byte) (*resty.Response, error) { + + //set debug flag + configuration := NewConfiguration() + resty.SetDebug(configuration.GetDebug()) + + request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) + + switch strings.ToUpper(method) { + case "GET": + response, err := request.Get(path) + return response, err + case "POST": + response, err := request.Post(path) + return response, err + case "PUT": + response, err := request.Put(path) + return response, err + case "PATCH": + response, err := request.Patch(path) + return response, err + case "DELETE": + response, err := request.Delete(path) + return response, err + } + + return nil, fmt.Errorf("invalid method %v", method) +} + +func (c *APIClient) ParameterToString(obj interface{}) string { + if reflect.TypeOf(obj).String() == "[]string" { + return strings.Join(obj.([]string), ",") + } else { + return obj.(string) + } +} + +func prepareRequest(postBody interface{}, + headerParams map[string]string, + queryParams map[string]string, + formParams map[string]string, + fileName string, + fileBytes []byte) *resty.Request { + + request := resty.R() + + request.SetBody(postBody) + + // add header parameter, if any + if len(headerParams) > 0 { + request.SetHeaders(headerParams) + } + + // add query parameter, if any + if len(queryParams) > 0 { + request.SetQueryParams(queryParams) + } + + // add form parameter, if any + if len(formParams) > 0 { + request.SetFormData(formParams) + } + + if len(fileBytes) > 0 && fileName != "" { + _, fileNm := filepath.Split(fileName) + request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) + } + return request +} diff --git a/samples/client/petstore/go/go-petstore/api_response.go b/samples/client/petstore/go/go-petstore/api_response.go index abb7971189d..2a34a8cf35a 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"` +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/configuration.go b/samples/client/petstore/go/go-petstore/configuration.go index e8a00bccaf5..2a1b4096399 100644 --- a/samples/client/petstore/go/go-petstore/configuration.go +++ b/samples/client/petstore/go/go-petstore/configuration.go @@ -7,9 +7,9 @@ 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"` - Debug bool `json:"debug,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"` Timeout int `json:"timeout,omitempty"` @@ -19,17 +19,17 @@ 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 { 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), + APIKey: make(map[string]string), + APIKeyPrefix: make(map[string]string), UserAgent: "Swagger-Codegen/1.0.0/go", } } @@ -42,10 +42,18 @@ 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){ + 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/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) + + diff --git a/samples/client/petstore/go/go-petstore/docs/PetApi.md b/samples/client/petstore/go/go-petstore/docs/PetApi.md index 5dad1949b04..e96bdc1a15e 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 @@ -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,13 +238,13 @@ Name | Type | Description | Notes ### Return type -[**ApiResponse**](ApiResponse.md) +[**ModelApiResponse**](ApiResponse.md) ### Authorization [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/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"` +} diff --git a/samples/client/petstore/go/go-petstore/pet_api.go b/samples/client/petstore/go/go-petstore/pet_api.go index 461df7449f3..423e8a795a7 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" - "github.com/dghubble/sling" "os" + "io/ioutil" ) type PetApi struct { @@ -35,89 +35,70 @@ 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) { - // 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) +func (a PetApi) AddPet (body Pet) (APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/pet" - // 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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "application/json", - "application/xml", - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Deletes a pet @@ -126,88 +107,69 @@ func (a PetApi) AddPet (body Pet) (error) { * @param apiKey * @return void */ -func (a PetApi) DeletePet (petId int64, apiKey string) (error) { - // 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) +func (a PetApi) DeletePet (petId int64, apiKey string) (APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Delete" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // 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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - // header params "api_key" - _sling = _sling.Set("api_key", apiKey) - - - - - // 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(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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + // 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 { + } + //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 + + + + 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 } /** * Finds Pets by status @@ -215,89 +177,69 @@ 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) { - // 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) +func (a PetApi) FindPetsByStatus (status []string) ([]Pet, APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/findByStatus" - // create path and map variables - path := "/v2/pet/findByStatus" + // 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") + } - _sling = _sling.Path(path) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - - type QueryParams struct { - Status []string `url:"status,omitempty"` -} - _sling = _sling.QueryStruct(&QueryParams{ Status: status }) + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + // 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 Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Finds Pets by tags @@ -305,89 +247,69 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { * @param tags Tags to filter by * @return []Pet */ -func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { - // 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) +func (a PetApi) FindPetsByTags (tags []string) ([]Pet, APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/findByTags" - // create path and map variables - path := "/v2/pet/findByTags" + // 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") + } - _sling = _sling.Path(path) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - - type QueryParams struct { - Tags []string `url:"tags,omitempty"` -} - _sling = _sling.QueryStruct(&QueryParams{ Tags: tags }) + // authentication (petstore_auth) required + + // oauth required + if a.Configuration.AccessToken != ""{ + headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken + } - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + // 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 Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Find pet by ID @@ -395,85 +317,68 @@ 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) { - // 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) +func (a PetApi) GetPetById (petId int64) (Pet, APIResponse, error) { - // authentication (api_key) required - - // set key with prefix in header - _sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")) - + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // create path and map variables - path := "/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), *NewAPIResponseWithError("400 - Bad Request"), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById") + } - _sling = _sling.Path(path) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - + // authentication (api_key) required + + // set key with prefix in header + headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Update an existing pet @@ -481,89 +386,70 @@ 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) { - // 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) +func (a PetApi) UpdatePet (body Pet) (APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Put" + // create path and map variables + path := a.Configuration.BasePath + "/pet" - // 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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "application/json", - "application/xml", - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Updates a pet in the store with form data @@ -573,92 +459,70 @@ 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) { - // 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) +func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/pet/{petId}" + path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1) - // 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]) - } - - - // 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 != "" { - _sling = _sling.Set("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 != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - - type FormParams struct { - Name string `url:"name,omitempty"` - Status string `url:"status,omitempty"` - } - _sling = _sling.BodyForm(&FormParams{ Name: name,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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * uploads an image @@ -666,91 +530,73 @@ 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) { - // 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) +func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ModelApiResponse, APIResponse, error) { - // authentication (petstore_auth) required - - // oauth required - if a.Configuration.AccessToken != ""{ - _sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken) - } + 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) - // 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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - "multipart/form-data", - } - //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 { - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - - type FormParams struct { - AdditionalMetadata string `url:"additionalMetadata,omitempty"` - File *os.File `url:"file,omitempty"` - } - _sling = _sling.BodyForm(&FormParams{ AdditionalMetadata: additionalMetadata,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 := _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)) - } - } + // 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 *successPayload, err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + // 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 { + "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 + fbs, _ := ioutil.ReadAll(file) + fileBytes = fbs + fileName = file.Name() + + var successPayload = new(ModelApiResponse) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + + + if err != nil { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err + } + + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + 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 2fa59c1efd1..a8b48f63b39 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 { @@ -34,159 +33,123 @@ 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) { - // 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) +func (a StoreApi) DeleteOrder (orderId string) (APIResponse, error) { - - // create path and map variables - path := "/v2/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + 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) - _sling = _sling.Path(path) - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(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 != "" { - _sling = _sling.Set("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 != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - - - - - // 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(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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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 + } + + + + 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 } /** * 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) { - _sling := sling.New().Get(a.Configuration.BasePath) +func (a StoreApi) GetInventory () (map[string]int32, APIResponse, error) { - // authentication (api_key) required - - // set key with prefix in header - _sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")) - + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/store/inventory" - // create path and map variables - path := "/v2/store/inventory" - _sling = _sling.Path(path) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - + // authentication (api_key) required + + // set key with prefix in header + headerParams["api_key"] = a.Configuration.GetAPIKeyWithPrefix("api_key") + - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Find purchase order by ID @@ -194,80 +157,63 @@ 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) { - // 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) +func (a StoreApi) GetOrderById (orderId int64) (Order, APIResponse, error) { - - // create path and map variables - path := "/v2/store/order/{orderId}" - path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1) + 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) - _sling = _sling.Path(path) + // 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") + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Place an order for a pet @@ -275,79 +221,62 @@ 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) { - // 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) +func (a StoreApi) PlaceOrder (body Order) (Order, APIResponse, error) { - - // create path and map variables - path := "/v2/store/order" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 *successPayload, err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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 + + var successPayload = new(Order) + httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) + + + if err != nil { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err + } + + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + 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 b6639d9e65f..228c8d3f9bd 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 { @@ -34,81 +33,62 @@ func NewUserApiWithBasePath(basePath string) *UserApi{ * @param body Created user object * @return void */ -func (a UserApi) CreateUser (body User) (error) { - // 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) +func (a UserApi) CreateUser (body User) (APIResponse, error) { - - // create path and map variables - path := "/v2/user" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/user" - _sling = _sling.Path(path) - - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(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 != "" { - _sling = _sling.Set("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 != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -116,81 +96,62 @@ func (a UserApi) CreateUser (body User) (error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { - // 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) +func (a UserApi) CreateUsersWithArrayInput (body []User) (APIResponse, error) { - - // create path and map variables - path := "/v2/user/createWithArray" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Creates list of users with given input array @@ -198,81 +159,62 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { * @param body List of user object * @return void */ -func (a UserApi) CreateUsersWithListInput (body []User) (error) { - // 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) +func (a UserApi) CreateUsersWithListInput (body []User) (APIResponse, error) { - - // create path and map variables - path := "/v2/user/createWithList" + var httpMethod = "Post" + // create path and map variables + path := a.Configuration.BasePath + "/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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Delete user @@ -280,80 +222,61 @@ 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) { - // 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) +func (a UserApi) DeleteUser (username string) (APIResponse, error) { - - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + var httpMethod = "Delete" + // create path and map variables + path := a.Configuration.BasePath + "/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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - - - - - // 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(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)) - } - } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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 + } + + + + 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 } /** * Get user by user name @@ -361,80 +284,63 @@ 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) { - // 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) +func (a UserApi) GetUserByName (username string) (User, APIResponse, error) { - - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/user/{username}" + path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) - _sling = _sling.Path(path) + // 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") + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) - } - + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // to determine the Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Logs user into the system @@ -443,163 +349,124 @@ 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) { - // 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") - } - _sling := sling.New().Get(a.Configuration.BasePath) +func (a UserApi) LoginUser (username string, password string) (string, APIResponse, error) { - - // create path and map variables - path := "/v2/user/login" + var httpMethod = "Get" + // create path and map variables + path := a.Configuration.BasePath + "/user/login" - _sling = _sling.Path(path) + // 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") + } + // 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") + } - // add default headers if any - for key := range a.Configuration.DefaultHeader { - _sling = _sling.Set(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 }) + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //set Content-Type header - localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - _sling = _sling.Set("Content-Type", localVarHttpContentType) - } + + // 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 Accept header - localVarHttpHeaderAccepts := []string { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("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, fileName, fileBytes) - // 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(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 { + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } - return *successPayload, err + err = json.Unmarshal(httpResponse.Body(), &successPayload) + + return *successPayload, *NewAPIResponse(httpResponse.RawResponse), err } /** * Logs out current logged in user session * * @return void */ -func (a UserApi) LogoutUser () (error) { - _sling := sling.New().Get(a.Configuration.BasePath) +func (a UserApi) LogoutUser () (APIResponse, error) { - - // 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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } + 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{} + var fileName string + var fileBytes []byte + + // add default headers if any + for key := range a.Configuration.DefaultHeader { + headerParams[key] = a.Configuration.DefaultHeader[key] + } + - // 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(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)) - } - } + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), err + } + + return *NewAPIResponse(httpResponse.RawResponse), err } /** * Updated user @@ -608,84 +475,65 @@ func (a UserApi) LogoutUser () (error) { * @param body Updated user object * @return void */ -func (a UserApi) UpdateUser (username string, body User) (error) { - // 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") - } - _sling := sling.New().Put(a.Configuration.BasePath) +func (a UserApi) UpdateUser (username string, body User) (APIResponse, error) { - - // create path and map variables - path := "/v2/user/{username}" - path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1) + var httpMethod = "Put" + // create path and map variables + path := a.Configuration.BasePath + "/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]) - } - - - // to determine the Content-Type header - localVarHttpContentTypes := []string { - } - //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 { - "application/xml", - "application/json", - } - //set Accept header - localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - _sling = _sling.Set("Accept", localVarHttpHeaderAccept) - } - -// body params - _sling = _sling.BodyJSON(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 := _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)) - } - } + // 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") + } + // 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 err + headerParams := make(map[string]string) + queryParams := make(map[string]string) + formParams := make(map[string]string) + var postBody interface{} + var fileName string + var fileBytes []byte + + + // 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, fileName, fileBytes) + + + if err != nil { + return *NewAPIResponse(httpResponse.RawResponse), 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 8ac7dc1a77a..5b18e3a7675 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) { @@ -11,19 +12,36 @@ 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) + apiResponse, err := s.AddPet(newPet) if err != nil { t.Errorf("Error while adding pet") t.Log(err) } + 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) + } } func TestGetPetById(t *testing.T) { assert := assert.New(t) s := sw.NewPetApi() - resp, err := s.GetPetById(12830) + resp, apiResponse, err := s.GetPetById(12830) if err != nil { t.Errorf("Error while getting pet by id") t.Log(err) @@ -34,14 +52,83 @@ func TestGetPetById(t *testing.T) { //t.Log(resp) } + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } +} + +func TestGetPetByIdWithInvalidID(t *testing.T) { + s := sw.NewPetApi() + resp, apiResponse, err := 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) + } + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } } func TestUpdatePetWithForm(t *testing.T) { s := sw.NewPetApi() - err := s.UpdatePetWithForm(12830, "golang", "available") + apiResponse, err := s.UpdatePetWithForm(12830, "golang", "available") if err != nil { t.Errorf("Error while updating pet by id") t.Log(err) + t.Log(apiResponse) + } + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } +} + +func TestFindPetsByStatus(t *testing.T) { + s := sw.NewPetApi() + resp, apiResponse, err := 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") + } + + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } + } +} + +func TestUploadFile(t *testing.T) { + s := sw.NewPetApi() + file, _ := os.Open("../python/testfiles/foo.png") + + _, apiResponse, err := s.UploadFile(12830, "golang", file) + + if err != nil { + t.Errorf("Error while uploading file") + t.Log(err) + } + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) + } +} + +func TestDeletePet(t *testing.T) { + s := sw.NewPetApi() + apiResponse, err := s.DeletePet(12830, "") + + if err != nil { + t.Errorf("Error while deleting pet by id") + t.Log(err) + } + if apiResponse.Response.StatusCode != 200 { + t.Log(apiResponse.Response) } } diff --git a/samples/client/petstore/go/test.go b/samples/client/petstore/go/test.go index f73d4e338ca..6a50c9bbc8e 100644 --- a/samples/client/petstore/go/test.go +++ b/samples/client/petstore/go/test.go @@ -22,7 +22,9 @@ 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) + err2, apiResponse2 := s.DeletePet(12830, "") + fmt.Println("DeletePet: ", err2, apiResponse2) }