Skip to content

Commit

Permalink
allow api response to be NULL and regenerate samples (OpenAPITools#18141
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joXemMx authored and zapodot committed Mar 21, 2024
1 parent 829b953 commit bbe7ac1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions samples/client/echo_api/r/R/api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/R-httr2-wrapper/R/api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/R-httr2/R/api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/R/R/api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit bbe7ac1

Please sign in to comment.