Skip to content

Commit 5f49a04

Browse files
authored
allow api response to be NULL and regenerate samples (#18141)
1 parent ddb5ab4 commit 5f49a04

5 files changed

Lines changed: 15 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/r/ApiResponse.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ ApiResponse <- R6::R6Class(
5050
#' @param to_encoding The target encoding of the return value.
5151
#' @export
5252
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
53+
if (is.null(self$response)) {
54+
self$response <- charToRaw(jsonlite::toJSON("NULL"))
55+
}
5356
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
5457
if (is.na(text_response)) {
5558
warning("The response is binary and will not be converted to text.")

samples/client/echo_api/r/R/api_response.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ ApiResponse <- R6::R6Class(
5757
#' @param to_encoding The target encoding of the return value.
5858
#' @export
5959
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
60+
if (is.null(self$response)) {
61+
self$response <- charToRaw(jsonlite::toJSON("NULL"))
62+
}
6063
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
6164
if (is.na(text_response)) {
6265
warning("The response is binary and will not be converted to text.")

samples/client/petstore/R-httr2-wrapper/R/api_response.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class(
5656
#' @param to_encoding The target encoding of the return value.
5757
#' @export
5858
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
59+
if (is.null(self$response)) {
60+
self$response <- charToRaw(jsonlite::toJSON("NULL"))
61+
}
5962
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
6063
if (is.na(text_response)) {
6164
warning("The response is binary and will not be converted to text.")

samples/client/petstore/R-httr2/R/api_response.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class(
5656
#' @param to_encoding The target encoding of the return value.
5757
#' @export
5858
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
59+
if (is.null(self$response)) {
60+
self$response <- charToRaw(jsonlite::toJSON("NULL"))
61+
}
5962
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
6063
if (is.na(text_response)) {
6164
warning("The response is binary and will not be converted to text.")

samples/client/petstore/R/R/api_response.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ApiResponse <- R6::R6Class(
5656
#' @param to_encoding The target encoding of the return value.
5757
#' @export
5858
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
59+
if (is.null(self$response)) {
60+
self$response <- charToRaw(jsonlite::toJSON("NULL"))
61+
}
5962
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
6063
if (is.na(text_response)) {
6164
warning("The response is binary and will not be converted to text.")

0 commit comments

Comments
 (0)