forked from loafle/openapi-generator-original
update go test, update pom
This commit is contained in:
parent
8d450a29da
commit
993d121e35
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# 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"
|
||||
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"
|
||||
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/go-petstore"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
13
pom.xml
13
pom.xml
@ -450,6 +450,18 @@
|
||||
<module>samples/client/petstore/ruby</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>go-client</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/client/petstore/go</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>spring-mvc</id>
|
||||
<activation>
|
||||
@ -484,6 +496,7 @@
|
||||
<module>samples/client/petstore/scala</module>
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
<module>samples/client/petstore/ruby</module>
|
||||
<module>samples/client/petstore/go</module>
|
||||
<module>samples/server/petstore/jaxrs</module>
|
||||
<module>samples/server/petstore/jaxrs-resteasy</module>
|
||||
<!--module>samples/client/petstore/objc/SwaggerClientTests</module-->
|
||||
|
@ -1,40 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ApiClient struct {
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string {
|
||||
if len(contentTypes) == 0 {
|
||||
return ""
|
||||
}
|
||||
if contains(contentTypes, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return contentTypes[0] // use the first content type specified in 'consumes'
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderAccept(accepts []string) string {
|
||||
if len(accepts) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if contains(accepts, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return strings.Join(accepts, ",")
|
||||
}
|
||||
|
||||
func contains(source []string, containvalue string) bool {
|
||||
for _, a := range source {
|
||||
if strings.ToLower(a) == strings.ToLower(containvalue) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
type ApiResponse struct {
|
||||
|
||||
Code int32 `json:"code,omitempty"`
|
||||
|
||||
Type_ string `json:"type,omitempty"`
|
||||
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
type Category struct {
|
||||
|
||||
Id int64 `json:"id,omitempty"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
UserName string `json:"userName,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"`
|
||||
ApiKey map[string] string `json:"apiKey,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
DebugFile string `json:"debugFile,omitempty"`
|
||||
OAuthToken string `json:"oAuthToken,omitempty"`
|
||||
Timeout int `json:"timeout,omitempty"`
|
||||
BasePath string `json:"basePath,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Scheme string `json:"scheme,omitempty"`
|
||||
AccessToken string `json:"accessToken,omitempty"`
|
||||
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
|
||||
UserAgent string `json:"userAgent,omitempty"`
|
||||
ApiClient ApiClient `json:"apiClient,omitempty"`
|
||||
}
|
||||
|
||||
func NewConfiguration() *Configuration {
|
||||
return &Configuration{
|
||||
BasePath: "http://petstore.swagger.io/v2",
|
||||
UserName: "",
|
||||
Debug: false,
|
||||
DefaultHeader: make(map[string]string),
|
||||
ApiKey: make(map[string]string),
|
||||
ApiKeyPrefix: make(map[string]string),
|
||||
UserAgent: "Swagger-Codegen/1.0.0/go",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Configuration) GetBasicAuthEncodedString() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(c.UserName + ":" + c.Password))
|
||||
}
|
||||
|
||||
func (c *Configuration) AddDefaultHeader(key string, value string) {
|
||||
c.DefaultHeader[key] = value
|
||||
}
|
||||
|
||||
func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string {
|
||||
if c.ApiKeyPrefix[apiKeyIdentifier] != ""{
|
||||
return c.ApiKeyPrefix[apiKeyIdentifier] + " " + c.ApiKey[apiKeyIdentifier]
|
||||
}
|
||||
|
||||
return c.ApiKey[apiKeyIdentifier]
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
# ApiResponse
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Code** | **int32** | | [optional] [default to null]
|
||||
**Type_** | **string** | | [optional] [default to null]
|
||||
**Message** | **string** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
# Category
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Id** | **int64** | | [optional] [default to null]
|
||||
**Name** | **string** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
# Order
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Id** | **int64** | | [optional] [default to null]
|
||||
**PetId** | **int64** | | [optional] [default to null]
|
||||
**Quantity** | **int32** | | [optional] [default to null]
|
||||
**ShipDate** | [**time.Time**](time.Time.md) | | [optional] [default to null]
|
||||
**Status** | **string** | Order Status | [optional] [default to null]
|
||||
**Complete** | **bool** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
# Pet
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Id** | **int64** | | [optional] [default to null]
|
||||
**Category** | [**Category**](Category.md) | | [optional] [default to null]
|
||||
**Name** | **string** | | [default to null]
|
||||
**PhotoUrls** | **[]string** | | [default to null]
|
||||
**Tags** | [**[]Tag**](Tag.md) | | [optional] [default to null]
|
||||
**Status** | **string** | pet status in the store | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,253 +0,0 @@
|
||||
# \PetApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**AddPet**](PetApi.md#AddPet) | **Post** /pet | Add a new pet to the store
|
||||
[**DeletePet**](PetApi.md#DeletePet) | **Delete** /pet/{petId} | Deletes a pet
|
||||
[**FindPetsByStatus**](PetApi.md#FindPetsByStatus) | **Get** /pet/findByStatus | Finds Pets by status
|
||||
[**FindPetsByTags**](PetApi.md#FindPetsByTags) | **Get** /pet/findByTags | Finds Pets by tags
|
||||
[**GetPetById**](PetApi.md#GetPetById) | **Get** /pet/{petId} | Find pet by ID
|
||||
[**UpdatePet**](PetApi.md#UpdatePet) | **Put** /pet | Update an existing pet
|
||||
[**UpdatePetWithForm**](PetApi.md#UpdatePetWithForm) | **Post** /pet/{petId} | Updates a pet in the store with form data
|
||||
[**UploadFile**](PetApi.md#UploadFile) | **Post** /pet/{petId}/uploadImage | uploads an image
|
||||
|
||||
|
||||
# **AddPet**
|
||||
> AddPet($body)
|
||||
|
||||
Add a new pet to the store
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: application/json, application/xml
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **DeletePet**
|
||||
> DeletePet($petId, $apiKey)
|
||||
|
||||
Deletes a pet
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**petId** | **int64**| Pet id to delete |
|
||||
**apiKey** | **string**| | [optional]
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **FindPetsByStatus**
|
||||
> []Pet FindPetsByStatus($status)
|
||||
|
||||
Finds Pets by status
|
||||
|
||||
Multiple status values can be provided with comma separated strings
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**status** | [**[]string**](string.md)| Status values that need to be considered for filter |
|
||||
|
||||
### Return type
|
||||
|
||||
[**[]Pet**](Pet.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **FindPetsByTags**
|
||||
> []Pet FindPetsByTags($tags)
|
||||
|
||||
Finds Pets by tags
|
||||
|
||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**tags** | [**[]string**](string.md)| Tags to filter by |
|
||||
|
||||
### Return type
|
||||
|
||||
[**[]Pet**](Pet.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **GetPetById**
|
||||
> Pet GetPetById($petId)
|
||||
|
||||
Find pet by ID
|
||||
|
||||
Returns a single pet
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**petId** | **int64**| ID of pet to return |
|
||||
|
||||
### Return type
|
||||
|
||||
[**Pet**](Pet.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **UpdatePet**
|
||||
> UpdatePet($body)
|
||||
|
||||
Update an existing pet
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: application/json, application/xml
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **UpdatePetWithForm**
|
||||
> UpdatePetWithForm($petId, $name, $status)
|
||||
|
||||
Updates a pet in the store with form data
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**petId** | **int64**| ID of pet that needs to be updated |
|
||||
**name** | **string**| Updated name of the pet | [optional]
|
||||
**status** | **string**| Updated status of the pet | [optional]
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: application/x-www-form-urlencoded
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **UploadFile**
|
||||
> ApiResponse UploadFile($petId, $additionalMetadata, $file)
|
||||
|
||||
uploads an image
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**petId** | **int64**| ID of pet to update |
|
||||
**additionalMetadata** | **string**| Additional data to pass to server | [optional]
|
||||
**file** | ***os.File**| file to upload | [optional]
|
||||
|
||||
### Return type
|
||||
|
||||
[**ApiResponse**](ApiResponse.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[petstore_auth](../README.md#petstore_auth)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: multipart/form-data
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
@ -1,125 +0,0 @@
|
||||
# \StoreApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**DeleteOrder**](StoreApi.md#DeleteOrder) | **Delete** /store/order/{orderId} | Delete purchase order by ID
|
||||
[**GetInventory**](StoreApi.md#GetInventory) | **Get** /store/inventory | Returns pet inventories by status
|
||||
[**GetOrderById**](StoreApi.md#GetOrderById) | **Get** /store/order/{orderId} | Find purchase order by ID
|
||||
[**PlaceOrder**](StoreApi.md#PlaceOrder) | **Post** /store/order | Place an order for a pet
|
||||
|
||||
|
||||
# **DeleteOrder**
|
||||
> DeleteOrder($orderId)
|
||||
|
||||
Delete purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**orderId** | **string**| ID of the order that needs to be deleted |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **GetInventory**
|
||||
> map[string]int32 GetInventory()
|
||||
|
||||
Returns pet inventories by status
|
||||
|
||||
Returns a map of status codes to quantities
|
||||
|
||||
|
||||
### Parameters
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
[**map[string]int32**](map.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **GetOrderById**
|
||||
> Order GetOrderById($orderId)
|
||||
|
||||
Find purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**orderId** | **int64**| ID of pet that needs to be fetched |
|
||||
|
||||
### Return type
|
||||
|
||||
[**Order**](Order.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **PlaceOrder**
|
||||
> Order PlaceOrder($body)
|
||||
|
||||
Place an order for a pet
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**Order**](Order.md)| order placed for purchasing the pet |
|
||||
|
||||
### Return type
|
||||
|
||||
[**Order**](Order.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
@ -1,11 +0,0 @@
|
||||
# Tag
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Id** | **int64** | | [optional] [default to null]
|
||||
**Name** | **string** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
# User
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**Id** | **int64** | | [optional] [default to null]
|
||||
**Username** | **string** | | [optional] [default to null]
|
||||
**FirstName** | **string** | | [optional] [default to null]
|
||||
**LastName** | **string** | | [optional] [default to null]
|
||||
**Email** | **string** | | [optional] [default to null]
|
||||
**Password** | **string** | | [optional] [default to null]
|
||||
**Phone** | **string** | | [optional] [default to null]
|
||||
**UserStatus** | **int32** | User Status | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -1,247 +0,0 @@
|
||||
# \UserApi
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**CreateUser**](UserApi.md#CreateUser) | **Post** /user | Create user
|
||||
[**CreateUsersWithArrayInput**](UserApi.md#CreateUsersWithArrayInput) | **Post** /user/createWithArray | Creates list of users with given input array
|
||||
[**CreateUsersWithListInput**](UserApi.md#CreateUsersWithListInput) | **Post** /user/createWithList | Creates list of users with given input array
|
||||
[**DeleteUser**](UserApi.md#DeleteUser) | **Delete** /user/{username} | Delete user
|
||||
[**GetUserByName**](UserApi.md#GetUserByName) | **Get** /user/{username} | Get user by user name
|
||||
[**LoginUser**](UserApi.md#LoginUser) | **Get** /user/login | Logs user into the system
|
||||
[**LogoutUser**](UserApi.md#LogoutUser) | **Get** /user/logout | Logs out current logged in user session
|
||||
[**UpdateUser**](UserApi.md#UpdateUser) | **Put** /user/{username} | Updated user
|
||||
|
||||
|
||||
# **CreateUser**
|
||||
> CreateUser($body)
|
||||
|
||||
Create user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**User**](User.md)| Created user object |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **CreateUsersWithArrayInput**
|
||||
> CreateUsersWithArrayInput($body)
|
||||
|
||||
Creates list of users with given input array
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**[]User**](User.md)| List of user object |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **CreateUsersWithListInput**
|
||||
> CreateUsersWithListInput($body)
|
||||
|
||||
Creates list of users with given input array
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**[]User**](User.md)| List of user object |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **DeleteUser**
|
||||
> DeleteUser($username)
|
||||
|
||||
Delete user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**username** | **string**| The name that needs to be deleted |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **GetUserByName**
|
||||
> User GetUserByName($username)
|
||||
|
||||
Get user by user name
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**username** | **string**| The name that needs to be fetched. Use user1 for testing. |
|
||||
|
||||
### Return type
|
||||
|
||||
[**User**](User.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **LoginUser**
|
||||
> string LoginUser($username, $password)
|
||||
|
||||
Logs user into the system
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**username** | **string**| The user name for login |
|
||||
**password** | **string**| The password for login in clear text |
|
||||
|
||||
### Return type
|
||||
|
||||
**string**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **LogoutUser**
|
||||
> LogoutUser()
|
||||
|
||||
Logs out current logged in user session
|
||||
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **UpdateUser**
|
||||
> UpdateUser($username, $body)
|
||||
|
||||
Updated user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**username** | **string**| name that need to be deleted |
|
||||
**body** | [**User**](User.md)| Updated user object |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP reuqest headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
@ -1,21 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
type Order struct {
|
||||
|
||||
Id int64 `json:"id,omitempty"`
|
||||
|
||||
PetId int64 `json:"petId,omitempty"`
|
||||
|
||||
Quantity int32 `json:"quantity,omitempty"`
|
||||
|
||||
ShipDate time.Time `json:"shipDate,omitempty"`
|
||||
// Order Status
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
Complete bool `json:"complete,omitempty"`
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
type Pet struct {
|
||||
|
||||
Id int64 `json:"id,omitempty"`
|
||||
|
||||
Category Category `json:"category,omitempty"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
PhotoUrls []string `json:"photoUrls,omitempty"`
|
||||
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
// pet status in the store
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
@ -1,756 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/dghubble/sling"
|
||||
"os"
|
||||
)
|
||||
|
||||
type PetApi struct {
|
||||
Configuration Configuration
|
||||
}
|
||||
|
||||
func NewPetApi() *PetApi{
|
||||
configuration := NewConfiguration()
|
||||
return &PetApi {
|
||||
Configuration: *configuration,
|
||||
}
|
||||
}
|
||||
|
||||
func NewPetApiWithBasePath(basePath string) *PetApi{
|
||||
configuration := NewConfiguration()
|
||||
configuration.BasePath = basePath
|
||||
|
||||
return &PetApi {
|
||||
Configuration: *configuration,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
*/
|
||||
func (a PetApi) AddPet (body Pet) (error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling PetApi->AddPet")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
"application/json",
|
||||
"application/xml",
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
* @return void
|
||||
*/
|
||||
func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
||||
// verify the required parameter 'petId' is set
|
||||
if &petId == nil {
|
||||
return errors.New("Missing required parameter 'petId' when calling PetApi->DeletePet")
|
||||
}
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
// header params "api_key"
|
||||
_sling = _sling.Set("api_key", apiKey)
|
||||
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return []Pet
|
||||
*/
|
||||
func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
||||
// verify the required parameter 'status' is set
|
||||
if &status == nil {
|
||||
return *new([]Pet), errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
type QueryParams struct {
|
||||
Status []string `url:"status,omitempty"`
|
||||
}
|
||||
_sling = _sling.QueryStruct(&QueryParams{ Status: status })
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var successPayload = new([]Pet)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _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
|
||||
}
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return []Pet
|
||||
*/
|
||||
func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
|
||||
// verify the required parameter 'tags' is set
|
||||
if &tags == nil {
|
||||
return *new([]Pet), errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
type QueryParams struct {
|
||||
Tags []string `url:"tags,omitempty"`
|
||||
}
|
||||
_sling = _sling.QueryStruct(&QueryParams{ Tags: tags })
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var successPayload = new([]Pet)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _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 pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
* @return Pet
|
||||
*/
|
||||
func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
||||
// verify the required parameter 'petId' is set
|
||||
if &petId == nil {
|
||||
return *new(Pet), errors.New("Missing required parameter 'petId' when calling PetApi->GetPetById")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// set key with prefix in header
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var successPayload = new(Pet)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _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
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return void
|
||||
*/
|
||||
func (a PetApi) UpdatePet (body Pet) (error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling PetApi->UpdatePet")
|
||||
}
|
||||
_sling := sling.New().Put(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
"application/json",
|
||||
"application/xml",
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet
|
||||
* @param status Updated status of the pet
|
||||
* @return void
|
||||
*/
|
||||
func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (error) {
|
||||
// verify the required parameter 'petId' is set
|
||||
if &petId == nil {
|
||||
return errors.New("Missing required parameter 'petId' when calling PetApi->UpdatePetWithForm")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
"application/x-www-form-urlencoded",
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
type FormParams struct {
|
||||
Name string `url:"name,omitempty"`
|
||||
Status string `url:"status,omitempty"`
|
||||
}
|
||||
_sling = _sling.BodyForm(&FormParams{ Name: name,Status: status })
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 ApiResponse
|
||||
*/
|
||||
func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error) {
|
||||
// verify the required parameter 'petId' is set
|
||||
if &petId == nil {
|
||||
return *new(ApiResponse), errors.New("Missing required parameter 'petId' when calling PetApi->UploadFile")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
"multipart/form-data",
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
type FormParams struct {
|
||||
AdditionalMetadata string `url:"additionalMetadata,omitempty"`
|
||||
File *os.File `url:"file,omitempty"`
|
||||
}
|
||||
_sling = _sling.BodyForm(&FormParams{ AdditionalMetadata: additionalMetadata,File: file })
|
||||
|
||||
var successPayload = new(ApiResponse)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *successPayload, err
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package swagger
|
||||
package main
|
||||
|
||||
import (
|
||||
sw "./swagger"
|
||||
sw "./go-petstore"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddPet(t *testing.T) {
|
||||
s := NewPetApi()
|
||||
newPet := (Pet{Id: 12830, Name: "gopher",
|
||||
s := sw.NewPetApi()
|
||||
newPet := (sw.Pet{Id: 12830, Name: "gopher",
|
||||
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
|
||||
|
||||
err := s.AddPet(newPet)
|
||||
@ -20,9 +20,9 @@ func TestAddPet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPetById(t *testing.T) {
|
||||
//assert := assert.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
s := NewPetApi()
|
||||
s := sw.NewPetApi()
|
||||
resp, err := s.GetPetById(12830)
|
||||
if err != nil {
|
||||
t.Errorf("Error while getting pet by id")
|
||||
@ -37,7 +37,7 @@ func TestGetPetById(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdatePetWithForm(t *testing.T) {
|
||||
s := NewPetApi()
|
||||
s := sw.NewPetApi()
|
||||
err := s.UpdatePetWithForm(12830, "golang", "available")
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,353 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/dghubble/sling"
|
||||
)
|
||||
|
||||
type StoreApi struct {
|
||||
Configuration Configuration
|
||||
}
|
||||
|
||||
func NewStoreApi() *StoreApi{
|
||||
configuration := NewConfiguration()
|
||||
return &StoreApi {
|
||||
Configuration: *configuration,
|
||||
}
|
||||
}
|
||||
|
||||
func NewStoreApiWithBasePath(basePath string) *StoreApi{
|
||||
configuration := NewConfiguration()
|
||||
configuration.BasePath = basePath
|
||||
|
||||
return &StoreApi {
|
||||
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
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return void
|
||||
*/
|
||||
func (a StoreApi) DeleteOrder (orderId string) (error) {
|
||||
// verify the required parameter 'orderId' is set
|
||||
if &orderId == nil {
|
||||
return errors.New("Missing required parameter 'orderId' when calling StoreApi->DeleteOrder")
|
||||
}
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return map[string]int32
|
||||
*/
|
||||
func (a StoreApi) GetInventory () (map[string]int32, error) {
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// set key with prefix in header
|
||||
_sling.Set("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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return Order
|
||||
*/
|
||||
func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
|
||||
// verify the required parameter 'orderId' is set
|
||||
if &orderId == nil {
|
||||
return *new(Order), errors.New("Missing required parameter 'orderId' when calling StoreApi->GetOrderById")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var 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
|
||||
}
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return Order
|
||||
*/
|
||||
func (a StoreApi) PlaceOrder (body Order) (Order, error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return *new(Order), errors.New("Missing required parameter 'body' when calling StoreApi->PlaceOrder")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
var successPayload = new(Order)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(successPayload, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *successPayload, err
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
type Tag struct {
|
||||
|
||||
Id int64 `json:"id,omitempty"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
package swagger
|
||||
package main
|
||||
|
||||
import (
|
||||
sw "./go-petstore"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
s := NewPetApi()
|
||||
s := sw.NewPetApi()
|
||||
|
||||
// test POST(body)
|
||||
newPet := (Pet{Id: 12830, Name: "gopher",
|
||||
newPet := (sw.Pet{Id: 12830, Name: "gopher",
|
||||
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
|
||||
|
||||
jsonNewPet, _ := json.Marshal(newPet)
|
||||
|
@ -1,24 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
type User struct {
|
||||
|
||||
Id int64 `json:"id,omitempty"`
|
||||
|
||||
Username string `json:"username,omitempty"`
|
||||
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
|
||||
Email string `json:"email,omitempty"`
|
||||
|
||||
Password string `json:"password,omitempty"`
|
||||
|
||||
Phone string `json:"phone,omitempty"`
|
||||
// User Status
|
||||
UserStatus int32 `json:"userStatus,omitempty"`
|
||||
}
|
@ -1,691 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/dghubble/sling"
|
||||
)
|
||||
|
||||
type UserApi struct {
|
||||
Configuration Configuration
|
||||
}
|
||||
|
||||
func NewUserApi() *UserApi{
|
||||
configuration := NewConfiguration()
|
||||
return &UserApi {
|
||||
Configuration: *configuration,
|
||||
}
|
||||
}
|
||||
|
||||
func NewUserApiWithBasePath(basePath string) *UserApi{
|
||||
configuration := NewConfiguration()
|
||||
configuration.BasePath = basePath
|
||||
|
||||
return &UserApi {
|
||||
Configuration: *configuration,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) CreateUser (body User) (error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUser")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithArrayInput")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) CreateUsersWithListInput (body []User) (error) {
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling UserApi->CreateUsersWithListInput")
|
||||
}
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) DeleteUser (username string) (error) {
|
||||
// verify the required parameter 'username' is set
|
||||
if &username == nil {
|
||||
return errors.New("Missing required parameter 'username' when calling UserApi->DeleteUser")
|
||||
}
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return User
|
||||
*/
|
||||
func (a UserApi) GetUserByName (username string) (User, error) {
|
||||
// verify the required parameter 'username' is set
|
||||
if &username == nil {
|
||||
return *new(User), errors.New("Missing required parameter 'username' when calling UserApi->GetUserByName")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var successPayload = new(User)
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _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
|
||||
}
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return string
|
||||
*/
|
||||
func (a UserApi) LoginUser (username string, password string) (string, error) {
|
||||
// verify the required parameter 'username' is set
|
||||
if &username == nil {
|
||||
return *new(string), errors.New("Missing required parameter 'username' when calling UserApi->LoginUser")
|
||||
}
|
||||
// verify the required parameter 'password' is set
|
||||
if &password == nil {
|
||||
return *new(string), errors.New("Missing required parameter 'password' when calling UserApi->LoginUser")
|
||||
}
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
type QueryParams struct {
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
}
|
||||
_sling = _sling.QueryStruct(&QueryParams{ Username: username,Password: password })
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
var 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
|
||||
}
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) LogoutUser () (error) {
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/logout"
|
||||
|
||||
_sling = _sling.Path(path)
|
||||
|
||||
// add default headers if any
|
||||
for key := range a.Configuration.DefaultHeader {
|
||||
_sling = _sling.Set(key, a.Configuration.DefaultHeader[key])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
}
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return void
|
||||
*/
|
||||
func (a UserApi) UpdateUser (username string, body User) (error) {
|
||||
// verify the required parameter 'username' is set
|
||||
if &username == nil {
|
||||
return errors.New("Missing required parameter 'username' when calling UserApi->UpdateUser")
|
||||
}
|
||||
// verify the required parameter 'body' is set
|
||||
if &body == nil {
|
||||
return errors.New("Missing required parameter 'body' when calling UserApi->UpdateUser")
|
||||
}
|
||||
_sling := sling.New().Put(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// 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])
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string {
|
||||
}
|
||||
//set Content-Type header
|
||||
localVarHttpContentType := a.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
_sling = _sling.Set("Content-Type", localVarHttpContentType)
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string {
|
||||
"application/xml",
|
||||
"application/json",
|
||||
}
|
||||
//set Accept header
|
||||
localVarHttpHeaderAccept := a.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
_sling = _sling.Set("Accept", localVarHttpHeaderAccept)
|
||||
}
|
||||
|
||||
// body params
|
||||
_sling = _sling.BodyJSON(body)
|
||||
|
||||
|
||||
|
||||
// We use this map (below) so that any arbitrary error JSON can be handled.
|
||||
// FIXME: This is in the absence of this Go generator honoring the non-2xx
|
||||
// response (error) models, which needs to be implemented at some point.
|
||||
var failurePayload map[string]interface{}
|
||||
|
||||
httpResponse, err := _sling.Receive(nil, &failurePayload)
|
||||
|
||||
if err == nil {
|
||||
// err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
|
||||
if failurePayload != nil {
|
||||
// If the failurePayload is present, there likely was some kind of non-2xx status
|
||||
// returned (and a JSON payload error present)
|
||||
var str []byte
|
||||
str, err = json.Marshal(failurePayload)
|
||||
if err == nil { // For safety, check for an error marshalling... probably superfluous
|
||||
// This will return the JSON error body as a string
|
||||
err = errors.New(string(str))
|
||||
}
|
||||
} else {
|
||||
// So, there was no network-type error, and nothing in the failure payload,
|
||||
// but we should still check the status code
|
||||
if httpResponse == nil {
|
||||
// This should never happen...
|
||||
err = errors.New("No HTTP Response received.")
|
||||
} else if code := httpResponse.StatusCode; 200 > code || code > 299 {
|
||||
err = errors.New("HTTP Error: " + string(httpResponse.StatusCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user