updated api_client.go to ensure there is value before setting the request

This commit is contained in:
Guo Huang 2016-04-18 17:09:47 -07:00
parent 36219a00e9
commit af19a70f72
5 changed files with 33 additions and 39 deletions

View File

@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool {
return false
}
func (c *ApiClient) CallApi(path string, method string,
postBody interface{},
headerParams map[string]string,
queryParams map[string]string,
formParams map[string]string,
fileParams map[string]string) (*resty.Response, error) {
verb := strings.ToUpper(method)
request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams)
switch verb {
request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams)
switch strings.ToUpper(method) {
case "GET":
response, err := request.Get(path)
return response, err
@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string,
return nil, errors.New("Invalid method " + method)
}
func prepareRequest(verb string, postBody interface{},
func prepareRequest(postBody interface{},
headerParams map[string]string,
queryParams map[string]string,
formParams map[string]string,
@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{},
request.SetBody(postBody)
// add header parameter, if any
if len(headerParams) > 0 {
request.SetHeaders(headerParams)
}
// add query parameter, if any
if len(queryParams) > 0 {
request.SetQueryParams(queryParams)
}
// add form parameter, if any
if len(fileParams) > 0 {
request.SetFormData(formParams)
}
// add file parameter, if any
if verb != "GET"{
if len(fileParams) > 0 {
request.SetFiles(fileParams)
}

View File

@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool {
return false
}
func (c *ApiClient) CallApi(path string, method string,
postBody interface{},
headerParams map[string]string,
queryParams map[string]string,
formParams map[string]string,
fileParams map[string]string) (*resty.Response, error) {
verb := strings.ToUpper(method)
request := prepareRequest(verb, postBody, headerParams, queryParams, formParams, fileParams)
switch verb {
request := prepareRequest(postBody, headerParams, queryParams, formParams, fileParams)
switch strings.ToUpper(method) {
case "GET":
response, err := request.Get(path)
return response, err
@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string,
return nil, errors.New("Invalid method " + method)
}
func prepareRequest(verb string, postBody interface{},
func prepareRequest(postBody interface{},
headerParams map[string]string,
queryParams map[string]string,
formParams map[string]string,
@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{},
request.SetBody(postBody)
// add header parameter, if any
if len(headerParams) > 0 {
request.SetHeaders(headerParams)
}
// add query parameter, if any
if len(queryParams) > 0 {
request.SetQueryParams(queryParams)
}
// add form parameter, if any
if len(fileParams) > 0 {
request.SetFormData(formParams)
}
// add file parameter, if any
if verb != "GET"{
if len(fileParams) > 0 {
request.SetFiles(fileParams)
}

View File

@ -75,7 +75,6 @@ func (a PetApi) AddPet (body Pet) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -95,7 +94,7 @@ func (a PetApi) AddPet (body Pet) (error) {
httpResponse, err := a.Configuration.ApiClient.CallApi(path, httpMethod, postBody, headerParams, queryParams, formParams, fileParams)
if err != nil && httpResponse.StatusCode() != 0{
if err != nil && httpResponse.StatusCode() != 200{
return err
}
@ -148,7 +147,6 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -219,7 +217,6 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -290,7 +287,6 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -360,7 +356,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -432,7 +427,6 @@ func (a PetApi) UpdatePet (body Pet) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -507,7 +501,6 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -581,7 +574,6 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/json",

View File

@ -67,7 +67,6 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -129,7 +128,6 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/json",
@ -193,7 +191,6 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -257,7 +254,6 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",

View File

@ -66,7 +66,6 @@ func (a UserApi) CreateUser (body User) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -131,7 +130,6 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -196,7 +194,6 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -262,7 +259,6 @@ func (a UserApi) DeleteUser (username string) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -325,7 +321,6 @@ func (a UserApi) GetUserByName (username string) (User, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -396,7 +391,6 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -455,7 +449,6 @@ func (a UserApi) LogoutUser () (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",
@ -523,7 +516,6 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string {
"application/xml",