From 6399a7a97ea238e497006599afe67b6c398aabdc Mon Sep 17 00:00:00 2001 From: Matt Pollock Date: Sun, 24 Nov 2024 09:12:39 -0500 Subject: [PATCH] [R] improve binary/text response handling (#20131) * [R client] better support for binary/compressed responses * cleanup * revert change after PR review * update samples * fix R tests * move private api methods to api-client, revert breaking method name change --- .../src/main/resources/r/ApiResponse.mustache | 3 - .../src/main/resources/r/api.mustache | 30 ++- .../src/main/resources/r/api_client.mustache | 46 ++++ .../main/resources/r/api_exception.mustache | 4 +- .../r/libraries/httr2/api_client.mustache | 46 ++++ samples/client/echo_api/r/R/api_client.R | 46 ++++ samples/client/echo_api/r/R/api_response.R | 3 - samples/client/echo_api/r/R/auth_api.R | 42 ++-- samples/client/echo_api/r/R/body_api.R | 210 ++++++++++------- samples/client/echo_api/r/R/form_api.R | 63 ++--- samples/client/echo_api/r/R/header_api.R | 21 +- samples/client/echo_api/r/R/path_api.R | 21 +- samples/client/echo_api/r/R/query_api.R | 210 ++++++++++------- .../petstore/R-httr2-wrapper/R/api_client.R | 46 ++++ .../R-httr2-wrapper/R/api_exception.R | 4 +- .../petstore/R-httr2-wrapper/R/api_response.R | 3 - .../petstore/R-httr2-wrapper/R/fake_api.R | 103 ++++---- .../petstore/R-httr2-wrapper/R/pet_api.R | 222 +++++++++--------- .../petstore/R-httr2-wrapper/R/store_api.R | 88 +++---- .../petstore/R-httr2-wrapper/R/user_api.R | 160 +++++++------ .../client/petstore/R-httr2/R/api_client.R | 46 ++++ .../client/petstore/R-httr2/R/api_exception.R | 4 +- .../client/petstore/R-httr2/R/api_response.R | 3 - samples/client/petstore/R-httr2/R/fake_api.R | 103 ++++---- samples/client/petstore/R-httr2/R/pet_api.R | 222 +++++++++--------- samples/client/petstore/R-httr2/R/store_api.R | 88 +++---- samples/client/petstore/R-httr2/R/user_api.R | 160 +++++++------ samples/client/petstore/R/R/api_client.R | 46 ++++ samples/client/petstore/R/R/api_exception.R | 4 +- samples/client/petstore/R/R/api_response.R | 3 - samples/client/petstore/R/R/fake_api.R | 103 ++++---- samples/client/petstore/R/R/pet_api.R | 222 +++++++++--------- samples/client/petstore/R/R/store_api.R | 88 +++---- samples/client/petstore/R/R/user_api.R | 160 +++++++------ 34 files changed, 1522 insertions(+), 1101 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache index c817cb42713e..e985255bdda8 100644 --- a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache +++ b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache @@ -50,9 +50,6 @@ ApiResponse <- R6::R6Class( self$response <- charToRaw(jsonlite::toJSON("NULL")) } text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding) - if (is.na(text_response)) { - warning("The response is binary and will not be converted to text.") - } return(text_response) } ) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 8fec6e01f861..2895328c09c9 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -153,13 +153,13 @@ {{/vendorExtensions.x-streaming}} if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -543,12 +543,9 @@ if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { {{#returnType}} {{#isPrimitiveType}} - local_var_content <- local_var_resp$response - local_var_resp, "text", encoding = "UTF-8", simplifyVector = FALSE - ) # save response in a file if (!is.null(data_file)) { - write(local_var_content, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } ApiResponse$new(content,resp) @@ -556,11 +553,11 @@ {{^isPrimitiveType}} # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "{{returnType}}", loadNamespace("{{packageName}}")), + self$api_client$DeserializeResponse(local_var_resp, "{{returnType}}"), error = function(e) { {{#useDefaultExceptionHandling}} stop("Failed to deserialize response") @@ -579,10 +576,13 @@ {{! Returning the ApiResponse object with NULL object when the endpoint doesn't return anything}} local_var_resp$content <- NULL {{/returnType}} - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { {{#returnExceptionOnFailure}} - local_var_error_msg <- local_var_resp$response + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -600,7 +600,6 @@ {{/returnExceptionOnFailure}} } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { {{#returnExceptionOnFailure}} - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -618,7 +617,6 @@ {{/returnExceptionOnFailure}} } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { {{#returnExceptionOnFailure}} - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -635,7 +633,7 @@ if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) {{/returnExceptionOnFailure}} } }{{^-last}},{{/-last}} diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index fb1285d0f177..b1844f4686b0 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -430,6 +430,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("{{packageName}}"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/modules/openapi-generator/src/main/resources/r/api_exception.mustache b/modules/openapi-generator/src/main/resources/r/api_exception.mustache index 5c2e0bc45b2a..5aac3eab7889 100644 --- a/modules/openapi-generator/src/main/resources/r/api_exception.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_exception.mustache @@ -32,7 +32,7 @@ ApiException <- R6::R6Class( initialize = function(status = NULL, reason = NULL, http_response = NULL) { if (!is.null(http_response)) { self$status <- http_response$status_code - errorMsg <- http_response$response + errorMsg <- http_response$response_as_text() if (is.null(errorMsg) || errorMsg == "") { errorMsg <- "Api exception encountered. No details given." } @@ -40,7 +40,7 @@ ApiException <- R6::R6Class( self$headers <- http_response$headers self$reason <- http_response$http_status_desc {{#errorObjectType}} - self$error_object <- {{errorObjectType}}$new()$fromJSONString(http_response$response) + self$error_object <- {{errorObjectType}}$new()$fromJSONString(http_response$response_as_text()) {{/errorObjectType}} } else { self$status <- status diff --git a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache index e888008f4597..f2e95e679465 100644 --- a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache @@ -443,6 +443,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("{{packageName}}"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/samples/client/echo_api/r/R/api_client.R b/samples/client/echo_api/r/R/api_client.R index 3c9001df6ef3..2f7bcc7a1710 100644 --- a/samples/client/echo_api/r/R/api_client.R +++ b/samples/client/echo_api/r/R/api_client.R @@ -382,6 +382,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("openapi"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/samples/client/echo_api/r/R/api_response.R b/samples/client/echo_api/r/R/api_response.R index 7d628bab258d..3dfb2c96a588 100644 --- a/samples/client/echo_api/r/R/api_response.R +++ b/samples/client/echo_api/r/R/api_response.R @@ -57,9 +57,6 @@ ApiResponse <- R6::R6Class( self$response <- charToRaw(jsonlite::toJSON("NULL")) } text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding) - if (is.na(text_response)) { - warning("The response is binary and will not be converted to text.") - } return(text_response) } ) diff --git a/samples/client/echo_api/r/R/auth_api.R b/samples/client/echo_api/r/R/auth_api.R index 3785b97b5cb7..8b2999b3758e 100644 --- a/samples/client/echo_api/r/R/auth_api.R +++ b/samples/client/echo_api/r/R/auth_api.R @@ -78,13 +78,13 @@ AuthApi <- R6::R6Class( TestAuthHttpBasic = function(data_file = NULL, ...) { local_var_response <- self$TestAuthHttpBasicWithHttpInfo(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -133,18 +133,21 @@ AuthApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -152,7 +155,7 @@ AuthApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -166,13 +169,13 @@ AuthApi <- R6::R6Class( TestAuthHttpBearer = function(data_file = NULL, ...) { local_var_response <- self$TestAuthHttpBearerWithHttpInfo(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -221,18 +224,21 @@ AuthApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -240,7 +246,7 @@ AuthApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/echo_api/r/R/body_api.R b/samples/client/echo_api/r/R/body_api.R index 5fb012236667..1be1cafba8b4 100644 --- a/samples/client/echo_api/r/R/body_api.R +++ b/samples/client/echo_api/r/R/body_api.R @@ -184,13 +184,13 @@ BodyApi <- R6::R6Class( TestBinaryGif = function(data_file = NULL, ...) { local_var_response <- self$TestBinaryGifWithHttpInfo(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -235,18 +235,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "data.frame", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "data.frame"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -254,7 +257,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -269,13 +272,13 @@ BodyApi <- R6::R6Class( TestBodyApplicationOctetstreamBinary = function(body = NULL, data_file = NULL, ...) { local_var_response <- self$TestBodyApplicationOctetstreamBinaryWithHttpInfo(body, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -328,18 +331,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -347,7 +353,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -362,13 +368,13 @@ BodyApi <- R6::R6Class( TestBodyMultipartFormdataArrayOfBinary = function(files, data_file = NULL, ...) { local_var_response <- self$TestBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -420,18 +426,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -439,7 +448,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -454,13 +463,13 @@ BodyApi <- R6::R6Class( TestBodyMultipartFormdataSingleBinary = function(my_file = NULL, data_file = NULL, ...) { local_var_response <- self$TestBodyMultipartFormdataSingleBinaryWithHttpInfo(my_file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -508,18 +517,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -527,7 +539,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -542,13 +554,13 @@ BodyApi <- R6::R6Class( TestEchoBodyAllOfPet = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyAllOfPetWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -601,18 +613,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -620,7 +635,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -635,13 +650,13 @@ BodyApi <- R6::R6Class( TestEchoBodyFreeFormObjectResponseString = function(body = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyFreeFormObjectResponseStringWithHttpInfo(body, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -694,18 +709,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -713,7 +731,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -728,13 +746,13 @@ BodyApi <- R6::R6Class( TestEchoBodyPet = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyPetWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -787,18 +805,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -806,7 +827,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -821,13 +842,13 @@ BodyApi <- R6::R6Class( TestEchoBodyPetResponseString = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyPetResponseStringWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -880,18 +901,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -899,7 +923,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -914,13 +938,13 @@ BodyApi <- R6::R6Class( TestEchoBodyStringEnum = function(body = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyStringEnumWithHttpInfo(body, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -973,18 +997,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "StringEnumRef", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "StringEnumRef"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -992,7 +1019,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -1007,13 +1034,13 @@ BodyApi <- R6::R6Class( TestEchoBodyTagResponseString = function(tag = NULL, data_file = NULL, ...) { local_var_response <- self$TestEchoBodyTagResponseStringWithHttpInfo(tag, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1066,18 +1093,21 @@ BodyApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -1085,7 +1115,7 @@ BodyApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/echo_api/r/R/form_api.R b/samples/client/echo_api/r/R/form_api.R index 25bacabdd6a6..040ce871545b 100644 --- a/samples/client/echo_api/r/R/form_api.R +++ b/samples/client/echo_api/r/R/form_api.R @@ -97,13 +97,13 @@ FormApi <- R6::R6Class( TestFormIntegerBooleanString = function(integer_form = NULL, boolean_form = NULL, string_form = NULL, data_file = NULL, ...) { local_var_response <- self$TestFormIntegerBooleanStringWithHttpInfo(integer_form, boolean_form, string_form, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -157,18 +157,21 @@ FormApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -176,7 +179,7 @@ FormApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -191,13 +194,13 @@ FormApi <- R6::R6Class( TestFormObjectMultipart = function(marker, data_file = NULL, ...) { local_var_response <- self$TestFormObjectMultipartWithHttpInfo(marker, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -249,18 +252,21 @@ FormApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -268,7 +274,7 @@ FormApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -288,13 +294,13 @@ FormApi <- R6::R6Class( TestFormOneof = function(form1 = NULL, form2 = NULL, form3 = NULL, form4 = NULL, id = NULL, name = NULL, data_file = NULL, ...) { local_var_response <- self$TestFormOneofWithHttpInfo(form1, form2, form3, form4, id, name, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -357,18 +363,21 @@ FormApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -376,7 +385,7 @@ FormApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/echo_api/r/R/header_api.R b/samples/client/echo_api/r/R/header_api.R index 4117739ac339..c20fab0df874 100644 --- a/samples/client/echo_api/r/R/header_api.R +++ b/samples/client/echo_api/r/R/header_api.R @@ -68,13 +68,13 @@ HeaderApi <- R6::R6Class( TestHeaderIntegerBooleanStringEnums = function(integer_header = NULL, boolean_header = NULL, string_header = NULL, enum_nonref_string_header = NULL, enum_ref_string_header = NULL, data_file = NULL, ...) { local_var_response <- self$TestHeaderIntegerBooleanStringEnumsWithHttpInfo(integer_header, boolean_header, string_header, enum_nonref_string_header, enum_ref_string_header, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -139,18 +139,21 @@ HeaderApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -158,7 +161,7 @@ HeaderApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/echo_api/r/R/path_api.R b/samples/client/echo_api/r/R/path_api.R index 5b690cfc8f99..20456181683f 100644 --- a/samples/client/echo_api/r/R/path_api.R +++ b/samples/client/echo_api/r/R/path_api.R @@ -66,13 +66,13 @@ PathApi <- R6::R6Class( TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath = function(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = NULL, ...) { local_var_response <- self$TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -157,18 +157,21 @@ PathApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -176,7 +179,7 @@ PathApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/echo_api/r/R/query_api.R b/samples/client/echo_api/r/R/query_api.R index e4f2697ae717..4fb98bd8008c 100644 --- a/samples/client/echo_api/r/R/query_api.R +++ b/samples/client/echo_api/r/R/query_api.R @@ -192,13 +192,13 @@ QueryApi <- R6::R6Class( TestEnumRefString = function(enum_nonref_string_query = NULL, enum_ref_string_query = NULL, data_file = NULL, ...) { local_var_response <- self$TestEnumRefStringWithHttpInfo(enum_nonref_string_query, enum_ref_string_query, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -254,18 +254,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -273,7 +276,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -290,13 +293,13 @@ QueryApi <- R6::R6Class( TestQueryDatetimeDateString = function(datetime_query = NULL, date_query = NULL, string_query = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryDatetimeDateStringWithHttpInfo(datetime_query, date_query, string_query, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -353,18 +356,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -372,7 +378,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -389,13 +395,13 @@ QueryApi <- R6::R6Class( TestQueryIntegerBooleanString = function(integer_query = NULL, boolean_query = NULL, string_query = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryIntegerBooleanStringWithHttpInfo(integer_query, boolean_query, string_query, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -452,18 +458,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -471,7 +480,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -486,13 +495,13 @@ QueryApi <- R6::R6Class( TestQueryStyleDeepObjectExplodeTrueObject = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -541,18 +550,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -560,7 +572,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -575,13 +587,13 @@ QueryApi <- R6::R6Class( TestQueryStyleDeepObjectExplodeTrueObjectAllOf = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -630,18 +642,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -649,7 +664,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -664,13 +679,13 @@ QueryApi <- R6::R6Class( TestQueryStyleFormExplodeFalseArrayInteger = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -720,18 +735,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -739,7 +757,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -754,13 +772,13 @@ QueryApi <- R6::R6Class( TestQueryStyleFormExplodeFalseArrayString = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleFormExplodeFalseArrayStringWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -810,18 +828,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -829,7 +850,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -844,13 +865,13 @@ QueryApi <- R6::R6Class( TestQueryStyleFormExplodeTrueArrayString = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleFormExplodeTrueArrayStringWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -899,18 +920,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -918,7 +942,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -933,13 +957,13 @@ QueryApi <- R6::R6Class( TestQueryStyleFormExplodeTrueObject = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleFormExplodeTrueObjectWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -988,18 +1012,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -1007,7 +1034,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } }, @@ -1022,13 +1049,13 @@ QueryApi <- R6::R6Class( TestQueryStyleFormExplodeTrueObjectAllOf = function(query_object = NULL, data_file = NULL, ...) { local_var_response <- self$TestQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo(query_object, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1077,18 +1104,21 @@ QueryApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { stop("Failed to deserialize response") } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { ApiResponse$new("API client error", local_var_resp) @@ -1096,7 +1126,7 @@ QueryApi <- R6::R6Class( if (is.null(local_var_resp$response) || local_var_resp$response == "") { local_var_resp$response <- "API server error" } - local_var_resp + return(local_var_resp) } } ) diff --git a/samples/client/petstore/R-httr2-wrapper/R/api_client.R b/samples/client/petstore/R-httr2-wrapper/R/api_client.R index 32aa262f5545..9c5bba767310 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_client.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_client.R @@ -432,6 +432,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("petstore"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/samples/client/petstore/R-httr2-wrapper/R/api_exception.R b/samples/client/petstore/R-httr2-wrapper/R/api_exception.R index cc6e7b0e7b40..fcb62402484c 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_exception.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_exception.R @@ -33,14 +33,14 @@ ApiException <- R6::R6Class( initialize = function(status = NULL, reason = NULL, http_response = NULL) { if (!is.null(http_response)) { self$status <- http_response$status_code - errorMsg <- http_response$response + errorMsg <- http_response$response_as_text() if (is.null(errorMsg) || errorMsg == "") { errorMsg <- "Api exception encountered. No details given." } self$body <- errorMsg self$headers <- http_response$headers self$reason <- http_response$http_status_desc - self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response) + self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response_as_text()) } else { self$status <- status self$reason <- reason diff --git a/samples/client/petstore/R-httr2-wrapper/R/api_response.R b/samples/client/petstore/R-httr2-wrapper/R/api_response.R index 95dc6428290e..605553d98a1e 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_response.R @@ -56,9 +56,6 @@ ApiResponse <- R6::R6Class( self$response <- charToRaw(jsonlite::toJSON("NULL")) } text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding) - if (is.na(text_response)) { - warning("The response is binary and will not be converted to text.") - } return(text_response) } ) diff --git a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R index 9493c19e70b7..5dae105c228b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/fake_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/fake_api.R @@ -193,13 +193,13 @@ FakeApi <- R6::R6Class( add_pet_optional = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$add_pet_optional_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -256,11 +256,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -268,9 +268,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -278,7 +281,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -286,7 +288,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -308,13 +309,13 @@ FakeApi <- R6::R6Class( fake_data_file = function(dummy, var_data_file = NULL, data_file = NULL, ...) { local_var_response <- self$fake_data_file_with_http_info(dummy, var_data_file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -374,11 +375,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -386,9 +387,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -396,7 +400,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -404,7 +407,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -424,13 +426,13 @@ FakeApi <- R6::R6Class( fake_path_array = function(path_array, ...) { local_var_response <- self$fake_path_array_with_http_info(path_array, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -486,9 +488,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -496,7 +501,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -504,7 +508,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -524,13 +527,13 @@ FakeApi <- R6::R6Class( fake_regular_expression = function(reg_exp_test, ...) { local_var_response <- self$fake_regular_expression_with_http_info(reg_exp_test, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -590,9 +593,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -600,7 +606,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -608,7 +613,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -629,13 +633,13 @@ FakeApi <- R6::R6Class( fake_set_query = function(set_dummy, array_dummy, ...) { local_var_response <- self$fake_set_query_with_http_info(set_dummy, array_dummy, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -713,9 +717,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -723,7 +730,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -731,7 +737,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R index e5e359b0526f..b19e01d9d8ab 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -396,13 +396,13 @@ PetApi <- R6::R6Class( add_pet = function(pet, data_file = NULL, ...) { local_var_response <- self$add_pet_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -466,11 +466,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -478,9 +478,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -488,7 +491,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -496,7 +498,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -517,13 +518,13 @@ PetApi <- R6::R6Class( delete_pet = function(pet_id, api_key = NULL, ...) { local_var_response <- self$delete_pet_with_http_info(pet_id, api_key, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -586,9 +587,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -596,7 +600,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -604,7 +607,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -625,13 +627,13 @@ PetApi <- R6::R6Class( find_pets_by_status = function(status, data_file = NULL, ...) { local_var_response <- self$find_pets_by_status_with_http_info(status, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -700,11 +702,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -712,9 +714,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -722,7 +727,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -730,7 +734,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -751,13 +754,13 @@ PetApi <- R6::R6Class( find_pets_by_tags = function(tags, data_file = NULL, ...) { local_var_response <- self$find_pets_by_tags_with_http_info(tags, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -814,11 +817,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -826,9 +829,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -836,7 +842,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -844,7 +849,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -865,13 +869,13 @@ PetApi <- R6::R6Class( get_pet_by_id = function(pet_id, data_file = NULL, ...) { local_var_response <- self$get_pet_by_id_with_http_info(pet_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -933,11 +937,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -945,9 +949,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -955,7 +962,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -963,7 +969,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -989,13 +994,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1063,11 +1068,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1075,9 +1080,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1085,7 +1093,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1093,7 +1100,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1119,13 +1125,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1191,11 +1197,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1203,9 +1209,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1213,7 +1222,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1221,7 +1229,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1242,13 +1249,13 @@ PetApi <- R6::R6Class( update_pet = function(pet, data_file = NULL, ...) { local_var_response <- self$update_pet_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1311,11 +1318,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1323,9 +1330,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1333,7 +1343,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1341,7 +1350,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1363,13 +1371,13 @@ PetApi <- R6::R6Class( update_pet_with_form = function(pet_id, name = NULL, status = NULL, ...) { local_var_response <- self$update_pet_with_form_with_http_info(pet_id, name, status, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1431,9 +1439,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1441,7 +1452,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1449,7 +1459,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1472,13 +1481,13 @@ PetApi <- R6::R6Class( upload_file = function(pet_id, additional_metadata = NULL, file = NULL, data_file = NULL, ...) { local_var_response <- self$upload_file_with_http_info(pet_id, additional_metadata, file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1545,11 +1554,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "ModelApiResponse", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "ModelApiResponse"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1557,9 +1566,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1567,7 +1579,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1575,7 +1586,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2-wrapper/R/store_api.R b/samples/client/petstore/R-httr2-wrapper/R/store_api.R index 03b65c4104a8..e49457700c0b 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/store_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/store_api.R @@ -171,13 +171,13 @@ StoreApi <- R6::R6Class( delete_order = function(order_id, ...) { local_var_response <- self$delete_order_with_http_info(order_id, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -233,9 +233,12 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -243,7 +246,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -251,7 +253,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -271,13 +272,13 @@ StoreApi <- R6::R6Class( get_inventory = function(data_file = NULL, ...) { local_var_response <- self$get_inventory_with_http_info(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -326,11 +327,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "map(integer)", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "map(integer)"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -338,9 +339,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -348,7 +352,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -356,7 +359,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -377,13 +379,13 @@ StoreApi <- R6::R6Class( get_order_by_id = function(order_id, data_file = NULL, ...) { local_var_response <- self$get_order_by_id_with_http_info(order_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -453,11 +455,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -465,9 +467,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -475,7 +480,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -483,7 +487,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -504,13 +507,13 @@ StoreApi <- R6::R6Class( place_order = function(order, data_file = NULL, ...) { local_var_response <- self$place_order_with_http_info(order, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -570,11 +573,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -582,9 +585,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -592,7 +598,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -600,7 +605,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2-wrapper/R/user_api.R b/samples/client/petstore/R-httr2-wrapper/R/user_api.R index 484cf99eecc4..4c938c7ee3ad 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/user_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/user_api.R @@ -280,13 +280,13 @@ UserApi <- R6::R6Class( create_user = function(user, ...) { local_var_response <- self$create_user_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -348,9 +348,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -358,7 +361,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -366,7 +368,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -386,13 +387,13 @@ UserApi <- R6::R6Class( create_users_with_array_input = function(user, ...) { local_var_response <- self$create_users_with_array_input_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -457,9 +458,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -467,7 +471,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -475,7 +478,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -495,13 +497,13 @@ UserApi <- R6::R6Class( create_users_with_list_input = function(user, ...) { local_var_response <- self$create_users_with_list_input_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -566,9 +568,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -576,7 +581,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -584,7 +588,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -604,13 +607,13 @@ UserApi <- R6::R6Class( delete_user = function(username, ...) { local_var_response <- self$delete_user_with_http_info(username, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -670,9 +673,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -680,7 +686,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -688,7 +693,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -709,13 +713,13 @@ UserApi <- R6::R6Class( get_user_by_name = function(username, data_file = NULL, ...) { local_var_response <- self$get_user_by_name_with_http_info(username, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -773,11 +777,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -785,9 +789,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -795,7 +802,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -803,7 +809,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -825,13 +830,13 @@ UserApi <- R6::R6Class( login_user = function(username, password, data_file = NULL, ...) { local_var_response <- self$login_user_with_http_info(username, password, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -904,11 +909,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -916,9 +921,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -926,7 +934,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -934,7 +941,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -953,13 +959,13 @@ UserApi <- R6::R6Class( logout_user = function(...) { local_var_response <- self$logout_user_with_http_info(...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1006,9 +1012,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1016,7 +1025,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1024,7 +1032,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1045,13 +1052,13 @@ UserApi <- R6::R6Class( update_user = function(username, user, ...) { local_var_response <- self$update_user_with_http_info(username, user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1126,9 +1133,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1136,7 +1146,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1144,7 +1153,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index 32aa262f5545..9c5bba767310 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -432,6 +432,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("petstore"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/samples/client/petstore/R-httr2/R/api_exception.R b/samples/client/petstore/R-httr2/R/api_exception.R index cc6e7b0e7b40..fcb62402484c 100644 --- a/samples/client/petstore/R-httr2/R/api_exception.R +++ b/samples/client/petstore/R-httr2/R/api_exception.R @@ -33,14 +33,14 @@ ApiException <- R6::R6Class( initialize = function(status = NULL, reason = NULL, http_response = NULL) { if (!is.null(http_response)) { self$status <- http_response$status_code - errorMsg <- http_response$response + errorMsg <- http_response$response_as_text() if (is.null(errorMsg) || errorMsg == "") { errorMsg <- "Api exception encountered. No details given." } self$body <- errorMsg self$headers <- http_response$headers self$reason <- http_response$http_status_desc - self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response) + self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response_as_text()) } else { self$status <- status self$reason <- reason diff --git a/samples/client/petstore/R-httr2/R/api_response.R b/samples/client/petstore/R-httr2/R/api_response.R index 95dc6428290e..605553d98a1e 100644 --- a/samples/client/petstore/R-httr2/R/api_response.R +++ b/samples/client/petstore/R-httr2/R/api_response.R @@ -56,9 +56,6 @@ ApiResponse <- R6::R6Class( self$response <- charToRaw(jsonlite::toJSON("NULL")) } text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding) - if (is.na(text_response)) { - warning("The response is binary and will not be converted to text.") - } return(text_response) } ) diff --git a/samples/client/petstore/R-httr2/R/fake_api.R b/samples/client/petstore/R-httr2/R/fake_api.R index d12e602f269d..175540cf5ee6 100644 --- a/samples/client/petstore/R-httr2/R/fake_api.R +++ b/samples/client/petstore/R-httr2/R/fake_api.R @@ -193,13 +193,13 @@ FakeApi <- R6::R6Class( add_pet_optional = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$add_pet_optional_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -256,11 +256,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -268,9 +268,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -278,7 +281,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -286,7 +288,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -308,13 +309,13 @@ FakeApi <- R6::R6Class( fake_data_file = function(dummy, var_data_file = NULL, data_file = NULL, ...) { local_var_response <- self$fake_data_file_with_http_info(dummy, var_data_file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -374,11 +375,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -386,9 +387,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -396,7 +400,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -404,7 +407,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -424,13 +426,13 @@ FakeApi <- R6::R6Class( fake_path_array = function(path_array_parameter, ...) { local_var_response <- self$fake_path_array_with_http_info(path_array_parameter, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -486,9 +488,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -496,7 +501,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -504,7 +508,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -524,13 +527,13 @@ FakeApi <- R6::R6Class( fake_regular_expression = function(reg_exp_test, ...) { local_var_response <- self$fake_regular_expression_with_http_info(reg_exp_test, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -590,9 +593,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -600,7 +606,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -608,7 +613,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -629,13 +633,13 @@ FakeApi <- R6::R6Class( fake_set_query = function(set_dummy, array_dummy, ...) { local_var_response <- self$fake_set_query_with_http_info(set_dummy, array_dummy, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -713,9 +717,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -723,7 +730,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -731,7 +737,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 506a0a2e33c7..f832c2ea5cbc 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -396,13 +396,13 @@ PetApi <- R6::R6Class( add_pet = function(pet, data_file = NULL, ...) { local_var_response <- self$add_pet_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -466,11 +466,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -478,9 +478,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -488,7 +491,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -496,7 +498,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -517,13 +518,13 @@ PetApi <- R6::R6Class( delete_pet = function(pet_id, api_key = NULL, ...) { local_var_response <- self$delete_pet_with_http_info(pet_id, api_key, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -586,9 +587,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -596,7 +600,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -604,7 +607,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -625,13 +627,13 @@ PetApi <- R6::R6Class( find_pets_by_status = function(status, data_file = NULL, ...) { local_var_response <- self$find_pets_by_status_with_http_info(status, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -700,11 +702,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -712,9 +714,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -722,7 +727,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -730,7 +734,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -751,13 +754,13 @@ PetApi <- R6::R6Class( find_pets_by_tags = function(tags, data_file = NULL, ...) { local_var_response <- self$find_pets_by_tags_with_http_info(tags, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -814,11 +817,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -826,9 +829,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -836,7 +842,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -844,7 +849,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -865,13 +869,13 @@ PetApi <- R6::R6Class( get_pet_by_id = function(pet_id, data_file = NULL, ...) { local_var_response <- self$get_pet_by_id_with_http_info(pet_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -933,11 +937,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -945,9 +949,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -955,7 +962,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -963,7 +969,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -989,13 +994,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1063,11 +1068,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1075,9 +1080,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1085,7 +1093,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1093,7 +1100,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1119,13 +1125,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1191,11 +1197,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1203,9 +1209,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1213,7 +1222,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1221,7 +1229,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1242,13 +1249,13 @@ PetApi <- R6::R6Class( update_pet = function(pet, data_file = NULL, ...) { local_var_response <- self$update_pet_with_http_info(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1311,11 +1318,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1323,9 +1330,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1333,7 +1343,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1341,7 +1350,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1363,13 +1371,13 @@ PetApi <- R6::R6Class( update_pet_with_form = function(pet_id, name = NULL, status = NULL, ...) { local_var_response <- self$update_pet_with_form_with_http_info(pet_id, name, status, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1431,9 +1439,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1441,7 +1452,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1449,7 +1459,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1472,13 +1481,13 @@ PetApi <- R6::R6Class( upload_file = function(pet_id, additional_metadata = NULL, file = NULL, data_file = NULL, ...) { local_var_response <- self$upload_file_with_http_info(pet_id, additional_metadata, file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1545,11 +1554,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "ModelApiResponse", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "ModelApiResponse"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1557,9 +1566,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1567,7 +1579,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1575,7 +1586,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2/R/store_api.R b/samples/client/petstore/R-httr2/R/store_api.R index b0526273367b..f445fabf3c2b 100644 --- a/samples/client/petstore/R-httr2/R/store_api.R +++ b/samples/client/petstore/R-httr2/R/store_api.R @@ -171,13 +171,13 @@ StoreApi <- R6::R6Class( delete_order = function(order_id, ...) { local_var_response <- self$delete_order_with_http_info(order_id, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -233,9 +233,12 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -243,7 +246,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -251,7 +253,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -271,13 +272,13 @@ StoreApi <- R6::R6Class( get_inventory = function(data_file = NULL, ...) { local_var_response <- self$get_inventory_with_http_info(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -326,11 +327,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "map(integer)", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "map(integer)"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -338,9 +339,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -348,7 +352,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -356,7 +359,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -377,13 +379,13 @@ StoreApi <- R6::R6Class( get_order_by_id = function(order_id, data_file = NULL, ...) { local_var_response <- self$get_order_by_id_with_http_info(order_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -453,11 +455,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -465,9 +467,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -475,7 +480,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -483,7 +487,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -504,13 +507,13 @@ StoreApi <- R6::R6Class( place_order = function(order, data_file = NULL, ...) { local_var_response <- self$place_order_with_http_info(order, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -570,11 +573,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -582,9 +585,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -592,7 +598,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -600,7 +605,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R-httr2/R/user_api.R b/samples/client/petstore/R-httr2/R/user_api.R index 0260367ffaa9..9487ca7835b0 100644 --- a/samples/client/petstore/R-httr2/R/user_api.R +++ b/samples/client/petstore/R-httr2/R/user_api.R @@ -280,13 +280,13 @@ UserApi <- R6::R6Class( create_user = function(user, ...) { local_var_response <- self$create_user_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -348,9 +348,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -358,7 +361,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -366,7 +368,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -386,13 +387,13 @@ UserApi <- R6::R6Class( create_users_with_array_input = function(user, ...) { local_var_response <- self$create_users_with_array_input_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -457,9 +458,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -467,7 +471,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -475,7 +478,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -495,13 +497,13 @@ UserApi <- R6::R6Class( create_users_with_list_input = function(user, ...) { local_var_response <- self$create_users_with_list_input_with_http_info(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -566,9 +568,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -576,7 +581,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -584,7 +588,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -604,13 +607,13 @@ UserApi <- R6::R6Class( delete_user = function(username, ...) { local_var_response <- self$delete_user_with_http_info(username, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -670,9 +673,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -680,7 +686,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -688,7 +693,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -709,13 +713,13 @@ UserApi <- R6::R6Class( get_user_by_name = function(username, data_file = NULL, ...) { local_var_response <- self$get_user_by_name_with_http_info(username, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -773,11 +777,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -785,9 +789,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -795,7 +802,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -803,7 +809,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -825,13 +830,13 @@ UserApi <- R6::R6Class( login_user = function(username, password, data_file = NULL, ...) { local_var_response <- self$login_user_with_http_info(username, password, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -904,11 +909,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -916,9 +921,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -926,7 +934,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -934,7 +941,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -953,13 +959,13 @@ UserApi <- R6::R6Class( logout_user = function(...) { local_var_response <- self$logout_user_with_http_info(...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1006,9 +1012,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1016,7 +1025,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1024,7 +1032,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1045,13 +1052,13 @@ UserApi <- R6::R6Class( update_user = function(username, user, ...) { local_var_response <- self$update_user_with_http_info(username, user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1126,9 +1133,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1136,7 +1146,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1144,7 +1153,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 631827298a30..638216216e37 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -411,6 +411,52 @@ ApiClient <- R6::R6Class( # not json mime type, simply return the first one return(headers[1]) } + }, + + #' @description + #' Deserialize the response + #' + #' @param local_var_resp The API response + #' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is. + #' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne. + DeserializeResponse = function(local_var_resp, return_type = NULL) { + text <- local_var_resp$response_as_text() + if (is.na(text)) { + return(local_var_resp$response) + } else if (is.null(return_type)) { + return(text) + } + return(self$deserialize(text, return_type, loadNamespace("petstore"))) + }, + + #' @description + #' Write response to a file + #' + #' The function will write out data. + #' + #' 1. If binary data is detected it will use `writeBin` + #' 2. If the raw response is coercable to text, the text will be written to a file + #' 3. If the raw response is not coercable to text, the raw response will be written + #' + #' @param local_var_resp The API response + #' @param file The name of the data file to save the result + WriteFile = function(local_var_resp, file) { + if (self$IsBinary(local_var_resp$response)) { + writeBin(local_var_resp$response, file) + } else { + response <- self$DeserializeResponse(local_var_resp) + base::write(response, file) + } + }, + + #' @description + #' Check response for binary content + #' + #' @param local_var_resp The API response + IsBinary = function(x) { + # ref: https://stackoverflow.com/a/17098690/1785752 + b <- readBin(x, "int", n = 1000, size=1, signed=FALSE) + return(max(b) > 128) } ) ) diff --git a/samples/client/petstore/R/R/api_exception.R b/samples/client/petstore/R/R/api_exception.R index cc6e7b0e7b40..fcb62402484c 100644 --- a/samples/client/petstore/R/R/api_exception.R +++ b/samples/client/petstore/R/R/api_exception.R @@ -33,14 +33,14 @@ ApiException <- R6::R6Class( initialize = function(status = NULL, reason = NULL, http_response = NULL) { if (!is.null(http_response)) { self$status <- http_response$status_code - errorMsg <- http_response$response + errorMsg <- http_response$response_as_text() if (is.null(errorMsg) || errorMsg == "") { errorMsg <- "Api exception encountered. No details given." } self$body <- errorMsg self$headers <- http_response$headers self$reason <- http_response$http_status_desc - self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response) + self$error_object <- ModelApiResponse$new()$fromJSONString(http_response$response_as_text()) } else { self$status <- status self$reason <- reason diff --git a/samples/client/petstore/R/R/api_response.R b/samples/client/petstore/R/R/api_response.R index 95dc6428290e..605553d98a1e 100644 --- a/samples/client/petstore/R/R/api_response.R +++ b/samples/client/petstore/R/R/api_response.R @@ -56,9 +56,6 @@ ApiResponse <- R6::R6Class( self$response <- charToRaw(jsonlite::toJSON("NULL")) } text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding) - if (is.na(text_response)) { - warning("The response is binary and will not be converted to text.") - } return(text_response) } ) diff --git a/samples/client/petstore/R/R/fake_api.R b/samples/client/petstore/R/R/fake_api.R index 8ec29fe83080..ee88e7eba789 100644 --- a/samples/client/petstore/R/R/fake_api.R +++ b/samples/client/petstore/R/R/fake_api.R @@ -193,13 +193,13 @@ FakeApi <- R6::R6Class( AddPetOptional = function(pet = NULL, data_file = NULL, ...) { local_var_response <- self$AddPetOptionalWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -256,11 +256,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -268,9 +268,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -278,7 +281,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -286,7 +288,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -308,13 +309,13 @@ FakeApi <- R6::R6Class( FakeDataFile = function(dummy, var_data_file = NULL, data_file = NULL, ...) { local_var_response <- self$FakeDataFileWithHttpInfo(dummy, var_data_file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -374,11 +375,11 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -386,9 +387,12 @@ FakeApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -396,7 +400,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -404,7 +407,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -424,13 +426,13 @@ FakeApi <- R6::R6Class( FakePathArray = function(path_array, ...) { local_var_response <- self$FakePathArrayWithHttpInfo(path_array, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -486,9 +488,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -496,7 +501,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -504,7 +508,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -524,13 +527,13 @@ FakeApi <- R6::R6Class( FakeRegularExpression = function(reg_exp_test, ...) { local_var_response <- self$FakeRegularExpressionWithHttpInfo(reg_exp_test, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -590,9 +593,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -600,7 +606,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -608,7 +613,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -629,13 +633,13 @@ FakeApi <- R6::R6Class( FakeSetQuery = function(set_dummy, array_dummy, ...) { local_var_response <- self$FakeSetQueryWithHttpInfo(set_dummy, array_dummy, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -713,9 +717,12 @@ FakeApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -723,7 +730,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -731,7 +737,6 @@ FakeApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index b1bae279acce..a19e01486290 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -396,13 +396,13 @@ PetApi <- R6::R6Class( AddPet = function(pet, data_file = NULL, ...) { local_var_response <- self$AddPetWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -466,11 +466,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -478,9 +478,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -488,7 +491,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -496,7 +498,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -517,13 +518,13 @@ PetApi <- R6::R6Class( DeletePet = function(pet_id, api_key = NULL, ...) { local_var_response <- self$DeletePetWithHttpInfo(pet_id, api_key, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -586,9 +587,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -596,7 +600,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -604,7 +607,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -625,13 +627,13 @@ PetApi <- R6::R6Class( FindPetsByStatus = function(status, data_file = NULL, ...) { local_var_response <- self$FindPetsByStatusWithHttpInfo(status, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -700,11 +702,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -712,9 +714,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -722,7 +727,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -730,7 +734,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -751,13 +754,13 @@ PetApi <- R6::R6Class( FindPetsByTags = function(tags, data_file = NULL, ...) { local_var_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -814,11 +817,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "array[Pet]", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "array[Pet]"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -826,9 +829,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -836,7 +842,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -844,7 +849,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -865,13 +869,13 @@ PetApi <- R6::R6Class( GetPetById = function(pet_id, data_file = NULL, ...) { local_var_response <- self$GetPetByIdWithHttpInfo(pet_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -933,11 +937,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -945,9 +949,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -955,7 +962,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -963,7 +969,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -989,13 +994,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1063,11 +1068,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1075,9 +1080,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1085,7 +1093,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1093,7 +1100,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1119,13 +1125,13 @@ PetApi <- R6::R6Class( } if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1191,11 +1197,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1203,9 +1209,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1213,7 +1222,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1221,7 +1229,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1242,13 +1249,13 @@ PetApi <- R6::R6Class( UpdatePet = function(pet, data_file = NULL, ...) { local_var_response <- self$UpdatePetWithHttpInfo(pet, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1311,11 +1318,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Pet"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1323,9 +1330,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1333,7 +1343,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1341,7 +1350,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1363,13 +1371,13 @@ PetApi <- R6::R6Class( UpdatePetWithForm = function(pet_id, name = NULL, status = NULL, ...) { local_var_response <- self$UpdatePetWithFormWithHttpInfo(pet_id, name, status, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1431,9 +1439,12 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1441,7 +1452,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1449,7 +1459,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1472,13 +1481,13 @@ PetApi <- R6::R6Class( UploadFile = function(pet_id, additional_metadata = NULL, file = NULL, data_file = NULL, ...) { local_var_response <- self$UploadFileWithHttpInfo(pet_id, additional_metadata, file, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1545,11 +1554,11 @@ PetApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "ModelApiResponse", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "ModelApiResponse"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -1557,9 +1566,12 @@ PetApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1567,7 +1579,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1575,7 +1586,6 @@ PetApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 62c14ff77022..6889cdf7aa70 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -171,13 +171,13 @@ StoreApi <- R6::R6Class( DeleteOrder = function(order_id, ...) { local_var_response <- self$DeleteOrderWithHttpInfo(order_id, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -233,9 +233,12 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -243,7 +246,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -251,7 +253,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -271,13 +272,13 @@ StoreApi <- R6::R6Class( GetInventory = function(data_file = NULL, ...) { local_var_response <- self$GetInventoryWithHttpInfo(data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -326,11 +327,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "map(integer)", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "map(integer)"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -338,9 +339,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -348,7 +352,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -356,7 +359,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -377,13 +379,13 @@ StoreApi <- R6::R6Class( GetOrderById = function(order_id, data_file = NULL, ...) { local_var_response <- self$GetOrderByIdWithHttpInfo(order_id, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -453,11 +455,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -465,9 +467,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -475,7 +480,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -483,7 +487,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -504,13 +507,13 @@ StoreApi <- R6::R6Class( PlaceOrder = function(order, data_file = NULL, ...) { local_var_response <- self$PlaceOrderWithHttpInfo(order, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -570,11 +573,11 @@ StoreApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "Order", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "Order"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -582,9 +585,12 @@ StoreApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -592,7 +598,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -600,7 +605,6 @@ StoreApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index 265044904b01..389cc69b57e4 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -280,13 +280,13 @@ UserApi <- R6::R6Class( CreateUser = function(user, ...) { local_var_response <- self$CreateUserWithHttpInfo(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -348,9 +348,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -358,7 +361,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -366,7 +368,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -386,13 +387,13 @@ UserApi <- R6::R6Class( CreateUsersWithArrayInput = function(user, ...) { local_var_response <- self$CreateUsersWithArrayInputWithHttpInfo(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -457,9 +458,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -467,7 +471,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -475,7 +478,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -495,13 +497,13 @@ UserApi <- R6::R6Class( CreateUsersWithListInput = function(user, ...) { local_var_response <- self$CreateUsersWithListInputWithHttpInfo(user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -566,9 +568,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -576,7 +581,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -584,7 +588,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -604,13 +607,13 @@ UserApi <- R6::R6Class( DeleteUser = function(username, ...) { local_var_response <- self$DeleteUserWithHttpInfo(username, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -670,9 +673,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -680,7 +686,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -688,7 +693,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -709,13 +713,13 @@ UserApi <- R6::R6Class( GetUserByName = function(username, data_file = NULL, ...) { local_var_response <- self$GetUserByNameWithHttpInfo(username, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -773,11 +777,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "User", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "User"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -785,9 +789,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -795,7 +802,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -803,7 +809,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -825,13 +830,13 @@ UserApi <- R6::R6Class( LoginUser = function(username, password, data_file = NULL, ...) { local_var_response <- self$LoginUserWithHttpInfo(username, password, data_file = data_file, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -904,11 +909,11 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { # save response in a file if (!is.null(data_file)) { - write(local_var_resp$response, data_file) + self$api_client$WriteFile(local_var_resp, data_file) } deserialized_resp_obj <- tryCatch( - self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("petstore")), + self$api_client$DeserializeResponse(local_var_resp, "character"), error = function(e) { rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", @@ -916,9 +921,12 @@ UserApi <- R6::R6Class( } ) local_var_resp$content <- deserialized_resp_obj - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -926,7 +934,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -934,7 +941,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -953,13 +959,13 @@ UserApi <- R6::R6Class( LogoutUser = function(...) { local_var_response <- self$LogoutUserWithHttpInfo(...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1006,9 +1012,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1016,7 +1025,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1024,7 +1032,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." } @@ -1045,13 +1052,13 @@ UserApi <- R6::R6Class( UpdateUser = function(username, user, ...) { local_var_response <- self$UpdateUserWithHttpInfo(username, user, ...) if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) { - local_var_response$content + return(local_var_response$content) } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) { - local_var_response + return(local_var_response) } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) { - local_var_response + return(local_var_response) } }, @@ -1126,9 +1133,12 @@ UserApi <- R6::R6Class( if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) { local_var_resp$content <- NULL - local_var_resp - } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { - local_var_error_msg <- local_var_resp$response + return(local_var_resp) + } + + local_var_error_msg <- local_var_resp$response_as_text() + if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) { + if (local_var_error_msg == "") { local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.") } @@ -1136,7 +1146,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api client exception encountered." } @@ -1144,7 +1153,6 @@ UserApi <- R6::R6Class( .subclass = "ApiException", ApiException = ApiException$new(http_response = local_var_resp)) } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) { - local_var_error_msg <- local_var_resp$response if (local_var_error_msg == "") { local_var_error_msg <- "Api server exception encountered." }