updated sample files

This commit is contained in:
Guo Huang
2016-04-07 22:27:33 -07:00
parent 20a81ca66a
commit 9cae125b2c
3 changed files with 124 additions and 27 deletions

View File

@@ -1,29 +1,36 @@
package swagger
import (
"strings"
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
)
type PetApi struct {
basePath string
Configuration Configuration
}
func NewPetApi() *PetApi{
configuration := NewConfiguration()
return &PetApi {
basePath: "http://petstore.swagger.io/v2",
Configuration: *configuration,
}
}
func NewPetApiWithBasePath(basePath string) *PetApi{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &PetApi {
basePath: basePath,
Configuration: *configuration,
}
}
/**
* Add a new pet to the store
*
@@ -33,13 +40,15 @@ func NewPetApiWithBasePath(basePath string) *PetApi{
//func (a PetApi) AddPet (body Pet) (error) {
func (a PetApi) AddPet (body Pet) (error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -47,6 +56,7 @@ func (a PetApi) AddPet (body Pet) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -84,6 +94,7 @@ func (a PetApi) AddPet (body Pet) (error) {
return err
}
/**
* Deletes a pet
*
@@ -94,14 +105,16 @@ func (a PetApi) AddPet (body Pet) (error) {
//func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
_sling := sling.New().Delete(a.basePath)
_sling := sling.New().Delete(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets/{petId}"
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 {
@@ -114,6 +127,7 @@ func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
@@ -146,6 +160,7 @@ func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
return err
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
@@ -155,11 +170,12 @@ func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
//func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets/findByStatus"
_sling = _sling.Path(path)
type QueryParams struct {
@@ -167,6 +183,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
}
_sling = _sling.QueryStruct(&QueryParams{ status: status })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -175,6 +192,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
}
var successPayload = new([]Pet)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -209,6 +227,7 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
return *successPayload, err
}
/**
* Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
@@ -218,11 +237,12 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
//func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets/findByTags"
_sling = _sling.Path(path)
type QueryParams struct {
@@ -230,6 +250,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
}
_sling = _sling.QueryStruct(&QueryParams{ tags: tags })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -238,6 +259,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
}
var successPayload = new([]Pet)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -272,6 +294,7 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
return *successPayload, err
}
/**
* Find pet by ID
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
@@ -281,14 +304,16 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
//func (a PetApi) GetPetById (petId int64) (Pet, error) {
func (a PetApi) GetPetById (petId int64) (Pet, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets/{petId}"
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 {
@@ -297,6 +322,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
}
var successPayload = new(Pet)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -331,6 +357,7 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
return *successPayload, err
}
/**
* Update an existing pet
*
@@ -340,13 +367,15 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
//func (a PetApi) UpdatePet (body Pet) (error) {
func (a PetApi) UpdatePet (body Pet) (error) {
_sling := sling.New().Put(a.basePath)
_sling := sling.New().Put(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -354,6 +383,7 @@ func (a PetApi) UpdatePet (body Pet) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -391,6 +421,7 @@ func (a PetApi) UpdatePet (body Pet) (error) {
return err
}
/**
* Updates a pet in the store with form data
*
@@ -402,14 +433,16 @@ func (a PetApi) UpdatePet (body Pet) (error) {
//func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (error) {
func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/pets/{petId}"
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 {
@@ -420,11 +453,13 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
type FormParams struct {
name string `url:"name,omitempty"`
status string `url:"status,omitempty"`
}
_sling = _sling.BodyForm(&FormParams{ name: name,status: status })
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
@@ -457,3 +492,5 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
return err
}

View File

@@ -1,29 +1,36 @@
package swagger
import (
"strings"
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
)
type StoreApi struct {
basePath string
Configuration Configuration
}
func NewStoreApi() *StoreApi{
configuration := NewConfiguration()
return &StoreApi {
basePath: "http://petstore.swagger.io/v2",
Configuration: *configuration,
}
}
func NewStoreApiWithBasePath(basePath string) *StoreApi{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &StoreApi {
basePath: basePath,
Configuration: *configuration,
}
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
@@ -33,14 +40,16 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{
//func (a StoreApi) DeleteOrder (orderId string) (error) {
func (a StoreApi) DeleteOrder (orderId string) (error) {
_sling := sling.New().Delete(a.basePath)
_sling := sling.New().Delete(a.Configuration.BasePath)
// create path and map variables
path := "/v2/stores/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -51,6 +60,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
@@ -83,6 +93,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
return err
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
@@ -92,14 +103,16 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
//func (a StoreApi) GetOrderById (orderId string) (Order, error) {
func (a StoreApi) GetOrderById (orderId string) (Order, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/stores/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -108,6 +121,7 @@ func (a StoreApi) GetOrderById (orderId string) (Order, error) {
}
var successPayload = new(Order)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -142,6 +156,7 @@ func (a StoreApi) GetOrderById (orderId string) (Order, error) {
return *successPayload, err
}
/**
* Place an order for a pet
*
@@ -151,13 +166,15 @@ func (a StoreApi) GetOrderById (orderId string) (Order, error) {
//func (a StoreApi) PlaceOrder (body Order) (Order, error) {
func (a StoreApi) PlaceOrder (body Order) (Order, error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/stores/order"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -165,6 +182,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -202,3 +220,5 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
return *successPayload, err
}

View File

@@ -1,29 +1,36 @@
package swagger
import (
"strings"
"fmt"
"encoding/json"
"errors"
"github.com/dghubble/sling"
)
type UserApi struct {
basePath string
Configuration Configuration
}
func NewUserApi() *UserApi{
configuration := NewConfiguration()
return &UserApi {
basePath: "http://petstore.swagger.io/v2",
Configuration: *configuration,
}
}
func NewUserApiWithBasePath(basePath string) *UserApi{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &UserApi {
basePath: basePath,
Configuration: *configuration,
}
}
/**
* Create user
* This can only be done by the logged in user.
@@ -33,13 +40,15 @@ func NewUserApiWithBasePath(basePath string) *UserApi{
//func (a UserApi) CreateUser (body User) (error) {
func (a UserApi) CreateUser (body User) (error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -47,6 +56,7 @@ func (a UserApi) CreateUser (body User) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -84,6 +94,7 @@ func (a UserApi) CreateUser (body User) (error) {
return err
}
/**
* Creates list of users with given input array
*
@@ -93,13 +104,15 @@ func (a UserApi) CreateUser (body User) (error) {
//func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/createWithArray"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -107,6 +120,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -144,6 +158,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
return err
}
/**
* Creates list of users with given input array
*
@@ -153,13 +168,15 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
//func (a UserApi) CreateUsersWithListInput (body []User) (error) {
func (a UserApi) CreateUsersWithListInput (body []User) (error) {
_sling := sling.New().Post(a.basePath)
_sling := sling.New().Post(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/createWithList"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -167,6 +184,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -204,6 +222,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
return err
}
/**
* Delete user
* This can only be done by the logged in user.
@@ -213,14 +232,16 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
//func (a UserApi) DeleteUser (username string) (error) {
func (a UserApi) DeleteUser (username string) (error) {
_sling := sling.New().Delete(a.basePath)
_sling := sling.New().Delete(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -231,6 +252,7 @@ func (a UserApi) DeleteUser (username string) (error) {
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
@@ -263,6 +285,7 @@ func (a UserApi) DeleteUser (username string) (error) {
return err
}
/**
* Get user by user name
*
@@ -272,14 +295,16 @@ func (a UserApi) DeleteUser (username string) (error) {
//func (a UserApi) GetUserByName (username string) (User, error) {
func (a UserApi) GetUserByName (username string) (User, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -288,6 +313,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
}
var successPayload = new(User)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -322,6 +348,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
return *successPayload, err
}
/**
* Logs user into the system
*
@@ -332,11 +359,12 @@ func (a UserApi) GetUserByName (username string) (User, error) {
//func (a UserApi) LoginUser (username string, password string) (string, error) {
func (a UserApi) LoginUser (username string, password string) (string, error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/login"
_sling = _sling.Path(path)
type QueryParams struct {
@@ -345,6 +373,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
}
_sling = _sling.QueryStruct(&QueryParams{ username: username,password: password })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -353,6 +382,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
}
var successPayload = new(string)
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -387,6 +417,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
return *successPayload, err
}
/**
* Logs out current logged in user session
*
@@ -395,13 +426,15 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
//func (a UserApi) LogoutUser () (error) {
func (a UserApi) LogoutUser () (error) {
_sling := sling.New().Get(a.basePath)
_sling := sling.New().Get(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/logout"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -412,6 +445,7 @@ func (a UserApi) LogoutUser () (error) {
// We use this map (below) so that any arbitrary error JSON can be handled.
// FIXME: This is in the absence of this Go generator honoring the non-2xx
// response (error) models, which needs to be implemented at some point.
@@ -444,6 +478,7 @@ func (a UserApi) LogoutUser () (error) {
return err
}
/**
* Updated user
* This can only be done by the logged in user.
@@ -454,14 +489,16 @@ func (a UserApi) LogoutUser () (error) {
//func (a UserApi) UpdateUser (username string, body User) (error) {
func (a UserApi) UpdateUser (username string, body User) (error) {
_sling := sling.New().Put(a.basePath)
_sling := sling.New().Put(a.Configuration.BasePath)
// create path and map variables
path := "/v2/users/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
@@ -469,6 +506,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
break // only use the first Accept
}
// body params
_sling = _sling.BodyJSON(body)
@@ -506,3 +544,5 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
return err
}