Skip to content

Commit

Permalink
allow api response to be NULL and regenerate samples (#18141)
Browse files Browse the repository at this point in the history
  • Loading branch information
joXemMx authored Mar 19, 2024
1 parent ddb5ab4 commit 5f49a04
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 5f49a04

Please sign in to comment.