[R][httr2] fix HTTP header (#13066)

* add test for header parameters

* fix header parameter in r httr2 client
This commit is contained in:
William Cheng 2022-08-03 15:05:39 +08:00 committed by GitHub
parent e0fca517cc
commit aa1f6276f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 563 additions and 12 deletions

View File

@ -185,14 +185,10 @@ ApiClient <- R6::R6Class(
## add headers and default headers ## add headers and default headers
if (!is.null(header_params) && length(header_params) != 0) { if (!is.null(header_params) && length(header_params) != 0) {
for (http_header in names(header_params)) { req <- req %>% req_headers(!!!header_params)
req <- req %>% req_headers(http_header = header_params[http_header])
}
} }
if (!is.null(self$default_headers) && length(self$default_headers) != 0) { if (!is.null(self$default_headers) && length(self$default_headers) != 0) {
for (http_header in names(header_params)) { req <- req %>% req_headers(!!!self$default_headers)
req <- req %>% req_headers(http_header = self$default_headers[http_header])
}
} }
# set HTTP accept header # set HTTP accept header

View File

@ -242,6 +242,38 @@ paths:
- petstore_auth: - petstore_auth:
- 'write:pets' - 'write:pets'
- 'read:pets' - 'read:pets'
'/pet_header_test':
get:
tags:
- pet
summary: Header test
description: Header test
operationId: test_header
x-streaming: true
parameters:
- name: header_test_int
in: header
description: header test int
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
'/pet/{petId}?streaming': '/pet/{petId}?streaming':
get: get:
tags: tags:

View File

@ -190,14 +190,10 @@ ApiClient <- R6::R6Class(
## add headers and default headers ## add headers and default headers
if (!is.null(header_params) && length(header_params) != 0) { if (!is.null(header_params) && length(header_params) != 0) {
for (http_header in names(header_params)) { req <- req %>% req_headers(!!!header_params)
req <- req %>% req_headers(http_header = header_params[http_header])
}
} }
if (!is.null(self$default_headers) && length(self$default_headers) != 0) { if (!is.null(self$default_headers) && length(self$default_headers) != 0) {
for (http_header in names(header_params)) { req <- req %>% req_headers(!!!self$default_headers)
req <- req %>% req_headers(http_header = self$default_headers[http_header])
}
} }
# set HTTP accept header # set HTTP accept header

View File

@ -171,6 +171,38 @@
#' } #' }
#' } #' }
#' #'
#' \strong{ test_header } \emph{ Header test }
#' Header test
#'
#' \itemize{
#' \item \emph{ @param } header_test_int integer
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ update_pet } \emph{ Update an existing pet } #' \strong{ update_pet } \emph{ Update an existing pet }
#' #'
#' #'
@ -424,6 +456,34 @@
#' } #' }
#' #'
#' #'
#' #################### test_header ####################
#'
#' library(petstore)
#' var.header_test_int <- 56 # integer | header test int
#'
#' #Header test
#' api.instance <- PetApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#'
#'result <- tryCatch(
#' api.instance$test_header(var.header_test_int),
#' ApiException = function(ex) ex
#' )
#' # In case of error, print the error object
#' if(!is.null(result$ApiException)) {
#' cat(result$ApiException$toString())
#' } else {
#' # deserialized response object
#' response.object <- result$content
#' # response headers
#' response.headers <- result$response$headers
#' # response status code
#' response.status.code <- result$response$status_code
#' }
#'
#'
#' #################### update_pet #################### #' #################### update_pet ####################
#' #'
#' library(petstore) #' library(petstore)
@ -1197,6 +1257,127 @@ PetApi <- R6::R6Class(
ApiException = ApiException$new(http_response = local_var_resp)) ApiException = ApiException$new(http_response = local_var_resp))
} }
}, },
#' Header test
#'
#' @description
#' Header test
#'
#' @param header_test_int header test int
#' @param stream_callback (optional) callback function to process the data stream
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return Pet
#' @export
test_header = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
local_var_response <- self$test_header_with_http_info(header_test_int, stream_callback = stream_callback, data_file = data_file, ...)
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
return(invisible(NULL))
}
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
local_var_response$content
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
local_var_response
} else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
local_var_response
} else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
local_var_response
}
},
#' Header test
#'
#' @description
#' Header test
#'
#' @param header_test_int header test int
#' @param stream_callback (optional) callback function to process the data stream
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return API response (Pet) with additional information such as HTTP status code, headers
#' @export
test_header_with_http_info = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
if (missing(`header_test_int`)) {
rlang::abort(message = "Missing required parameter `header_test_int`.",
.subclass = "ApiException",
ApiException = ApiException$new(status = 0,
reason = "Missing required parameter `header_test_int`."))
}
header_params["header_test_int"] <- `header_test_int`
local_var_body <- NULL
local_var_url_path <- "/pet_header_test"
# API key authentication
if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
}
# The Accept request HTTP header
local_var_accepts = list("application/xml", "application/json")
# The Content-Type representation header
local_var_content_types = list()
local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
method = "GET",
query_params = query_params,
header_params = header_params,
accepts = local_var_accepts,
content_types = local_var_content_types,
body = local_var_body,
stream_callback = stream_callback,
...)
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
return(invisible(NULL))
}
if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
# save response in a file
if (!is.null(data_file)) {
write(local_var_resp$response, data_file)
}
deserialized_resp_obj <- tryCatch(
self$api_client$deserialize(local_var_resp$response, "Pet", loadNamespace("petstore")),
error = function(e) {
rlang::abort(message = "Failed to deserialize response",
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
}
)
local_var_resp$content <- deserialized_resp_obj
local_var_resp
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.")
}
rlang::abort(message = local_var_error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api client exception encountered."
}
rlang::abort(message = local_var_error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
} else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api server exception encountered."
}
rlang::abort(message = error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
}
},
#' Update an existing pet #' Update an existing pet
#' #'
#' @description #' @description

