diff --git a/bin/configs/r-client.yaml b/bin/configs/r-client.yaml index 9043e19da79..ca3d74c45db 100644 --- a/bin/configs/r-client.yaml +++ b/bin/configs/r-client.yaml @@ -5,3 +5,6 @@ templateDir: modules/openapi-generator/src/main/resources/r httpUserAgent: PetstoreAgent additionalProperties: packageName: petstore + exceptionPackage: rlang + useRlangExceptionHandling: true + returnExceptionOnFailure: true diff --git a/modules/openapi-generator/src/main/resources/r/api_doc.mustache b/modules/openapi-generator/src/main/resources/r/api_doc.mustache index a00d06208e6..40b00753348 100644 --- a/modules/openapi-generator/src/main/resources/r/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_doc.mustache @@ -22,53 +22,53 @@ Method | HTTP request | Description library({{{packageName}}}) {{#allParams}} -var.{{{paramName}}} <- {{{vendorExtensions.x-r-example}}} # {{{dataType}}} | {{{description}}} +var_{{{paramName}}} <- {{{vendorExtensions.x-r-example}}} # {{{dataType}}} | {{{description}}} {{/allParams}} {{#summary}} #{{{.}}} {{/summary}} -api.instance <- {{{classname}}}$new() +api_instance <- {{{classname}}}$new() {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} # Configure HTTP basic authorization: {{{name}}} -api.instance$apiClient$username <- 'TODO_YOUR_USERNAME'; -api.instance$apiClient$password <- 'TODO_YOUR_PASSWORD'; +api_instance$api_client$username <- 'TODO_YOUR_USERNAME'; +api_instance$api_client$password <- 'TODO_YOUR_PASSWORD'; {{/isBasic}} {{#isApiKey}} # Configure API key authorization: {{{name}}} -api.instance$apiClient$apiKeys['{{{keyParamName}}}'] <- 'TODO_YOUR_API_KEY'; +api_instance$api_client$api_keys['{{{keyParamName}}}'] <- 'TODO_YOUR_API_KEY'; {{/isApiKey}} {{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; {{/isOAuth}} {{/authMethods}} {{/hasAuthMethods}} {{#returnExceptionOnFailure}} {{#useRlangExceptionHandling}} result <- tryCatch( - api.instance${{{operationId}}}({{#requiredParams}}var.{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var.{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}}), + api_instance${{{operationId}}}({{#requiredParams}}var_{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var_{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}}), ApiException = function(ex) ex ) # In case of error, print the error object if(!is.null(result$ApiException)) { cat(result$ApiException$toString()) - } else { -{{#returnType}} -# deserialized response object -response.object <- result$content -{{/returnType}} -# response headers -response.headers <- result$response$headers -# response status code -response.status.code <- result$response$status_code +} else { + {{#returnType}} + # deserialized response object + response.object <- result$content + {{/returnType}} + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code } {{/useRlangExceptionHandling}} {{/returnExceptionOnFailure}} {{^useRlangExceptionHandling}} -{{#returnType}}result <- {{/returnType}}api.instance${{{operationId}}}({{#requiredParams}}var.{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var.{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}}) +{{#returnType}}result <- {{/returnType}}api_instance${{{operationId}}}({{#requiredParams}}var_{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var_{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}}) {{#returnType}} dput(result) {{/returnType}} diff --git a/samples/client/petstore/R/.openapi-generator/FILES b/samples/client/petstore/R/.openapi-generator/FILES index 7c5f45bad20..77f97df74ed 100644 --- a/samples/client/petstore/R/.openapi-generator/FILES +++ b/samples/client/petstore/R/.openapi-generator/FILES @@ -6,6 +6,7 @@ NAMESPACE R/allof_tag_api_response.R R/animal.R R/api_client.R +R/api_exception.R R/api_response.R R/cat.R R/cat_all_of.R diff --git a/samples/client/petstore/R/DESCRIPTION b/samples/client/petstore/R/DESCRIPTION index 6293ab707f3..30778f884dc 100644 --- a/samples/client/petstore/R/DESCRIPTION +++ b/samples/client/petstore/R/DESCRIPTION @@ -11,5 +11,5 @@ Encoding: UTF-8 License: Apache License 2.0 LazyData: true Suggests: testthat -Imports: jsonlite, httr, R6, base64enc +Imports: jsonlite, httr, R6, base64enc, rlang RoxygenNote: 6.0.1.9000 diff --git a/samples/client/petstore/R/NAMESPACE b/samples/client/petstore/R/NAMESPACE index a889c35c709..78afe3ec044 100644 --- a/samples/client/petstore/R/NAMESPACE +++ b/samples/client/petstore/R/NAMESPACE @@ -9,6 +9,7 @@ import(base64enc) # Core export(ApiClient) export(ApiResponse) +export(ApiException) # Models export(AllofTagApiResponse) diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 4da8ff91545..299da075124 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -33,6 +33,7 @@ #' @field retry_status_codes vector of status codes to retry #' @field max_retry_attempts maximum number of retries for the status codes #' @importFrom httr add_headers accept timeout content +#' @importFrom rlang abort #' @export ApiClient <- R6::R6Class( "ApiClient", @@ -152,7 +153,7 @@ ApiClient <- R6::R6Class( httr::DELETE(url, query = query_params, headers, http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...) } else { err_msg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." - stop(err_msg) + rlang::abort(message = err_msg, .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = err_msg)) } }, diff --git a/samples/client/petstore/R/R/api_exception.R b/samples/client/petstore/R/R/api_exception.R new file mode 100644 index 00000000000..fccd7090141 --- /dev/null +++ b/samples/client/petstore/R/R/api_exception.R @@ -0,0 +1,54 @@ +#' @docType class +#' @title ApiException +#' @description ApiException Class +#' @format An \code{R6Class} generator object +#' @field status Status of the ApiException +#' @field reason Reason of the ApiException +#' @field body Body of the http response +#' @field headers Headers of the http response +#' @export +ApiException <- R6::R6Class( + "ApiException", + public = list( + status = NULL, + reason = NULL, + body = NULL, + headers = NULL, + + initialize = function(status = NULL, reason = NULL, http_response = NULL) { + if (!is.null(http_response)) { + self$status <- http_response$status_code + errorMsg <- toString(content(http_response)) + if(errorMsg == ""){ + errorMsg <- "Api exception encountered." + } + self$body <- errorMsg + self$headers <- http_response$headers + self$reason <- httr::http_status(http_response)$reason + } else { + self$status <- status + self$reason <- reason + self$body <- NULL + self$headers <- NULL + } + }, + + # returns the string format of ApiException + toString = function() { + errorMsg <- "" + errorMsg <- paste("status : ", self$status, "\n", sep = "") + errorMsg <- paste(errorMsg, "Reason : ", self$reason, "\n", sep = "") + if (!is.null(self$headers)) { + errorMsg <- paste(errorMsg, "Headers : ", "\n", sep = "") + for (name in names(self$headers)) { + errorMsg <- paste(errorMsg, name, " : ", self$headers[[name]], "\n", sep = " ") + } + } + if (!is.null(self$body)) { + errorMsg <- paste(errorMsg, "Body : ", "\n", sep = "") + errorMsg <- paste(errorMsg, self$body,"\n") + } + errorMsg + } + ) +) \ No newline at end of file diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index b956b43ec98..46e377cb8f6 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -21,6 +21,7 @@ #' \item \emph{ @param } var_data_file character #' \item \emph{ @returnType } \link{User} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -45,12 +46,27 @@ #' #test data_file to ensure it's escaped correctly #' api.instance <- FakeApi$new() #' -#' result <- api.instance$FakeDataFile(var.dummy, var_data_file=var.var_data_file) +#'result <- tryCatch( +#' api.instance$FakeDataFile(var.dummy, var_data_file=var.var_data_file), +#' 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 +#' } #' #' #' } #' @importFrom R6 R6Class #' @importFrom base64enc base64encode +#' @importFrom rlang abort #' @export FakeApi <- R6::R6Class( "FakeApi", @@ -84,7 +100,7 @@ FakeApi <- R6::R6Class( header_params <- c() if (missing(`dummy`)) { - stop("Missing required parameter `dummy`.") + rlang::abort(message = "Missing required parameter `dummy`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `dummy`.")) } body <- NULL @@ -106,16 +122,28 @@ FakeApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "User", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } } ) diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index d8c0a81a234..3045dd77dfb 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -20,6 +20,7 @@ #' \item \emph{ @param } pet \link{Pet} #' \item \emph{ @returnType } \link{Pet} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -44,6 +45,7 @@ #' \item \emph{ @param } pet_id integer #' \item \emph{ @param } api_key character #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 400 | Invalid pet value #' @@ -61,6 +63,7 @@ #' \item \emph{ @param } status Enum < [available, pending, sold] > #' \item \emph{ @returnType } list( \link{Pet} ) \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -85,6 +88,7 @@ #' \item \emph{ @param } tags list( character ) #' \item \emph{ @returnType } list( \link{Pet} ) \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -109,6 +113,7 @@ #' \item \emph{ @param } pet_id 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 #' @@ -140,6 +145,7 @@ #' \item \emph{ @param } pet \link{Pet} #' \item \emph{ @returnType } \link{Pet} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -179,6 +185,7 @@ #' \item \emph{ @param } name character #' \item \emph{ @param } status character #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 405 | Invalid input #' @@ -198,6 +205,7 @@ #' \item \emph{ @param } file data.frame #' \item \emph{ @returnType } \link{ModelApiResponse} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -224,7 +232,21 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$AddPet(var.pet) +#'result <- tryCatch( +#' api.instance$AddPet(var.pet), +#' 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 +#' } #' #' #' #################### DeletePet #################### @@ -239,7 +261,19 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$DeletePet(var.pet_id, api_key=var.api_key) +#'result <- tryCatch( +#' api.instance$DeletePet(var.pet_id, api_key=var.api_key), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### FindPetsByStatus #################### @@ -253,7 +287,21 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$FindPetsByStatus(var.status) +#'result <- tryCatch( +#' api.instance$FindPetsByStatus(var.status), +#' 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 +#' } #' #' #' #################### FindPetsByTags #################### @@ -267,7 +315,21 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$FindPetsByTags(var.tags) +#'result <- tryCatch( +#' api.instance$FindPetsByTags(var.tags), +#' 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 +#' } #' #' #' #################### GetPetById #################### @@ -281,7 +343,21 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$GetPetById(var.pet_id) +#'result <- tryCatch( +#' api.instance$GetPetById(var.pet_id), +#' 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 #################### @@ -295,7 +371,21 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$UpdatePet(var.pet) +#'result <- tryCatch( +#' api.instance$UpdatePet(var.pet), +#' 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 +#' } #' #' #' #################### UpdatePetWithForm #################### @@ -311,7 +401,19 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status) +#'result <- tryCatch( +#' api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### UploadFile #################### @@ -327,12 +429,27 @@ #' # Configure OAuth2 access token for authorization: petstore_auth #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; #' -#' result <- api.instance$UploadFile(var.pet_id, additional_metadata=var.additional_metadata, file=var.file) +#'result <- tryCatch( +#' api.instance$UploadFile(var.pet_id, additional_metadata=var.additional_metadata, file=var.file), +#' 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 +#' } #' #' #' } #' @importFrom R6 R6Class #' @importFrom base64enc base64encode +#' @importFrom rlang abort #' @export PetApi <- R6::R6Class( "PetApi", @@ -366,7 +483,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet`)) { - stop("Missing required parameter `pet`.") + rlang::abort(message = "Missing required parameter `pet`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet`.")) } if (!missing(`pet`)) { @@ -395,16 +512,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, DeletePet = function(pet_id, api_key=NULL, ...) { @@ -427,7 +556,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet_id`)) { - stop("Missing required parameter `pet_id`.") + rlang::abort(message = "Missing required parameter `pet_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet_id`.")) } body <- NULL @@ -449,11 +578,23 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, FindPetsByStatus = function(status, data_file=NULL, ...) { @@ -476,7 +617,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`status`)) { - stop("Missing required parameter `status`.") + rlang::abort(message = "Missing required parameter `status`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `status`.")) } body <- NULL @@ -500,16 +641,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, FindPetsByTags = function(tags, data_file=NULL, ...) { @@ -532,7 +685,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`tags`)) { - stop("Missing required parameter `tags`.") + rlang::abort(message = "Missing required parameter `tags`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `tags`.")) } body <- NULL @@ -556,16 +709,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, GetPetById = function(pet_id, data_file=NULL, ...) { @@ -588,7 +753,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet_id`)) { - stop("Missing required parameter `pet_id`.") + rlang::abort(message = "Missing required parameter `pet_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet_id`.")) } body <- NULL @@ -618,16 +783,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, UpdatePet = function(pet, data_file=NULL, ...) { @@ -650,7 +827,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet`)) { - stop("Missing required parameter `pet`.") + rlang::abort(message = "Missing required parameter `pet`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet`.")) } if (!missing(`pet`)) { @@ -679,16 +856,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, UpdatePetWithForm = function(pet_id, name=NULL, status=NULL, ...) { @@ -711,7 +900,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet_id`)) { - stop("Missing required parameter `pet_id`.") + rlang::abort(message = "Missing required parameter `pet_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet_id`.")) } body <- list( @@ -737,11 +926,23 @@ PetApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, UploadFile = function(pet_id, additional_metadata=NULL, file=NULL, data_file=NULL, ...) { @@ -764,7 +965,7 @@ PetApi <- R6::R6Class( header_params <- c() if (missing(`pet_id`)) { - stop("Missing required parameter `pet_id`.") + rlang::abort(message = "Missing required parameter `pet_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `pet_id`.")) } body <- list( @@ -796,16 +997,28 @@ PetApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } } ) diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index a44fe31a20f..64a85f6fddd 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -19,6 +19,7 @@ #' \itemize{ #' \item \emph{ @param } order_id character #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 400 | Invalid ID supplied #' @@ -41,6 +42,7 @@ #' #' \itemize{ #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -58,6 +60,7 @@ #' \item \emph{ @param } order_id integer #' \item \emph{ @returnType } \link{Order} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -89,6 +92,7 @@ #' \item \emph{ @param } order \link{Order} #' \item \emph{ @returnType } \link{Order} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -119,7 +123,19 @@ #' #Delete purchase order by ID #' api.instance <- StoreApi$new() #' -#' result <- api.instance$DeleteOrder(var.order_id) +#'result <- tryCatch( +#' api.instance$DeleteOrder(var.order_id), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### GetInventory #################### @@ -132,7 +148,21 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$GetInventory() +#'result <- tryCatch( +#' api.instance$GetInventory(), +#' 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 +#' } #' #' #' #################### GetOrderById #################### @@ -143,7 +173,21 @@ #' #Find purchase order by ID #' api.instance <- StoreApi$new() #' -#' result <- api.instance$GetOrderById(var.order_id) +#'result <- tryCatch( +#' api.instance$GetOrderById(var.order_id), +#' 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 +#' } #' #' #' #################### PlaceOrder #################### @@ -154,12 +198,27 @@ #' #Place an order for a pet #' api.instance <- StoreApi$new() #' -#' result <- api.instance$PlaceOrder(var.order) +#'result <- tryCatch( +#' api.instance$PlaceOrder(var.order), +#' 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 +#' } #' #' #' } #' @importFrom R6 R6Class #' @importFrom base64enc base64encode +#' @importFrom rlang abort #' @export StoreApi <- R6::R6Class( "StoreApi", @@ -193,7 +252,7 @@ StoreApi <- R6::R6Class( header_params <- c() if (missing(`order_id`)) { - stop("Missing required parameter `order_id`.") + rlang::abort(message = "Missing required parameter `order_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `order_id`.")) } body <- NULL @@ -213,11 +272,23 @@ StoreApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, GetInventory = function(data_file=NULL, ...) { @@ -262,16 +333,28 @@ StoreApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "map(integer)", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, GetOrderById = function(order_id, data_file=NULL, ...) { @@ -294,7 +377,7 @@ StoreApi <- R6::R6Class( header_params <- c() if (missing(`order_id`)) { - stop("Missing required parameter `order_id`.") + rlang::abort(message = "Missing required parameter `order_id`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `order_id`.")) } body <- NULL @@ -320,16 +403,28 @@ StoreApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, PlaceOrder = function(order, data_file=NULL, ...) { @@ -352,7 +447,7 @@ StoreApi <- R6::R6Class( header_params <- c() if (missing(`order`)) { - stop("Missing required parameter `order`.") + rlang::abort(message = "Missing required parameter `order`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `order`.")) } if (!missing(`order`)) { @@ -379,16 +474,28 @@ StoreApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } } ) diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 8bfa31cc4ce..8ac0f4d37dd 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -19,6 +19,7 @@ #' \itemize{ #' \item \emph{ @param } user \link{User} #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 0 | successful operation #' @@ -35,6 +36,7 @@ #' \itemize{ #' \item \emph{ @param } user list( \link{User} ) #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 0 | successful operation #' @@ -51,6 +53,7 @@ #' \itemize{ #' \item \emph{ @param } user list( \link{User} ) #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 0 | successful operation #' @@ -67,6 +70,7 @@ #' \itemize{ #' \item \emph{ @param } username character #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 400 | Invalid username supplied #' @@ -91,6 +95,7 @@ #' \item \emph{ @param } username character #' \item \emph{ @returnType } \link{User} \cr #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -122,6 +127,7 @@ #' \item \emph{ @param } username character #' \item \emph{ @param } password character #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 200 | successful operation #' @@ -147,6 +153,7 @@ #' #' \itemize{ #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 0 | successful operation #' @@ -164,6 +171,7 @@ #' \item \emph{ @param } username character #' \item \emph{ @param } user \link{User} #' +#' \item On encountering errors, an error of subclass ApiException will be thrown. #' #' \item status code : 400 | Invalid user supplied #' @@ -197,7 +205,19 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$CreateUser(var.user) +#'result <- tryCatch( +#' api.instance$CreateUser(var.user), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### CreateUsersWithArrayInput #################### @@ -211,7 +231,19 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$CreateUsersWithArrayInput(var.user) +#'result <- tryCatch( +#' api.instance$CreateUsersWithArrayInput(var.user), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### CreateUsersWithListInput #################### @@ -225,7 +257,19 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$CreateUsersWithListInput(var.user) +#'result <- tryCatch( +#' api.instance$CreateUsersWithListInput(var.user), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### DeleteUser #################### @@ -239,7 +283,19 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$DeleteUser(var.username) +#'result <- tryCatch( +#' api.instance$DeleteUser(var.username), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### GetUserByName #################### @@ -250,7 +306,21 @@ #' #Get user by user name #' api.instance <- UserApi$new() #' -#' result <- api.instance$GetUserByName(var.username) +#'result <- tryCatch( +#' api.instance$GetUserByName(var.username), +#' 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 +#' } #' #' #' #################### LoginUser #################### @@ -262,7 +332,21 @@ #' #Logs user into the system #' api.instance <- UserApi$new() #' -#' result <- api.instance$LoginUser(var.username, var.password) +#'result <- tryCatch( +#' api.instance$LoginUser(var.username, var.password), +#' 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 +#' } #' #' #' #################### LogoutUser #################### @@ -275,7 +359,19 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$LogoutUser() +#'result <- tryCatch( +#' api.instance$LogoutUser(), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' #################### UpdateUser #################### @@ -290,12 +386,25 @@ #' #Configure API key authorization: api_key #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; #' -#' result <- api.instance$UpdateUser(var.username, var.user) +#'result <- tryCatch( +#' api.instance$UpdateUser(var.username, var.user), +#' ApiException = function(ex) ex +#' ) +#' # In case of error, print the error object +#' if(!is.null(result$ApiException)) { +#' cat(result$ApiException$toString()) +#' } else { +#' # response headers +#' response.headers <- result$response$headers +#' # response status code +#' response.status.code <- result$response$status_code +#' } #' #' #' } #' @importFrom R6 R6Class #' @importFrom base64enc base64encode +#' @importFrom rlang abort #' @export UserApi <- R6::R6Class( "UserApi", @@ -329,7 +438,7 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`user`)) { - stop("Missing required parameter `user`.") + rlang::abort(message = "Missing required parameter `user`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `user`.")) } if (!missing(`user`)) { @@ -354,11 +463,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, CreateUsersWithArrayInput = function(user, ...) { @@ -381,7 +502,7 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`user`)) { - stop("Missing required parameter `user`.") + rlang::abort(message = "Missing required parameter `user`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `user`.")) } if (!missing(`user`)) { @@ -407,11 +528,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, CreateUsersWithListInput = function(user, ...) { @@ -434,7 +567,7 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`user`)) { - stop("Missing required parameter `user`.") + rlang::abort(message = "Missing required parameter `user`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `user`.")) } if (!missing(`user`)) { @@ -460,11 +593,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, DeleteUser = function(username, ...) { @@ -487,7 +632,7 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`username`)) { - stop("Missing required parameter `username`.") + rlang::abort(message = "Missing required parameter `username`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `username`.")) } body <- NULL @@ -511,11 +656,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, GetUserByName = function(username, data_file=NULL, ...) { @@ -538,7 +695,7 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`username`)) { - stop("Missing required parameter `username`.") + rlang::abort(message = "Missing required parameter `username`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `username`.")) } body <- NULL @@ -564,16 +721,28 @@ UserApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "User", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, LoginUser = function(username, password, data_file=NULL, ...) { @@ -596,11 +765,11 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`username`)) { - stop("Missing required parameter `username`.") + rlang::abort(message = "Missing required parameter `username`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `username`.")) } if (missing(`password`)) { - stop("Missing required parameter `password`.") + rlang::abort(message = "Missing required parameter `password`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `password`.")) } body <- NULL @@ -622,16 +791,28 @@ UserApi <- R6::R6Class( deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "character", loadNamespace("petstore")), error = function(e) { - stop("Failed to deserialize response") + rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } ) ApiResponse$new(deserialized_resp_obj, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, LogoutUser = function(...) { @@ -670,11 +851,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } }, UpdateUser = function(username, user, ...) { @@ -697,11 +890,11 @@ UserApi <- R6::R6Class( header_params <- c() if (missing(`username`)) { - stop("Missing required parameter `username`.") + rlang::abort(message = "Missing required parameter `username`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `username`.")) } if (missing(`user`)) { - stop("Missing required parameter `user`.") + rlang::abort(message = "Missing required parameter `user`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `user`.")) } if (!missing(`user`)) { @@ -730,11 +923,23 @@ UserApi <- R6::R6Class( if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { - ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { - ApiResponse$new("API client error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { - ApiResponse$new("API server error", resp) + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." + } + rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) } } ) diff --git a/samples/client/petstore/R/docs/FakeApi.md b/samples/client/petstore/R/docs/FakeApi.md index 02b3eba91d9..8de1fc175c5 100644 --- a/samples/client/petstore/R/docs/FakeApi.md +++ b/samples/client/petstore/R/docs/FakeApi.md @@ -18,13 +18,26 @@ test data_file to ensure it's escaped correctly ```R library(petstore) -var.dummy <- 'dummy_example' # character | dummy required parameter -var.var_data_file <- 'var_data_file_example' # character | header data file +var_dummy <- 'dummy_example' # character | dummy required parameter +var_var_data_file <- 'var_data_file_example' # character | header data file #test data_file to ensure it's escaped correctly -api.instance <- FakeApi$new() -result <- api.instance$FakeDataFile(var.dummy, var_data_file=var.var_data_file) -dput(result) +api_instance <- FakeApi$new() +result <- tryCatch( + api_instance$FakeDataFile(var_dummy, var_data_file=var_var_data_file), + 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 +} ``` ### Parameters diff --git a/samples/client/petstore/R/docs/PetApi.md b/samples/client/petstore/R/docs/PetApi.md index cbd6e49c2fc..d67f8fe20a2 100644 --- a/samples/client/petstore/R/docs/PetApi.md +++ b/samples/client/petstore/R/docs/PetApi.md @@ -25,14 +25,27 @@ Add a new pet to the store ```R library(petstore) -var.pet <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store +var_pet <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store #Add a new pet to the store -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -result <- api.instance$AddPet(var.pet) -dput(result) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$AddPet(var_pet), + 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 +} ``` ### Parameters @@ -71,14 +84,26 @@ Deletes a pet ```R library(petstore) -var.pet_id <- 56 # integer | Pet id to delete -var.api_key <- 'api_key_example' # character | +var_pet_id <- 56 # integer | Pet id to delete +var_api_key <- 'api_key_example' # character | #Deletes a pet -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -api.instance$DeletePet(var.pet_id, api_key=var.api_key) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$DeletePet(var_pet_id, api_key=var_api_key), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -117,14 +142,27 @@ Multiple status values can be provided with comma separated strings ```R library(petstore) -var.status <- list("available") # array[character] | Status values that need to be considered for filter +var_status <- list("available") # array[character] | Status values that need to be considered for filter #Finds Pets by status -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -result <- api.instance$FindPetsByStatus(var.status) -dput(result) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$FindPetsByStatus(var_status), + 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 +} ``` ### Parameters @@ -163,14 +201,27 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ```R library(petstore) -var.tags <- list("inner_example") # array[character] | Tags to filter by +var_tags <- list("inner_example") # array[character] | Tags to filter by #Finds Pets by tags -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -result <- api.instance$FindPetsByTags(var.tags) -dput(result) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$FindPetsByTags(var_tags), + 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 +} ``` ### Parameters @@ -209,14 +260,27 @@ Returns a single pet ```R library(petstore) -var.pet_id <- 56 # integer | ID of pet to return +var_pet_id <- 56 # integer | ID of pet to return #Find pet by ID -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -result <- api.instance$GetPetById(var.pet_id) -dput(result) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$GetPetById(var_pet_id), + 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 +} ``` ### Parameters @@ -256,14 +320,27 @@ Update an existing pet ```R library(petstore) -var.pet <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store +var_pet <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store #Update an existing pet -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -result <- api.instance$UpdatePet(var.pet) -dput(result) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$UpdatePet(var_pet), + 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 +} ``` ### Parameters @@ -304,15 +381,27 @@ Updates a pet in the store with form data ```R library(petstore) -var.pet_id <- 56 # integer | ID of pet that needs to be updated -var.name <- 'name_example' # character | Updated name of the pet -var.status <- 'status_example' # character | Updated status of the pet +var_pet_id <- 56 # integer | ID of pet that needs to be updated +var_name <- 'name_example' # character | Updated name of the pet +var_status <- 'status_example' # character | Updated status of the pet #Updates a pet in the store with form data -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$UpdatePetWithForm(var_pet_id, name=var_name, status=var_status), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -352,16 +441,29 @@ uploads an image ```R library(petstore) -var.pet_id <- 56 # integer | ID of pet to update -var.additional_metadata <- 'additional_metadata_example' # character | Additional data to pass to server -var.file <- File.new('/path/to/file') # data.frame | file to upload +var_pet_id <- 56 # integer | ID of pet to update +var_additional_metadata <- 'additional_metadata_example' # character | Additional data to pass to server +var_file <- File.new('/path/to/file') # data.frame | file to upload #uploads an image -api.instance <- PetApi$new() +api_instance <- PetApi$new() # Configure OAuth2 access token for authorization: petstore_auth -api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; -result <- api.instance$UploadFile(var.pet_id, additional_metadata=var.additional_metadata, file=var.file) -dput(result) +api_instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN'; +result <- tryCatch( + api_instance$UploadFile(var_pet_id, additional_metadata=var_additional_metadata, file=var_file), + 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 +} ``` ### Parameters diff --git a/samples/client/petstore/R/docs/StoreApi.md b/samples/client/petstore/R/docs/StoreApi.md index 1c7d982fc1b..f62dcf6e76b 100644 --- a/samples/client/petstore/R/docs/StoreApi.md +++ b/samples/client/petstore/R/docs/StoreApi.md @@ -21,11 +21,23 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non ```R library(petstore) -var.order_id <- 'order_id_example' # character | ID of the order that needs to be deleted +var_order_id <- 'order_id_example' # character | ID of the order that needs to be deleted #Delete purchase order by ID -api.instance <- StoreApi$new() -api.instance$DeleteOrder(var.order_id) +api_instance <- StoreApi$new() +result <- tryCatch( + api_instance$DeleteOrder(var_order_id), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -66,11 +78,24 @@ library(petstore) #Returns pet inventories by status -api.instance <- StoreApi$new() +api_instance <- StoreApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -result <- api.instance$GetInventory() -dput(result) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$GetInventory(), + 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 +} ``` ### Parameters @@ -105,12 +130,25 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge ```R library(petstore) -var.order_id <- 56 # integer | ID of pet that needs to be fetched +var_order_id <- 56 # integer | ID of pet that needs to be fetched #Find purchase order by ID -api.instance <- StoreApi$new() -result <- api.instance$GetOrderById(var.order_id) -dput(result) +api_instance <- StoreApi$new() +result <- tryCatch( + api_instance$GetOrderById(var_order_id), + 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 +} ``` ### Parameters @@ -150,12 +188,25 @@ Place an order for a pet ```R library(petstore) -var.order <- Order$new(123, 123, 123, "shipDate_example", "placed", "complete_example") # Order | order placed for purchasing the pet +var_order <- Order$new(123, 123, 123, "shipDate_example", "placed", "complete_example") # Order | order placed for purchasing the pet #Place an order for a pet -api.instance <- StoreApi$new() -result <- api.instance$PlaceOrder(var.order) -dput(result) +api_instance <- StoreApi$new() +result <- tryCatch( + api_instance$PlaceOrder(var_order), + 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 +} ``` ### Parameters diff --git a/samples/client/petstore/R/docs/UserApi.md b/samples/client/petstore/R/docs/UserApi.md index 31e599f28ce..62fbbe4970a 100644 --- a/samples/client/petstore/R/docs/UserApi.md +++ b/samples/client/petstore/R/docs/UserApi.md @@ -25,13 +25,25 @@ This can only be done by the logged in user. ```R library(petstore) -var.user <- User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123) # User | Created user object +var_user <- User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123) # User | Created user object #Create user -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$CreateUser(var.user) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$CreateUser(var_user), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -69,13 +81,25 @@ Creates list of users with given input array ```R library(petstore) -var.user <- list(User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123)) # array[User] | List of user object +var_user <- list(User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123)) # array[User] | List of user object #Creates list of users with given input array -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$CreateUsersWithArrayInput(var.user) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$CreateUsersWithArrayInput(var_user), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -113,13 +137,25 @@ Creates list of users with given input array ```R library(petstore) -var.user <- list(User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123)) # array[User] | List of user object +var_user <- list(User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123)) # array[User] | List of user object #Creates list of users with given input array -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$CreateUsersWithListInput(var.user) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$CreateUsersWithListInput(var_user), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -157,13 +193,25 @@ This can only be done by the logged in user. ```R library(petstore) -var.username <- 'username_example' # character | The name that needs to be deleted +var_username <- 'username_example' # character | The name that needs to be deleted #Delete user -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$DeleteUser(var.username) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$DeleteUser(var_username), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -202,12 +250,25 @@ Get user by user name ```R library(petstore) -var.username <- 'username_example' # character | The name that needs to be fetched. Use user1 for testing. +var_username <- 'username_example' # character | The name that needs to be fetched. Use user1 for testing. #Get user by user name -api.instance <- UserApi$new() -result <- api.instance$GetUserByName(var.username) -dput(result) +api_instance <- UserApi$new() +result <- tryCatch( + api_instance$GetUserByName(var_username), + 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 +} ``` ### Parameters @@ -247,13 +308,26 @@ Logs user into the system ```R library(petstore) -var.username <- 'username_example' # character | The user name for login -var.password <- 'password_example' # character | The password for login in clear text +var_username <- 'username_example' # character | The user name for login +var_password <- 'password_example' # character | The password for login in clear text #Logs user into the system -api.instance <- UserApi$new() -result <- api.instance$LoginUser(var.username, var.password) -dput(result) +api_instance <- UserApi$new() +result <- tryCatch( + api_instance$LoginUser(var_username, var_password), + 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 +} ``` ### Parameters @@ -295,10 +369,22 @@ library(petstore) #Logs out current logged in user session -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$LogoutUser() +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$LogoutUser(), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters @@ -333,14 +419,26 @@ This can only be done by the logged in user. ```R library(petstore) -var.username <- 'username_example' # character | name that need to be deleted -var.user <- User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123) # User | Updated user object +var_username <- 'username_example' # character | name that need to be deleted +var_user <- User$new(123, "username_example", "firstName_example", "lastName_example", "email_example", "password_example", "phone_example", 123) # User | Updated user object #Updated user -api.instance <- UserApi$new() +api_instance <- UserApi$new() # Configure API key authorization: api_key -api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; -api.instance$UpdateUser(var.username, var.user) +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; +result <- tryCatch( + api_instance$UpdateUser(var_username, var_user), + ApiException = function(ex) ex + ) +# In case of error, print the error object +if(!is.null(result$ApiException)) { + cat(result$ApiException$toString()) +} else { + # response headers + response.headers <- result$response$headers + # response status code + response.status.code <- result$response$status_code +} ``` ### Parameters diff --git a/samples/client/petstore/R/test_petstore.R b/samples/client/petstore/R/test_petstore.R new file mode 100644 index 00000000000..f0be4739860 --- /dev/null +++ b/samples/client/petstore/R/test_petstore.R @@ -0,0 +1,24 @@ +library(petstore) + +var_pet_id <- 56 # integer | ID of pet to return + +#Find pet by ID +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$GetPetById(var_pet_id), + 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 +} +