mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-06 08:50:52 +00:00
Merge branch 'master' of https://github.com/swagger-api/swagger-codegen into issue1949
This commit is contained in:
commit
20a81ca66a
@ -26,6 +26,6 @@ fi
|
|||||||
|
|
||||||
# if you've executed sbt assembly previously it will use that instead.
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l go -o samples/client/petstore/go"
|
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go -o samples/client/petstore/go"
|
||||||
|
|
||||||
java $JAVA_OPTS -jar $executable $ags
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package swagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type InlineResponse200 struct {
|
|
||||||
Tags []Tag `json:"tags,omitempty"`
|
|
||||||
Id int64 `json:"id,omitempty"`
|
|
||||||
Category Object `json:"category,omitempty"`
|
|
||||||
Status string `json:"status,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
PhotoUrls []string `json:"photoUrls,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/dghubble/sling"
|
"github.com/dghubble/sling"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PetApi struct {
|
type PetApi struct {
|
||||||
@ -37,67 +36,7 @@ func (a PetApi) AddPet (body Pet) (error) {
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet"
|
path := "/v2/pets"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
|
|
||||||
*
|
|
||||||
* @param body Pet object in the form of byte array
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
//func (a PetApi) AddPetUsingByteArray (body string) (error) {
|
|
||||||
func (a PetApi) AddPetUsingByteArray (body string) (error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/pet?testing_byte_array=true"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -148,17 +87,17 @@ func (a PetApi) AddPetUsingByteArray (body string) (error) {
|
|||||||
/**
|
/**
|
||||||
* Deletes a pet
|
* Deletes a pet
|
||||||
*
|
*
|
||||||
* @param petId Pet id to delete
|
|
||||||
* @param apiKey
|
* @param apiKey
|
||||||
|
* @param petId Pet id to delete
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
//func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
//func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
|
||||||
func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
|
||||||
|
|
||||||
_sling := sling.New().Delete(a.basePath)
|
_sling := sling.New().Delete(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pets/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -209,8 +148,8 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Finds Pets by status
|
* Finds Pets by status
|
||||||
* Multiple status values can be provided with comma separated strings
|
* Multiple status values can be provided with comma seperated strings
|
||||||
* @param status Status values that need to be considered for query
|
* @param status Status values that need to be considered for filter
|
||||||
* @return []Pet
|
* @return []Pet
|
||||||
*/
|
*/
|
||||||
//func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
//func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
||||||
@ -219,7 +158,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/findByStatus"
|
path := "/v2/pets/findByStatus"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -282,7 +221,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/findByTags"
|
path := "/v2/pets/findByTags"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -345,7 +284,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pets/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -392,124 +331,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
|||||||
|
|
||||||
return *successPayload, err
|
return *successPayload, err
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
|
||||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
|
||||||
* @param petId ID of pet that needs to be fetched
|
|
||||||
* @return InlineResponse200
|
|
||||||
*/
|
|
||||||
//func (a PetApi) GetPetByIdInObject (petId int64) (InlineResponse200, error) {
|
|
||||||
func (a PetApi) GetPetByIdInObject (petId int64) (InlineResponse200, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/pet/{petId}?response=inline_arbitrary_object"
|
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(InlineResponse200)
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
|
||||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
|
||||||
* @param petId ID of pet that needs to be fetched
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
//func (a PetApi) PetPetIdtestingByteArraytrueGet (petId int64) (string, error) {
|
|
||||||
func (a PetApi) PetPetIdtestingByteArraytrueGet (petId int64) (string, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/pet/{petId}?testing_byte_array=true"
|
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(string)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Update an existing pet
|
* Update an existing pet
|
||||||
*
|
*
|
||||||
@ -522,7 +343,7 @@ func (a PetApi) UpdatePet (body Pet) (error) {
|
|||||||
_sling := sling.New().Put(a.basePath)
|
_sling := sling.New().Put(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet"
|
path := "/v2/pets"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -584,7 +405,7 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pets/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -604,72 +425,6 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* uploads an image
|
|
||||||
*
|
|
||||||
* @param petId ID of pet to update
|
|
||||||
* @param additionalMetadata Additional data to pass to server
|
|
||||||
* @param file file to upload
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
//func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (error) {
|
|
||||||
func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Post(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/pet/{petId}/uploadImage"
|
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
type FormParams struct {
|
|
||||||
additionalMetadata string `url:"additionalMetadata,omitempty"`
|
|
||||||
file *os.File `url:"file,omitempty"`
|
|
||||||
}
|
|
||||||
_sling = _sling.BodyForm(&FormParams{ additionalMetadata: additionalMetadata,file: file })
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
// 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
|
// 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.
|
// response (error) models, which needs to be implemented at some point.
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package swagger
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type SpecialModelName struct {
|
|
||||||
$Special[propertyName] int64 `json:"$special[property.name],omitempty"`
|
|
||||||
|
|
||||||
}
|
|
@ -36,7 +36,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
|
|||||||
_sling := sling.New().Delete(a.basePath)
|
_sling := sling.New().Delete(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order/{orderId}"
|
path := "/v2/stores/order/{orderId}"
|
||||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -83,183 +83,6 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Finds orders by status
|
|
||||||
* A single status value can be provided as a string
|
|
||||||
* @param status Status value that needs to be considered for query
|
|
||||||
* @return []Order
|
|
||||||
*/
|
|
||||||
//func (a StoreApi) FindOrdersByStatus (status string) ([]Order, error) {
|
|
||||||
func (a StoreApi) FindOrdersByStatus (status string) ([]Order, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/store/findByStatus"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
type QueryParams struct {
|
|
||||||
status string `url:"status,omitempty"`
|
|
||||||
|
|
||||||
}
|
|
||||||
_sling = _sling.QueryStruct(&QueryParams{ status: status })
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, 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) {
|
|
||||||
func (a StoreApi) GetInventory () (map[string]int32, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/store/inventory"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(map[string]int32)
|
|
||||||
|
|
||||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
|
||||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
|
||||||
// response (error) models, which needs to be implemented at some point.
|
|
||||||
var failurePayload map[string]interface{}
|
|
||||||
|
|
||||||
httpResponse, err := _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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
|
||||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
|
||||||
* @return Object
|
|
||||||
*/
|
|
||||||
//func (a StoreApi) GetInventoryInObject () (Object, error) {
|
|
||||||
func (a StoreApi) GetInventoryInObject () (Object, error) {
|
|
||||||
|
|
||||||
_sling := sling.New().Get(a.basePath)
|
|
||||||
|
|
||||||
// create path and map variables
|
|
||||||
path := "/v2/store/inventory?response=arbitrary_object"
|
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
|
||||||
|
|
||||||
// accept header
|
|
||||||
accepts := []string { "application/json", "application/xml" }
|
|
||||||
for key := range accepts {
|
|
||||||
_sling = _sling.Set("Accept", accepts[key])
|
|
||||||
break // only use the first Accept
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var successPayload = new(Object)
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *successPayload, err
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Find purchase order by ID
|
* Find purchase order by ID
|
||||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
@ -272,7 +95,7 @@ func (a StoreApi) GetOrderById (orderId string) (Order, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order/{orderId}"
|
path := "/v2/stores/order/{orderId}"
|
||||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -331,7 +154,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order"
|
path := "/v2/stores/order"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func (a UserApi) CreateUser (body User) (error) {
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user"
|
path := "/v2/users"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/createWithArray"
|
path := "/v2/users/createWithArray"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
|
|||||||
_sling := sling.New().Post(a.basePath)
|
_sling := sling.New().Post(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/createWithList"
|
path := "/v2/users/createWithList"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ func (a UserApi) DeleteUser (username string) (error) {
|
|||||||
_sling := sling.New().Delete(a.basePath)
|
_sling := sling.New().Delete(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/users/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -275,7 +275,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/users/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
@ -335,7 +335,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/login"
|
path := "/v2/users/login"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -398,7 +398,7 @@ func (a UserApi) LogoutUser () (error) {
|
|||||||
_sling := sling.New().Get(a.basePath)
|
_sling := sling.New().Get(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/logout"
|
path := "/v2/users/logout"
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
|
||||||
@ -457,7 +457,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
|
|||||||
_sling := sling.New().Put(a.basePath)
|
_sling := sling.New().Put(a.basePath)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/users/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||||
|
|
||||||
_sling = _sling.Path(path)
|
_sling = _sling.Path(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user