forked from loafle/openapi-generator-original
updated api_client.go to ensure there is value before setting the request
This commit is contained in:
parent
36219a00e9
commit
af19a70f72
@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *ApiClient) CallApi(path string, method string,
|
func (c *ApiClient) CallApi(path string, method string,
|
||||||
postBody interface{},
|
postBody interface{},
|
||||||
headerParams map[string]string,
|
headerParams map[string]string,
|
||||||
queryParams map[string]string,
|
queryParams map[string]string,
|
||||||
formParams map[string]string,
|
formParams map[string]string,
|
||||||
fileParams map[string]string) (*resty.Response, error) {
|
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":
|
case "GET":
|
||||||
response, err := request.Get(path)
|
response, err := request.Get(path)
|
||||||
return response, err
|
return response, err
|
||||||
@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string,
|
|||||||
return nil, errors.New("Invalid method " + method)
|
return nil, errors.New("Invalid method " + method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareRequest(verb string, postBody interface{},
|
func prepareRequest(postBody interface{},
|
||||||
headerParams map[string]string,
|
headerParams map[string]string,
|
||||||
queryParams map[string]string,
|
queryParams map[string]string,
|
||||||
formParams map[string]string,
|
formParams map[string]string,
|
||||||
@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{},
|
|||||||
request.SetBody(postBody)
|
request.SetBody(postBody)
|
||||||
|
|
||||||
// add header parameter, if any
|
// add header parameter, if any
|
||||||
request.SetHeaders(headerParams)
|
if len(headerParams) > 0 {
|
||||||
|
request.SetHeaders(headerParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add query parameter, if any
|
// add query parameter, if any
|
||||||
request.SetQueryParams(queryParams)
|
if len(queryParams) > 0 {
|
||||||
|
request.SetQueryParams(queryParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add form parameter, if any
|
// add form parameter, if any
|
||||||
request.SetFormData(formParams)
|
if len(fileParams) > 0 {
|
||||||
|
request.SetFormData(formParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add file parameter, if any
|
// add file parameter, if any
|
||||||
if verb != "GET"{
|
if len(fileParams) > 0 {
|
||||||
request.SetFiles(fileParams)
|
request.SetFiles(fileParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,16 +42,17 @@ func contains(source []string, containvalue string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *ApiClient) CallApi(path string, method string,
|
func (c *ApiClient) CallApi(path string, method string,
|
||||||
postBody interface{},
|
postBody interface{},
|
||||||
headerParams map[string]string,
|
headerParams map[string]string,
|
||||||
queryParams map[string]string,
|
queryParams map[string]string,
|
||||||
formParams map[string]string,
|
formParams map[string]string,
|
||||||
fileParams map[string]string) (*resty.Response, error) {
|
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":
|
case "GET":
|
||||||
response, err := request.Get(path)
|
response, err := request.Get(path)
|
||||||
return response, err
|
return response, err
|
||||||
@ -72,7 +73,7 @@ func (c *ApiClient) CallApi(path string, method string,
|
|||||||
return nil, errors.New("Invalid method " + method)
|
return nil, errors.New("Invalid method " + method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareRequest(verb string, postBody interface{},
|
func prepareRequest(postBody interface{},
|
||||||
headerParams map[string]string,
|
headerParams map[string]string,
|
||||||
queryParams map[string]string,
|
queryParams map[string]string,
|
||||||
formParams map[string]string,
|
formParams map[string]string,
|
||||||
@ -83,16 +84,22 @@ func prepareRequest(verb string, postBody interface{},
|
|||||||
request.SetBody(postBody)
|
request.SetBody(postBody)
|
||||||
|
|
||||||
// add header parameter, if any
|
// add header parameter, if any
|
||||||
request.SetHeaders(headerParams)
|
if len(headerParams) > 0 {
|
||||||
|
request.SetHeaders(headerParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add query parameter, if any
|
// add query parameter, if any
|
||||||
request.SetQueryParams(queryParams)
|
if len(queryParams) > 0 {
|
||||||
|
request.SetQueryParams(queryParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add form parameter, if any
|
// add form parameter, if any
|
||||||
request.SetFormData(formParams)
|
if len(fileParams) > 0 {
|
||||||
|
request.SetFormData(formParams)
|
||||||
|
}
|
||||||
|
|
||||||
// add file parameter, if any
|
// add file parameter, if any
|
||||||
if verb != "GET"{
|
if len(fileParams) > 0 {
|
||||||
request.SetFiles(fileParams)
|
request.SetFiles(fileParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ func (a PetApi) AddPet (body Pet) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"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)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +147,6 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -219,7 +217,6 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -290,7 +287,6 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -360,7 +356,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -432,7 +427,6 @@ func (a PetApi) UpdatePet (body Pet) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -507,7 +501,6 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -581,7 +574,6 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/json",
|
"application/json",
|
||||||
|
@ -67,7 +67,6 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -129,7 +128,6 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/json",
|
"application/json",
|
||||||
@ -193,7 +191,6 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -257,7 +254,6 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
|
@ -66,7 +66,6 @@ func (a UserApi) CreateUser (body User) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -131,7 +130,6 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -196,7 +194,6 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -262,7 +259,6 @@ func (a UserApi) DeleteUser (username string) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -325,7 +321,6 @@ func (a UserApi) GetUserByName (username string) (User, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -396,7 +391,6 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -455,7 +449,6 @@ func (a UserApi) LogoutUser () (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
@ -523,7 +516,6 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
|
|||||||
if localVarHttpContentType != "" {
|
if localVarHttpContentType != "" {
|
||||||
headerParams["Content-Type"] = localVarHttpContentType
|
headerParams["Content-Type"] = localVarHttpContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
// to determine the Accept header
|
// to determine the Accept header
|
||||||
localVarHttpHeaderAccepts := []string {
|
localVarHttpHeaderAccepts := []string {
|
||||||
"application/xml",
|
"application/xml",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user