updated api.mustache to call the api client http request

This commit is contained in:
Guo Huang 2016-04-17 23:45:23 -07:00
parent 87f9ff189a
commit 8b896a2353
13 changed files with 400 additions and 931 deletions

View File

@ -39,7 +39,7 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{
*/
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
var httpMethod = {{httpMethod}}
var httpMethod = "{{httpMethod}}"
// create path and map variables
path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
@ -54,30 +54,32 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
{{/required}}
{{/allParams}}
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
{{#authMethods}}// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
// set key with prefix in header
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}"))
headerParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")
{{/isKeyInHeader}}{{#isKeyInQuery}}
// set key with prefix in querystring
{{#hasKeyParamName}} type KeyQueryParams struct {
{{keyParamName}} string `url:"{{keyParamName}},omitempty"`
}
_sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") })
{{#hasKeyParamName}}
queryParams["{{keyParamName}}"] = a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")
{{/hasKeyParamName}}
{{/isKeyInQuery}}{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if a.Configuration.Username != "" || a.Configuration.Password != ""{
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
headerParams["Authorization"] = "Basic " + a.Configuration.GetBasicAuthEncodedString()
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
{{/isOAuth}}
{{/authMethods}}
@ -85,15 +87,14 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
{{#hasQueryParams}} type QueryParams struct {
{{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
{{#hasQueryParams}}
{{#queryParams}}
queryParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}}
{{/queryParams}}
{{/hasQueryParams}}
// to determine the Content-Type header
localVarHttpContentTypes := []string {
@ -104,7 +105,7 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -116,16 +117,15 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
headerParams["{{baseName}}"] = {{paramName}}
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{#hasFormParams}}
{{#formParams}}
headerParams["{{vendorExtensions.x-exportParamName}}"] = {{paramName}}
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#hasBodyParam}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
@ -137,7 +137,8 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)

View File

@ -1,169 +0,0 @@
package {{packageName}}
{{#operations}}
import (
"strings"
"fmt"
"encoding/json"
"errors"
{{#imports}} "{{import}}"
{{/imports}}
)
type {{classname}} struct {
Configuration Configuration
}
func New{{classname}}() *{{classname}}{
configuration := NewConfiguration()
return &{{classname}} {
Configuration: *configuration,
}
}
func New{{classname}}WithBasePath(basePath string) *{{classname}}{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &{{classname}} {
Configuration: *configuration,
}
}
{{#operation}}
/**
* {{summary}}
* {{notes}}
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
<<<<<<< HEAD
var httpMethod = {{httpMethod}}
// create path and map variables
path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
{{/pathParams}}
=======
{{#allParams}}
{{#required}}
// verify the required parameter '{{paramName}}' is set
if &{{paramName}} == nil {
return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
}
{{/required}}
{{/allParams}}
>>>>>>> c375f2fed5138125228c6e881df7acf3a8ada17d
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
{{#authMethods}}// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
// set key with prefix in header
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}"))
{{/isKeyInHeader}}{{#isKeyInQuery}}
// set key with prefix in querystring
{{#hasKeyParamName}} type KeyQueryParams struct {
{{keyParamName}} string `url:"{{keyParamName}},omitempty"`
}
_sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") })
{{/hasKeyParamName}}
{{/isKeyInQuery}}{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if a.Configuration.Username != "" || a.Configuration.Password != ""{
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
}
{{/isOAuth}}
{{/authMethods}}
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
}
{{#hasQueryParams}} type QueryParams struct {
{{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
// to determine the Content-Type header
localVarHttpContentTypes := []string {
{{#consumes}}
"{{mediaType}}",
{{/consumes}}
}
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
{{#produces}}
"{{mediaType}}",
{{/produces}}
}
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#hasBodyParam}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
{{/bodyParams}}{{/hasBodyParam}}
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
if failurePayload != nil {
// If the failurePayload is present, there likely was some kind of non-2xx status
// returned (and a JSON payload error present)
var str []byte
str, err = json.Marshal(failurePayload)
if err == nil { // For safety, check for an error marshalling... probably superfluous
// This will return the JSON error body as a string
err = errors.New(string(str))
}
} else {
// So, there was no network-type error, and nothing in the failure payload,
// but we should still check the status code
if httpResponse == nil {
// This should never happen...
err = errors.New("No HTTP Response received.")
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
}
}
}
return {{#returnType}}*successPayload, {{/returnType}}err
}
{{/operation}}
{{/operations}}

View File

@ -1,160 +0,0 @@
package {{packageName}}
{{#operations}}
import (
"strings"
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
{{#imports}} "{{import}}"
{{/imports}}
)
type {{classname}} struct {
Configuration Configuration
}
func New{{classname}}() *{{classname}}{
configuration := NewConfiguration()
return &{{classname}} {
Configuration: *configuration,
}
}
func New{{classname}}WithBasePath(basePath string) *{{classname}}{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &{{classname}} {
Configuration: *configuration,
}
}
{{#operation}}
/**
* {{summary}}
* {{notes}}
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
{{#authMethods}}// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
// set key with prefix in header
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}"))
{{/isKeyInHeader}}{{#isKeyInQuery}}
// set key with prefix in querystring
{{#hasKeyParamName}} type KeyQueryParams struct {
{{keyParamName}} string `url:"{{keyParamName}},omitempty"`
}
_sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") })
{{/hasKeyParamName}}
{{/isKeyInQuery}}{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if a.Configuration.Username != "" || a.Configuration.Password != ""{
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
}
{{/isOAuth}}
{{/authMethods}}
// create path and map variables
path := "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
{{/pathParams}}
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
}
{{#hasQueryParams}} type QueryParams struct {
{{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
// to determine the Content-Type header
localVarHttpContentTypes := []string {
{{#consumes}}
"{{mediaType}}",
{{/consumes}}
}
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
{{#produces}}
"{{mediaType}}",
{{/produces}}
}
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#hasBodyParam}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
{{/bodyParams}}{{/hasBodyParam}}
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
if failurePayload != nil {
// If the failurePayload is present, there likely was some kind of non-2xx status
// returned (and a JSON payload error present)
var str []byte
str, err = json.Marshal(failurePayload)
if err == nil { // For safety, check for an error marshalling... probably superfluous
// This will return the JSON error body as a string
err = errors.New(string(str))
}
} else {
// So, there was no network-type error, and nothing in the failure payload,
// but we should still check the status code
if httpResponse == nil {
// This should never happen...
err = errors.New("No HTTP Response received.")
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
}
}
}
return {{#returnType}}*successPayload, {{/returnType}}err
}
{{/operation}}
{{/operations}}

View File

@ -1,158 +0,0 @@
package {{packageName}}
{{#operations}}
import (
"strings"
"fmt"
"encoding/json"
"errors"
{{#imports}} "{{import}}"
{{/imports}}
)
type {{classname}} struct {
Configuration Configuration
}
func New{{classname}}() *{{classname}}{
configuration := NewConfiguration()
return &{{classname}} {
Configuration: *configuration,
}
}
func New{{classname}}WithBasePath(basePath string) *{{classname}}{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &{{classname}} {
Configuration: *configuration,
}
}
{{#operation}}
/**
* {{summary}}
* {{notes}}
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
var httpMethod = {{httpMethod}}
// create path and map variables
path := c.Configuration.BasePath + "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
{{/pathParams}}
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
{{#authMethods}}// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
// set key with prefix in header
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}"))
{{/isKeyInHeader}}{{#isKeyInQuery}}
// set key with prefix in querystring
{{#hasKeyParamName}} type KeyQueryParams struct {
{{keyParamName}} string `url:"{{keyParamName}},omitempty"`
}
_sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") })
{{/hasKeyParamName}}
{{/isKeyInQuery}}{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if a.Configuration.Username != "" || a.Configuration.Password != ""{
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
}
{{/isOAuth}}
{{/authMethods}}
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
}
{{#hasQueryParams}} type QueryParams struct {
{{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
// to determine the Content-Type header
localVarHttpContentTypes := []string {
{{#consumes}}
"{{mediaType}}",
{{/consumes}}
}
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
{{#produces}}
"{{mediaType}}",
{{/produces}}
}
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#hasBodyParam}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
{{/bodyParams}}{{/hasBodyParam}}
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
if failurePayload != nil {
// If the failurePayload is present, there likely was some kind of non-2xx status
// returned (and a JSON payload error present)
var str []byte
str, err = json.Marshal(failurePayload)
if err == nil { // For safety, check for an error marshalling... probably superfluous
// This will return the JSON error body as a string
err = errors.New(string(str))
}
} else {
// So, there was no network-type error, and nothing in the failure payload,
// but we should still check the status code
if httpResponse == nil {
// This should never happen...
err = errors.New("No HTTP Response received.")
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
}
}
}
return {{#returnType}}*successPayload, {{/returnType}}err
}
{{/operation}}
{{/operations}}

View File

@ -1,167 +0,0 @@
package {{packageName}}
{{#operations}}
import (
"strings"
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
{{#imports}} "{{import}}"
{{/imports}}
)
type {{classname}} struct {
Configuration Configuration
}
func New{{classname}}() *{{classname}}{
configuration := NewConfiguration()
return &{{classname}} {
Configuration: *configuration,
}
}
func New{{classname}}WithBasePath(basePath string) *{{classname}}{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &{{classname}} {
Configuration: *configuration,
}
}
{{#operation}}
/**
* {{summary}}
* {{notes}}
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
{{#allParams}}
{{#required}}
// verify the required parameter '{{paramName}}' is set
if &{{paramName}} == nil {
return {{#returnType}}*new({{{returnType}}}), {{/returnType}}errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
}
{{/required}}
{{/allParams}}
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
{{#authMethods}}// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
// set key with prefix in header
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}"))
{{/isKeyInHeader}}{{#isKeyInQuery}}
// set key with prefix in querystring
{{#hasKeyParamName}} type KeyQueryParams struct {
{{keyParamName}} string `url:"{{keyParamName}},omitempty"`
}
_sling = _sling.QueryStruct(&KeyQueryParams{ {{keyParamName}}: a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}") })
{{/hasKeyParamName}}
{{/isKeyInQuery}}{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if a.Configuration.Username != "" || a.Configuration.Password != ""{
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
}
{{/isBasic}}
{{#isOAuth}}
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
}
{{/isOAuth}}
{{/authMethods}}
// create path and map variables
path := "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
{{/pathParams}}
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
}
{{#hasQueryParams}} type QueryParams struct {
{{#queryParams}}{{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
// to determine the Content-Type header
localVarHttpContentTypes := []string {
{{#consumes}}
"{{mediaType}}",
{{/consumes}}
}
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
{{#produces}}
"{{mediaType}}",
{{/produces}}
}
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{vendorExtensions.x-exportParamName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{vendorExtensions.x-exportParamName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#hasBodyParam}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
{{/bodyParams}}{{/hasBodyParam}}
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive({{#returnType}}successPayload{{/returnType}}{{^returnType}}nil{{/returnType}}, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
if failurePayload != nil {
// If the failurePayload is present, there likely was some kind of non-2xx status
// returned (and a JSON payload error present)
var str []byte
str, err = json.Marshal(failurePayload)
if err == nil { // For safety, check for an error marshalling... probably superfluous
// This will return the JSON error body as a string
err = errors.New(string(str))
}
} else {
// So, there was no network-type error, and nothing in the failure payload,
// but we should still check the status code
if httpResponse == nil {
// This should never happen...
err = errors.New("No HTTP Response received.")
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
}
}
}
return {{#returnType}}*successPayload, {{/returnType}}err
}
{{/operation}}
{{/operations}}

View File

@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge
- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-04-17T16:17:52.285+08:00
- Build date: 2016-04-17T23:42:10.705-07:00
- Build package: class io.swagger.codegen.languages.GoClientCodegen
## Installation
@ -57,12 +57,6 @@ Class | Method | HTTP request | Description
## Documentation For Authorization
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## petstore_auth
- **Type**: OAuth
@ -72,6 +66,12 @@ Class | Method | HTTP request | Description
- **write:pets**: modify pets in your account
- **read:pets**: read your pets
## api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
## Author

View File

@ -42,7 +42,7 @@ func contains(source []string, containvalue string) bool {
return false
}
func CallApiAsync(path string, method string,
func CallApi(path string, method string,
postBody interface{},
headerParams map[string]string,
queryParams map[string]string,

View File

@ -36,7 +36,7 @@ void (empty response body)
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Accept**: application/xml, application/json
@ -66,7 +66,7 @@ void (empty response body)
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
@ -95,7 +95,7 @@ Name | Type | Description | Notes
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
@ -124,7 +124,7 @@ Name | Type | Description | Notes
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
@ -153,7 +153,7 @@ Name | Type | Description | Notes
[api_key](../README.md#api_key)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
@ -182,7 +182,7 @@ void (empty response body)
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Accept**: application/xml, application/json
@ -213,7 +213,7 @@ void (empty response body)
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: application/x-www-form-urlencoded
- **Accept**: application/xml, application/json
@ -244,7 +244,7 @@ Name | Type | Description | Notes
[petstore_auth](../README.md#petstore_auth)
### HTTP reuqest headers
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: application/json

View File

@ -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

View File

@ -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

View File

@ -5,7 +5,6 @@ import (
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
"os"
)
@ -36,27 +35,33 @@ func NewPetApiWithBasePath(basePath string) *PetApi{
* @return void
*/
func (a PetApi) AddPet (body Pet) (error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet"
// verify the required parameter 'body' is set
if &body == nil {
return errors.New("Missing required parameter 'body' when calling PetApi->AddPet")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -68,7 +73,7 @@ func (a PetApi) AddPet (body Pet) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -79,7 +84,7 @@ func (a PetApi) AddPet (body Pet) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -92,7 +97,8 @@ func (a PetApi) AddPet (body Pet) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -127,28 +133,34 @@ func (a PetApi) AddPet (body Pet) (error) {
* @return void
*/
func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
var httpMethod = "Delete"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
// verify the required parameter 'petId' is set
if &petId == nil {
return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet")
}
_sling := sling.New().Delete(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -158,7 +170,7 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -169,10 +181,10 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// header params "api_key"
_sling = _sling.Set("api_key", apiKey)
headerParams["api_key"] = apiKey
@ -182,7 +194,8 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -216,33 +229,36 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
* @return []Pet
*/
func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/findByStatus"
// verify the required parameter 'status' is set
if &status == nil {
return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet/findByStatus"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
type QueryParams struct {
Status []string `url:"status,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ Status: status })
queryParams["Status"] = status
// to determine the Content-Type header
localVarHttpContentTypes := []string {
@ -250,7 +266,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -261,7 +277,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -272,7 +288,8 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -306,33 +323,36 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
* @return []Pet
*/
func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/findByTags"
// verify the required parameter 'tags' is set
if &tags == nil {
return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet/findByTags"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
type QueryParams struct {
Tags []string `url:"tags,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ Tags: tags })
queryParams["Tags"] = tags
// to determine the Content-Type header
localVarHttpContentTypes := []string {
@ -340,7 +360,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -351,7 +371,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -362,7 +382,8 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -396,27 +417,33 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
* @return Pet
*/
func (a PetApi) GetPetById (petId int64) (Pet, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
// verify the required parameter 'petId' is set
if &petId == nil {
return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (api_key) required
// set key with prefix in header
_sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key"))
headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key")
// create path and map variables
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -426,7 +453,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -437,7 +464,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -448,7 +475,8 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -482,27 +510,33 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
* @return void
*/
func (a PetApi) UpdatePet (body Pet) (error) {
var httpMethod = "Put"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet"
// verify the required parameter 'body' is set
if &body == nil {
return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet")
}
_sling := sling.New().Put(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -514,7 +548,7 @@ func (a PetApi) UpdatePet (body Pet) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -525,7 +559,7 @@ func (a PetApi) UpdatePet (body Pet) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -538,7 +572,8 @@ func (a PetApi) UpdatePet (body Pet) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -574,28 +609,34 @@ func (a PetApi) UpdatePet (body Pet) (error) {
* @return void
*/
func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
// verify the required parameter 'petId' is set
if &petId == nil {
return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -606,7 +647,7 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -617,14 +658,11 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
type FormParams struct {
Name string `url:"name,omitempty"`
Status string `url:"status,omitempty"`
}
_sling = _sling.BodyForm(&FormParams{ Name: name,Status: status })
headerParams["Name"] = name
headerParams["Status"] = status
@ -633,7 +671,8 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -669,28 +708,34 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
* @return ApiResponse
*/
func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/pet/{petId}/uploadImage"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
// verify the required parameter 'petId' is set
if &petId == nil {
return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (petstore_auth) required
// oauth required
if a.Configuration.AccessToken != ""{
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
headerParams["Authorization"] = "Bearer " + a.Configuration.AccessToken
}
// create path and map variables
path := "/v2/pet/{petId}/uploadImage"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -701,7 +746,7 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -711,14 +756,11 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
type FormParams struct {
AdditionalMetadata string `url:"additionalMetadata,omitempty"`
File *os.File `url:"file,omitempty"`
}
_sling = _sling.BodyForm(&FormParams{ AdditionalMetadata: additionalMetadata,File: file })
headerParams["AdditionalMetadata"] = additionalMetadata
headerParams["File"] = file
var successPayload = new(ApiResponse)
@ -727,7 +769,8 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)

View File

@ -5,7 +5,6 @@ import (
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
)
type StoreApi struct {
@ -35,22 +34,28 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{
* @return void
*/
func (a StoreApi) DeleteOrder (orderId string) (error) {
var httpMethod = "Delete"
// create path and map variables
path := c.Configuration.BasePath + "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
// verify the required parameter 'orderId' is set
if &orderId == nil {
return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder")
}
_sling := sling.New().Delete(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -60,7 +65,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -71,7 +76,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -82,7 +87,8 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -115,22 +121,28 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
* @return map[string]int32
*/
func (a StoreApi) GetInventory () (map[string]int32, error) {
_sling := sling.New().Get(a.Configuration.BasePath)
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/store/inventory"
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// authentication (api_key) required
// set key with prefix in header
_sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key"))
headerParams["api_key"] = a.Configuration.GetApiKeyWithPrefix("api_key")
// create path and map variables
path := "/v2/store/inventory"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -140,7 +152,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -150,7 +162,7 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -161,7 +173,8 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -195,22 +208,28 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
* @return Order
*/
func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
// verify the required parameter 'orderId' is set
if &orderId == nil {
return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -220,7 +239,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -231,7 +250,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -242,7 +261,8 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -276,21 +296,27 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
* @return Order
*/
func (a StoreApi) PlaceOrder (body Order) (Order, error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/store/order"
// verify the required parameter 'body' is set
if &body == nil {
return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/store/order"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -300,7 +326,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -311,7 +337,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -324,7 +350,8 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)

View File

@ -5,7 +5,6 @@ import (
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
)
type UserApi struct {
@ -35,21 +34,27 @@ func NewUserApiWithBasePath(basePath string) *UserApi{
* @return void
*/
func (a UserApi) CreateUser (body User) (error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user"
// verify the required parameter 'body' is set
if &body == nil {
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -59,7 +64,7 @@ func (a UserApi) CreateUser (body User) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -70,7 +75,7 @@ func (a UserApi) CreateUser (body User) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -83,7 +88,8 @@ func (a UserApi) CreateUser (body User) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -117,21 +123,27 @@ func (a UserApi) CreateUser (body User) (error) {
* @return void
*/
func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/createWithArray"
// verify the required parameter 'body' is set
if &body == nil {
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/createWithArray"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -141,7 +153,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -152,7 +164,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -165,7 +177,8 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -199,21 +212,27 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
* @return void
*/
func (a UserApi) CreateUsersWithListInput (body []User) (error) {
var httpMethod = "Post"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/createWithList"
// verify the required parameter 'body' is set
if &body == nil {
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput")
}
_sling := sling.New().Post(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/createWithList"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -223,7 +242,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -234,7 +253,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -247,7 +266,8 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -281,22 +301,28 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
* @return void
*/
func (a UserApi) DeleteUser (username string) (error) {
var httpMethod = "Delete"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
// verify the required parameter 'username' is set
if &username == nil {
return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser")
}
_sling := sling.New().Delete(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -306,7 +332,7 @@ func (a UserApi) DeleteUser (username string) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -317,7 +343,7 @@ func (a UserApi) DeleteUser (username string) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -328,7 +354,8 @@ func (a UserApi) DeleteUser (username string) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -362,22 +389,28 @@ func (a UserApi) DeleteUser (username string) (error) {
* @return User
*/
func (a UserApi) GetUserByName (username string) (User, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
// verify the required parameter 'username' is set
if &username == nil {
return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -387,7 +420,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -398,7 +431,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -409,7 +442,8 @@ func (a UserApi) GetUserByName (username string) (User, error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -444,6 +478,11 @@ func (a UserApi) GetUserByName (username string) (User, error) {
* @return string
*/
func (a UserApi) LoginUser (username string, password string) (string, error) {
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/login"
// verify the required parameter 'username' is set
if &username == nil {
return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser")
@ -452,24 +491,22 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
if &password == nil {
return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser")
}
_sling := sling.New().Get(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/login"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
type QueryParams struct {
Username string `url:"username,omitempty"`
Password string `url:"password,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ Username: username,Password: password })
queryParams["Username"] = username
queryParams["Password"] = password
// to determine the Content-Type header
localVarHttpContentTypes := []string {
@ -477,7 +514,7 @@ Password string `url:"password,omitempty"`
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -488,7 +525,7 @@ Password string `url:"password,omitempty"`
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -499,7 +536,8 @@ Password string `url:"password,omitempty"`
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(successPayload, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -532,17 +570,23 @@ Password string `url:"password,omitempty"`
* @return void
*/
func (a UserApi) LogoutUser () (error) {
_sling := sling.New().Get(a.Configuration.BasePath)
var httpMethod = "Get"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/logout"
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/logout"
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -552,7 +596,7 @@ func (a UserApi) LogoutUser () (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -563,7 +607,7 @@ func (a UserApi) LogoutUser () (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
@ -574,7 +618,8 @@ func (a UserApi) LogoutUser () (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
@ -609,6 +654,12 @@ func (a UserApi) LogoutUser () (error) {
* @return void
*/
func (a UserApi) UpdateUser (username string, body User) (error) {
var httpMethod = "Put"
// create path and map variables
path := c.Configuration.BasePath + "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
// verify the required parameter 'username' is set
if &username == nil {
return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser")
@ -617,18 +668,18 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
if &body == nil {
return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser")
}
_sling := sling.New().Put(a.Configuration.BasePath)
headerParams := make(map[string]string)
queryParams := make(map[string]string)
formParams := make(map[string]string)
fileParams := make(map[string]string)
formBody := make(interface{})
// create path and map variables
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// add default headers if any
for key := range a.Configuration.DefaultHeader {
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
headerParams[key] = a.Configuration.DefaultHeader[key]
}
@ -638,7 +689,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
//set Content-Type header
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
_sling = _sling.Set("Content-Type", localVarHttpContentType)
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
@ -649,7 +700,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
//set Accept header
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
headerParams["Accept"] = localVarHttpHeaderAccept
}
// body params
@ -662,7 +713,8 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
// response (error) models, which needs to be implemented at some point.
var failurePayload map[string]interface{}
httpResponse, err := _sling.Receive(nil, &failurePayload)
httpResponse, err := a.Configuration.ApiClient.CallApi(path, method, postBody, headerParams, queryParams, formParams, fileParams)
//httpResponse, err := _sling.Receive(nil, &failurePayload)
if err == nil {
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)