diff --git a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache index 058bdb5ca280..28520f752bef 100644 --- a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache +++ b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache @@ -50,6 +50,9 @@ ApiResponse <- R6::R6Class( #' @param to_encoding The target encoding of the return value. #' @export response_as_text = function(from_encoding = "", to_encoding = "UTF-8") { + if (is.null(self$response)) { + 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.") diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index e81cd16951d3..6fef8bb79c55 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -515,7 +515,7 @@ file_params["{{baseName}}"] <- httr::upload_file(`{{paramName}}`) {{/isHttr2}} {{#isHttr2}} - file_params["{{baseName}}"] <- curl::form_file(`{{paramName}}`) + file_params[["{{baseName}}"]] <- curl::form_file(`{{paramName}}`) {{/isHttr2}} {{/isFile}} {{/formParams}} 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 3057ea2c4004..ace9861b42ee 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -335,7 +335,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type 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..1f003712d3c7 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 @@ -344,7 +344,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type. diff --git a/samples/client/echo_api/r/R/api_client.R b/samples/client/echo_api/r/R/api_client.R index 9fbeffaa59f6..78edb04b7d33 100644 --- a/samples/client/echo_api/r/R/api_client.R +++ b/samples/client/echo_api/r/R/api_client.R @@ -287,7 +287,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type diff --git a/samples/client/echo_api/r/R/api_response.R b/samples/client/echo_api/r/R/api_response.R index 404f2ec8a9e8..999532bf3611 100644 --- a/samples/client/echo_api/r/R/api_response.R +++ b/samples/client/echo_api/r/R/api_response.R @@ -57,6 +57,9 @@ ApiResponse <- R6::R6Class( #' @param to_encoding The target encoding of the return value. #' @export response_as_text = function(from_encoding = "", to_encoding = "UTF-8") { + if (is.null(self$response)) { + 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.") 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..777f268794a3 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_client.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_client.R @@ -333,7 +333,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type. 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 b84d66f6ee0f..2916fd07d45a 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_response.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_response.R @@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class( #' @param to_encoding The target encoding of the return value. #' @export response_as_text = function(from_encoding = "", to_encoding = "UTF-8") { + if (is.null(self$response)) { + 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.") 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 054a8c18952e..22bba7ad4116 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/pet_api.R +++ b/samples/client/petstore/R-httr2-wrapper/R/pet_api.R @@ -1807,7 +1807,7 @@ PetApi <- R6::R6Class( form_params["additionalMetadata"] <- `additional_metadata` - file_params["file"] <- curl::form_file(`file`) + file_params[["file"]] <- curl::form_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" if (!missing(`pet_id`)) { local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index 32aa262f5545..777f268794a3 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -333,7 +333,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type. diff --git a/samples/client/petstore/R-httr2/R/api_response.R b/samples/client/petstore/R-httr2/R/api_response.R index b84d66f6ee0f..2916fd07d45a 100644 --- a/samples/client/petstore/R-httr2/R/api_response.R +++ b/samples/client/petstore/R-httr2/R/api_response.R @@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class( #' @param to_encoding The target encoding of the return value. #' @export response_as_text = function(from_encoding = "", to_encoding = "UTF-8") { + if (is.null(self$response)) { + 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.") diff --git a/samples/client/petstore/R-httr2/R/pet_api.R b/samples/client/petstore/R-httr2/R/pet_api.R index 9bc403759fdf..d79e53aa7189 100644 --- a/samples/client/petstore/R-httr2/R/pet_api.R +++ b/samples/client/petstore/R-httr2/R/pet_api.R @@ -1807,7 +1807,7 @@ PetApi <- R6::R6Class( form_params["additionalMetadata"] <- `additional_metadata` - file_params["file"] <- curl::form_file(`file`) + file_params[["file"]] <- curl::form_file(`file`) local_var_url_path <- "/pet/{petId}/uploadImage" if (!missing(`pet_id`)) { local_var_url_path <- gsub("\\{petId\\}", URLencode(as.character(`pet_id`), reserved = TRUE), local_var_url_path) diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 2fa06773f021..3acfc70b63ef 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -316,7 +316,11 @@ ApiClient <- R6::R6Class( #' @return Deserialized object. #' @export deserialize = function(raw_response, return_type, pkg_env) { - resp_obj <- jsonlite::fromJSON(raw_response) + if (jsonlite::validate(raw_response)) { + resp_obj <- jsonlite::fromJSON(raw_response) + } else { + resp_obj <- raw_response + } self$deserializeObj(resp_obj, return_type, pkg_env) }, #' Deserialize the response from jsonlite object based on the given type diff --git a/samples/client/petstore/R/R/api_response.R b/samples/client/petstore/R/R/api_response.R index b84d66f6ee0f..2916fd07d45a 100644 --- a/samples/client/petstore/R/R/api_response.R +++ b/samples/client/petstore/R/R/api_response.R @@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class( #' @param to_encoding The target encoding of the return value. #' @export response_as_text = function(from_encoding = "", to_encoding = "UTF-8") { + if (is.null(self$response)) { + 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.")