Merge pull request #2775 from guohuang/tests

fixed array return type return as pointer issue
This commit is contained in:
wing328 2016-05-06 17:07:02 +08:00
commit ce4a976916
5 changed files with 37 additions and 38 deletions

View File

@ -35,9 +35,9 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}} {
* {{notes}}{{/notes}} * {{notes}}{{/notes}}
* *
{{#allParams}} * @param {{paramName}} {{description}} {{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{/allParams}} * @return {{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/ */
func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}*{{{returnType}}}, {{/returnType}}*APIResponse, error) { func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {
var httpMethod = "{{httpMethod}}" var httpMethod = "{{httpMethod}}"
// create path and map variables // create path and map variables
@ -46,7 +46,7 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{
{{#allParams}}{{#required}} {{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set // verify the required parameter '{{paramName}}' is set
if &{{paramName}} == nil { if &{{paramName}} == nil {
return {{#returnType}}new({{{returnType}}}), {{/returnType}}nil, errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}new({{{returnType}}}), {{/returnType}}nil, errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
}{{/required}}{{/allParams}} }{{/required}}{{/allParams}}
headerParams := make(map[string]string) headerParams := make(map[string]string)
@ -113,10 +113,10 @@ func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{
{{#returnType}} var successPayload = new({{returnType}}){{/returnType}} {{#returnType}} var successPayload = new({{returnType}}){{/returnType}}
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil { if err != nil {
return {{#returnType}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err
} }
{{#returnType}} {{#returnType}}
err = json.Unmarshal(httpResponse.Body(), &successPayload){{/returnType}} err = json.Unmarshal(httpResponse.Body(), &successPayload){{/returnType}}
return {{#returnType}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err
} }
{{/operation}}{{/operations}} {{/operation}}{{/operations}}

View File

@ -171,7 +171,7 @@ func (a PetApi) DeletePet(petId int64, apiKey string) (*APIResponse, error) {
* @param status Status values that need to be considered for filter * @param status Status values that need to be considered for filter
* @return []Pet * @return []Pet
*/ */
func (a PetApi) FindPetsByStatus(status []string) (*[]Pet, *APIResponse, error) { func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) {
var httpMethod = "Get" var httpMethod = "Get"
// create path and map variables // create path and map variables
@ -179,7 +179,7 @@ func (a PetApi) FindPetsByStatus(status []string) (*[]Pet, *APIResponse, error)
// verify the required parameter 'status' is set // verify the required parameter 'status' is set
if &status == nil { if &status == nil {
return new([]Pet), nil, errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus") return *new([]Pet), nil, errors.New("Missing required parameter 'status' when calling PetApi->FindPetsByStatus")
} }
headerParams := make(map[string]string) headerParams := make(map[string]string)
@ -224,10 +224,10 @@ func (a PetApi) FindPetsByStatus(status []string) (*[]Pet, *APIResponse, error)
var successPayload = new([]Pet) var successPayload = new([]Pet)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil { if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
} }
err = json.Unmarshal(httpResponse.Body(), &successPayload) err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
} }
/** /**
@ -237,7 +237,7 @@ func (a PetApi) FindPetsByStatus(status []string) (*[]Pet, *APIResponse, error)
* @param tags Tags to filter by * @param tags Tags to filter by
* @return []Pet * @return []Pet
*/ */
func (a PetApi) FindPetsByTags(tags []string) (*[]Pet, *APIResponse, error) { func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) {
var httpMethod = "Get" var httpMethod = "Get"
// create path and map variables // create path and map variables
@ -245,7 +245,7 @@ func (a PetApi) FindPetsByTags(tags []string) (*[]Pet, *APIResponse, error) {
// verify the required parameter 'tags' is set // verify the required parameter 'tags' is set
if &tags == nil { if &tags == nil {
return new([]Pet), nil, errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags") return *new([]Pet), nil, errors.New("Missing required parameter 'tags' when calling PetApi->FindPetsByTags")
} }
headerParams := make(map[string]string) headerParams := make(map[string]string)
@ -290,10 +290,10 @@ func (a PetApi) FindPetsByTags(tags []string) (*[]Pet, *APIResponse, error) {
var successPayload = new([]Pet) var successPayload = new([]Pet)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil { if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
} }
err = json.Unmarshal(httpResponse.Body(), &successPayload) err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
} }
/** /**
@ -301,7 +301,7 @@ func (a PetApi) FindPetsByTags(tags []string) (*[]Pet, *APIResponse, error) {
* Returns a single pet * Returns a single pet
* *
* @param petId ID of pet to return * @param petId ID of pet to return
* @return Pet * @return *Pet
*/ */
func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) { func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) {
@ -501,7 +501,7 @@ func (a PetApi) UpdatePetWithForm(petId int64, name string, status string) (*API
* @param petId ID of pet to update * @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server * @param additionalMetadata Additional data to pass to server
* @param file file to upload * @param file file to upload
* @return ModelApiResponse * @return *ModelApiResponse
*/ */
func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File) (*ModelApiResponse, *APIResponse, error) { func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File) (*ModelApiResponse, *APIResponse, error) {

View File

@ -90,7 +90,7 @@ func (a StoreApi) DeleteOrder(orderId string) (*APIResponse, error) {
* Returns pet inventories by status * Returns pet inventories by status
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
* *
* @return map[string]int32 * @return *map[string]int32
*/ */
func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) { func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) {
@ -147,7 +147,7 @@ func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) {
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
* *
* @param orderId ID of pet that needs to be fetched * @param orderId ID of pet that needs to be fetched
* @return Order * @return *Order
*/ */
func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) { func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) {
@ -206,7 +206,7 @@ func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) {
* *
* *
* @param body order placed for purchasing the pet * @param body order placed for purchasing the pet
* @return Order * @return *Order
*/ */
func (a StoreApi) PlaceOrder(body Order) (*Order, *APIResponse, error) { func (a StoreApi) PlaceOrder(body Order) (*Order, *APIResponse, error) {

View File

@ -274,7 +274,7 @@ func (a UserApi) DeleteUser(username string) (*APIResponse, error) {
* *
* *
* @param username The name that needs to be fetched. Use user1 for testing. * @param username The name that needs to be fetched. Use user1 for testing.
* @return User * @return *User
*/ */
func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) { func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) {
@ -334,7 +334,7 @@ func (a UserApi) GetUserByName(username string) (*User, *APIResponse, error) {
* *
* @param username The user name for login * @param username The user name for login
* @param password The password for login in clear text * @param password The password for login in clear text
* @return string * @return *string
*/ */
func (a UserApi) LoginUser(username string, password string) (*string, *APIResponse, error) { func (a UserApi) LoginUser(username string, password string) (*string, *APIResponse, error) {

View File

@ -18,8 +18,8 @@ func TestAddPet(t *testing.T) {
t.Errorf("Error while adding pet") t.Errorf("Error while adding pet")
t.Log(err) t.Log(err)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
@ -32,8 +32,8 @@ func TestFindPetsByStatusWithMissingParam(t *testing.T) {
t.Errorf("Error while testing TestFindPetsByStatusWithMissingParam") t.Errorf("Error while testing TestFindPetsByStatusWithMissingParam")
t.Log(err) t.Log(err)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse) t.Log(apiResponse)
} }
} }
@ -52,8 +52,8 @@ func TestGetPetById(t *testing.T) {
//t.Log(resp) //t.Log(resp)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
@ -67,8 +67,8 @@ func TestGetPetByIdWithInvalidID(t *testing.T) {
} else { } else {
t.Log(resp) t.Log(resp)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
@ -79,10 +79,10 @@ func TestUpdatePetWithForm(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Error while updating pet by id") t.Errorf("Error while updating pet by id")
t.Log(err) t.Log(err)
t.Log(*apiResponse) t.Log(apiResponse)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
@ -92,10 +92,9 @@ func TestFindPetsByStatus(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Error while getting pet by id") t.Errorf("Error while getting pet by id")
t.Log(err) t.Log(err)
t.Log(*apiResponse) t.Log(apiResponse)
} else { } else {
t.Log(*apiResponse) if len(resp) == 0 {
if len(*resp) == 0 {
t.Errorf("Error no pets returned") t.Errorf("Error no pets returned")
} else { } else {
assert := assert.New(t) assert := assert.New(t)
@ -104,8 +103,8 @@ func TestFindPetsByStatus(t *testing.T) {
} }
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
} }
@ -121,7 +120,7 @@ func TestUploadFile(t *testing.T) {
t.Log(err) t.Log(err)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(apiResponse.Response) t.Log(apiResponse.Response)
} }
} }
@ -134,7 +133,7 @@ func TestDeletePet(t *testing.T) {
t.Errorf("Error while deleting pet by id") t.Errorf("Error while deleting pet by id")
t.Log(err) t.Log(err)
} }
if *apiResponse.Response.StatusCode != 200 { if apiResponse.Response.StatusCode != 200 {
t.Log(apiResponse.Response) t.Log(apiResponse.Response)
} }
} }