View File

@ -68,6 +68,7 @@ Class | Method | HTTP request | Description
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags *PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID *PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**get_pet_by_id_streaming**](docs/PetApi.md#get_pet_by_id_streaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming) *PetApi* | [**get_pet_by_id_streaming**](docs/PetApi.md#get_pet_by_id_streaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming)
*PetApi* | [**test_header**](docs/PetApi.md#test_header) | **GET** /pet_header_test | Header test
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet *PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image

View File

@ -10,6 +10,7 @@ Method | HTTP request | Description
[**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags [**find_pets_by_tags**](PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
[**get_pet_by_id**](PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID [**get_pet_by_id**](PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
[**get_pet_by_id_streaming**](PetApi.md#get_pet_by_id_streaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming) [**get_pet_by_id_streaming**](PetApi.md#get_pet_by_id_streaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming)
[**test_header**](PetApi.md#test_header) | **GET** /pet_header_test | Header test
[**update_pet**](PetApi.md#update_pet) | **PUT** /pet | Update an existing pet [**update_pet**](PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data [**update_pet_with_form**](PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
[**upload_file**](PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image [**upload_file**](PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
@ -395,6 +396,72 @@ Name | Type | Description | Notes
| **400** | Invalid ID supplied | - | | **400** | Invalid ID supplied | - |
| **404** | Pet not found | - | | **404** | Pet not found | - |
# **test_header**
> Pet test_header(header_test_int)
Header test
Header test
### Example
```R
library(petstore)
var_header_test_int <- 56 # integer | header test int
#Header test
api_instance <- PetApi$new()
# Configure API key authorization: api_key
api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
result <- tryCatch(
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
# api_instance$test_header(var_header_test_int, data_file = "result.txt"),
# this endpoint supports data streaming via a callback function using the optional `stream_callback` parameter, e.g.
# api_instance$test_header(var_header_test_int, stream_callback = function(x){ print(length(x)) }),
api_instance$test_header(var_header_test_int),
ApiException = function(ex) ex
)
# In case of error, print the error object
if (!is.null(result$ApiException)) {
dput(result$ApiException)
# error object
dput(result$ApiException$error_object)
} else {
# deserialized response object
dput(result$content)
# response headers
dput(result$response$headers)
# response status code
dput(result$response$status_code)
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**header_test_int** | **integer**| header test int |
### Return type
[**Pet**](Pet.md)
### Authorization
[api_key](../README.md#api_key)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |
| **400** | Invalid ID supplied | - |
| **404** | Pet not found | - |
# **update_pet** # **update_pet**
> Pet update_pet(pet) > Pet update_pet(pet)

View File

@ -101,6 +101,21 @@ test_that("get_pet_by_id_streaming", {
) )
}) })
test_that("Test header parameters", {
# test exception
result <- tryCatch(pet_api$test_header(45345),
ApiException = function(ex) ex
)
expect_true(!is.null(result))
expect_true(!is.null(result$ApiException))
expect_equal(result$ApiException$status, 404)
# test error object `ApiResponse`
#expect_equal(result$ApiException$error_object$toString(), "{\"code\":404,\"type\":\"unknown\",\"message\":\"null for uri: http://pet\n x[1]: store.swagger.io/v2/pet_header_test\"}")
expect_equal(result$ApiException$error_object$code, 404)
})
test_that("Test GetPetById exception", { test_that("Test GetPetById exception", {
# test exception # test exception
result <- tryCatch(pet_api$get_pet_by_id(98765), # petId not exist result <- tryCatch(pet_api$get_pet_by_id(98765), # petId not exist

View File

@ -171,6 +171,38 @@
#' } #' }
#' } #' }
#' #'
#' \strong{ TestHeader } \emph{ Header test }
#' Header test
#'
#' \itemize{
#' \item \emph{ @param } header_test_int integer
#' \item \emph{ @returnType } \link{Pet} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdatePet } \emph{ Update an existing pet } #' \strong{ UpdatePet } \emph{ Update an existing pet }
#' #'
#' #'
@ -424,6 +456,34 @@
#' } #' }
#' #'
#' #'
#' #################### TestHeader ####################
#'
#' library(petstore)
#' var.header_test_int <- 56 # integer | header test int
#'
#' #Header test
#' api.instance <- PetApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#'
#'result <- tryCatch(
#' api.instance$TestHeader(var.header_test_int),
#' ApiException = function(ex) ex
#' )
#' # In case of error, print the error object
#' if(!is.null(result$ApiException)) {
#' cat(result$ApiException$toString())
#' } else {
#' # deserialized response object
#' response.object <- result$content
#' # response headers
#' response.headers <- result$response$headers
#' # response status code
#' response.status.code <- result$response$status_code
#' }
#'
#'
#' #################### UpdatePet #################### #' #################### UpdatePet ####################
#' #'
#' library(petstore) #' library(petstore)
@ -1197,6 +1257,127 @@ PetApi <- R6::R6Class(
ApiException = ApiException$new(http_response = local_var_resp)) ApiException = ApiException$new(http_response = local_var_resp))
} }
}, },
#' Header test
#'
#' @description
#' Header test
#'
#' @param header_test_int header test int
#' @param stream_callback (optional) callback function to process the data stream
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return Pet
#' @export
TestHeader = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
local_var_response <- self$TestHeaderWithHttpInfo(header_test_int, stream_callback = stream_callback, data_file = data_file, ...)
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
return(invisible(NULL))
}
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
local_var_response$content
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
local_var_response
} else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
local_var_response
} else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
local_var_response
}
},
#' Header test
#'
#' @description
#' Header test
#'
#' @param header_test_int header test int
#' @param stream_callback (optional) callback function to process the data stream
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return API response (Pet) with additional information such as HTTP status code, headers
#' @export
TestHeaderWithHttpInfo = function(header_test_int, stream_callback = NULL, data_file = NULL, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
if (missing(`header_test_int`)) {
rlang::abort(message = "Missing required parameter `header_test_int`.",
.subclass = "ApiException",
ApiException = ApiException$new(status = 0,
reason = "Missing required parameter `header_test_int`."))
}
header_params["header_test_int"] <- `header_test_int`
local_var_body <- NULL
local_var_url_path <- "/pet_header_test"
# API key authentication
if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
}
# The Accept request HTTP header
local_var_accepts = list("application/xml", "application/json")
# The Content-Type representation header
local_var_content_types = list()
local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
method = "GET",
query_params = query_params,
header_params = header_params,
accepts = local_var_accepts,
content_types = local_var_content_types,
body = local_var_body,
stream_callback = stream_callback,
...)
if (typeof(stream_callback) == "closure") { # return void if streaming is enabled
return(invisible(NULL))
}
if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
# save response in a file
if (!is.null(data_file)) {
write(local_var_resp$response, data_file)
}
deserialized_resp_obj <- tryCatch(
self$api_client$deserialize(local_var_resp$response, "Pet", loadNamespace("petstore")),
error = function(e) {
rlang::abort(message = "Failed to deserialize response",
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
}
)
local_var_resp$content <- deserialized_resp_obj
local_var_resp
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.")
}
rlang::abort(message = local_var_error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api client exception encountered."
}
rlang::abort(message = local_var_error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
} else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api server exception encountered."
}
rlang::abort(message = error_msg,
.subclass = "ApiException",
ApiException = ApiException$new(http_response = local_var_resp))
}
},
#' Update an existing pet #' Update an existing pet
#' #'
#' @description #' @description

View File

@ -68,6 +68,7 @@ Class | Method | HTTP request | Description
*PetApi* | [**FindPetsByTags**](docs/PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags *PetApi* | [**FindPetsByTags**](docs/PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**GetPetById**](docs/PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID *PetApi* | [**GetPetById**](docs/PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**GetPetByIdStreaming**](docs/PetApi.md#GetPetByIdStreaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming) *PetApi* | [**GetPetByIdStreaming**](docs/PetApi.md#GetPetByIdStreaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming)
*PetApi* | [**TestHeader**](docs/PetApi.md#TestHeader) | **GET** /pet_header_test | Header test
*PetApi* | [**UpdatePet**](docs/PetApi.md#UpdatePet) | **PUT** /pet | Update an existing pet *PetApi* | [**UpdatePet**](docs/PetApi.md#UpdatePet) | **PUT** /pet | Update an existing pet
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#UpdatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#UpdatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**UploadFile**](docs/PetApi.md#UploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFile**](docs/PetApi.md#UploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image

View File

@ -10,6 +10,7 @@ Method | HTTP request | Description
[**FindPetsByTags**](PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**FindPetsByTags**](PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
[**GetPetById**](PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID [**GetPetById**](PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID
[**GetPetByIdStreaming**](PetApi.md#GetPetByIdStreaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming) [**GetPetByIdStreaming**](PetApi.md#GetPetByIdStreaming) | **GET** /pet/{petId}?streaming | Find pet by ID (streaming)
[**TestHeader**](PetApi.md#TestHeader) | **GET** /pet_header_test | Header test
[**UpdatePet**](PetApi.md#UpdatePet) | **PUT** /pet | Update an existing pet [**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 [**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 [**UploadFile**](PetApi.md#UploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
@ -395,6 +396,72 @@ Name | Type | Description | Notes
| **400** | Invalid ID supplied | - | | **400** | Invalid ID supplied | - |
| **404** | Pet not found | - | | **404** | Pet not found | - |
# **TestHeader**
> Pet TestHeader(header_test_int)
Header test
Header test
### Example
```R
library(petstore)
var_header_test_int <- 56 # integer | header test int
#Header test
api_instance <- PetApi$new()
# Configure API key authorization: api_key
api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
result <- tryCatch(
# to save the result into a file, simply add the optional `data_file` parameter, e.g.
# api_instance$TestHeader(var_header_test_int, data_file = "result.txt"),
# this endpoint supports data streaming via a callback function using the optional `stream_callback` parameter, e.g.
# api_instance$TestHeader(var_header_test_int, stream_callback = function(x){ print(length(x)) }),
api_instance$TestHeader(var_header_test_int),
ApiException = function(ex) ex
)
# In case of error, print the error object
if (!is.null(result$ApiException)) {
dput(result$ApiException)
# error object
dput(result$ApiException$error_object)
} else {
# deserialized response object
dput(result$content)
# response headers
dput(result$response$headers)
# response status code
dput(result$response$status_code)
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**header_test_int** | **integer**| header test int |
### Return type
[**Pet**](Pet.md)
### Authorization
[api_key](../README.md#api_key)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |
| **400** | Invalid ID supplied | - |
| **404** | Pet not found | - |
# **UpdatePet** # **UpdatePet**
> Pet UpdatePet(pet) > Pet UpdatePet(pet)

View File

@ -107,6 +107,20 @@ test_that("GetPetByIdStreaming", {
) )
}) })
test_that("Test header parameters", {
# test exception
result <- tryCatch(pet_api$TestHeader(45345),
ApiException = function(ex) ex
)
expect_true(!is.null(result))
expect_true(!is.null(result$ApiException))
expect_equal(result$ApiException$status, 404)
# test error object `ApiResponse`
#expect_equal(result$ApiException$error_object$toString(), "{\"code\":404,\"type\":\"unknown\",\"message\":\"null for uri: http://pet\n x[1]: store.swagger.io/v2/pet_header_test\"}")
expect_equal(result$ApiException$error_object$code, 404)
})
test_that("Test GetPetById exception", { test_that("Test GetPetById exception", {
# test exception # test exception
result <- tryCatch(pet_api$GetPetById(98765), # petId not exist result <- tryCatch(pet_api$GetPetById(98765), # petId not exist