diff --git a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache index 9fac8f302b5..b5586e1d1a5 100644 --- a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache @@ -185,14 +185,10 @@ ApiClient <- R6::R6Class( ## add headers and default headers if (!is.null(header_params) && length(header_params) != 0) { - for (http_header in names(header_params)) { - req <- req %>% req_headers(http_header = header_params[http_header]) - } + req <- req %>% req_headers(!!!header_params) } if (!is.null(self$default_headers) && length(self$default_headers) != 0) { - for (http_header in names(header_params)) { - req <- req %>% req_headers(http_header = self$default_headers[http_header]) - } + req <- req %>% req_headers(!!!self$default_headers) } # set HTTP accept header diff --git a/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml index e6d720afd91..b97af0500aa 100644 --- a/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml @@ -242,6 +242,38 @@ paths: - petstore_auth: - 'write: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': get: tags: diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index 91de834777f..d1dcb01b2d6 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -190,14 +190,10 @@ ApiClient <- R6::R6Class( ## add headers and default headers if (!is.null(header_params) && length(header_params) != 0) { - for (http_header in names(header_params)) { - req <- req %>% req_headers(http_header = header_params[http_header]) - } + req <- req %>% req_headers(!!!header_params) } if (!is.null(self$default_headers) && length(self$default_headers) != 0) { - for (http_header in names(header_params)) { - req <- req %>% req_headers(http_header = self$default_headers[http_header]) - } + req <- req %>% req_headers(!!!self$default_headers) } # set HTTP accept header diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 5f4136c175d..96d0db0b98d 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -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 } #' #' @@ -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 #################### #' #' library(petstore) @@ -1197,6 +1257,127 @@ PetApi <- R6::R6Class( 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 #' #' @description diff --git a/samples/client/petstore/R-httr2/README.md b/samples/client/petstore/R-httr2/README.md index e3d53b6bb8a..94e6f1a2cd7 100644 --- a/samples/client/petstore/R-httr2/README.md +++ b/samples/client/petstore/R-httr2/README.md @@ -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* | [**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* | [**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_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 diff --git a/samples/client/petstore/R-httr2/docs/PetApi.md b/samples/client/petstore/R-httr2/docs/PetApi.md index 2921224f4e0..1bbb4f200cd 100644 --- a/samples/client/petstore/R-httr2/docs/PetApi.md +++ b/samples/client/petstore/R-httr2/docs/PetApi.md @@ -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 [**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) +[**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_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 @@ -395,6 +396,72 @@ Name | Type | Description | Notes | **400** | Invalid ID supplied | - | | **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** > Pet update_pet(pet) diff --git a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R index 2383ebd3317..066af44c17d 100644 --- a/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2/tests/testthat/test_petstore.R @@ -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 exception result <- tryCatch(pet_api$get_pet_by_id(98765), # petId not exist diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index 30710fa4272..27d1770ece1 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -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 } #' #' @@ -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 #################### #' #' library(petstore) @@ -1197,6 +1257,127 @@ PetApi <- R6::R6Class( 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 #' #' @description diff --git a/samples/client/petstore/R/README.md b/samples/client/petstore/R/README.md index 0460cc08fca..ced7db355d6 100644 --- a/samples/client/petstore/R/README.md +++ b/samples/client/petstore/R/README.md @@ -68,6 +68,7 @@ Class | Method | HTTP request | Description *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* | [**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* | [**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 diff --git a/samples/client/petstore/R/docs/PetApi.md b/samples/client/petstore/R/docs/PetApi.md index c5bb07afb8e..daf84841e7b 100644 --- a/samples/client/petstore/R/docs/PetApi.md +++ b/samples/client/petstore/R/docs/PetApi.md @@ -10,6 +10,7 @@ Method | HTTP request | Description [**FindPetsByTags**](PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**GetPetById**](PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID [**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 [**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 @@ -395,6 +396,72 @@ Name | Type | Description | Notes | **400** | Invalid ID supplied | - | | **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** > Pet UpdatePet(pet) diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 3132def5352..2bbb7e3f000 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -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 exception result <- tryCatch(pet_api$GetPetById(98765), # petId not exist