From 5f49a041909f03ac82d6cc5ea1533647f0e058f7 Mon Sep 17 00:00:00 2001 From: Jonas Emmert <63006948+joXemMx@users.noreply.github.com> Date: Tue, 19 Mar 2024 03:03:17 +0100 Subject: [PATCH] allow api response to be NULL and regenerate samples (#18141) --- .../src/main/resources/r/ApiResponse.mustache | 3 +++ samples/client/echo_api/r/R/api_response.R | 3 +++ samples/client/petstore/R-httr2-wrapper/R/api_response.R | 3 +++ samples/client/petstore/R-httr2/R/api_response.R | 3 +++ samples/client/petstore/R/R/api_response.R | 3 +++ 5 files changed, 15 insertions(+) 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.")