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/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_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/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/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.")