Skip to content

Commit

Permalink
fix R tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpollock committed Nov 20, 2024
1 parent 47c9dca commit 09a5f4e
Show file tree
Hide file tree
Showing 29 changed files with 551 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ApiResponse <- R6::R6Class(
#'
#' @param from_encoding The encoding of the raw response.
#' @param to_encoding The target encoding of the return value.
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
ResponseAsText = function(from_encoding = "", to_encoding = "UTF-8") {
if (is.null(self$response)) {
self$response <- charToRaw(jsonlite::toJSON("NULL"))
}
Expand Down
11 changes: 6 additions & 5 deletions modules/openapi-generator/src/main/resources/r/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,12 @@
local_var_resp$content <- NULL
{{/returnType}}
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}
local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
{{#returnExceptionOnFailure}}
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- paste("Server returned ", local_var_resp$status_code, " response status code.")
}
Expand All @@ -597,7 +600,6 @@
{{/returnExceptionOnFailure}}
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
{{#returnExceptionOnFailure}}
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api client exception encountered."
}
Expand All @@ -615,7 +617,6 @@
{{/returnExceptionOnFailure}}
} else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
{{#returnExceptionOnFailure}}
local_var_error_msg <- local_var_resp$response
if (local_var_error_msg == "") {
local_var_error_msg <- "Api server exception encountered."
}
Expand Down Expand Up @@ -676,7 +677,7 @@
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ ApiException <- R6::R6Class(
initialize = function(status = NULL, reason = NULL, http_response = NULL) {
if (!is.null(http_response)) {
self$status <- http_response$status_code
errorMsg <- http_response$response
errorMsg <- http_response$ResponseAsText()
if (is.null(errorMsg) || errorMsg == "") {
errorMsg <- "Api exception encountered. No details given."
}
self$body <- errorMsg
self$headers <- http_response$headers
self$reason <- http_response$http_status_desc
{{#errorObjectType}}
self$error_object <- {{errorObjectType}}$new()$fromJSONString(http_response$response)
self$error_object <- {{errorObjectType}}$new()$fromJSONString(http_response$ResponseAsText())
{{/errorObjectType}}
} else {
self$status <- status
Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/r/R/api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ApiResponse <- R6::R6Class(
#'
#' @param from_encoding The encoding of the raw response.
#' @param to_encoding The target encoding of the return value.
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
ResponseAsText = function(from_encoding = "", to_encoding = "UTF-8") {
if (is.null(self$response)) {
self$response <- charToRaw(jsonlite::toJSON("NULL"))
}
Expand Down
12 changes: 9 additions & 3 deletions samples/client/echo_api/r/R/auth_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ AuthApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -232,7 +235,10 @@ AuthApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -282,7 +288,7 @@ AuthApi <- R6::R6Class(
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
52 changes: 41 additions & 11 deletions samples/client/echo_api/r/R/body_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -339,7 +342,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -431,7 +437,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -519,7 +528,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -612,7 +624,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -705,7 +720,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -798,7 +816,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -891,7 +912,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -984,7 +1008,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -1077,7 +1104,10 @@ BodyApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -1127,7 +1157,7 @@ BodyApi <- R6::R6Class(
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
17 changes: 13 additions & 4 deletions samples/client/echo_api/r/R/form_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ FormApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -260,7 +263,10 @@ FormApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -368,7 +374,10 @@ FormApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -418,7 +427,7 @@ FormApi <- R6::R6Class(
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
7 changes: 5 additions & 2 deletions samples/client/echo_api/r/R/header_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ HeaderApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -200,7 +203,7 @@ HeaderApi <- R6::R6Class(
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
7 changes: 5 additions & 2 deletions samples/client/echo_api/r/R/path_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ PathApi <- R6::R6Class(
)
local_var_resp$content <- deserialized_resp_obj
return(local_var_resp)
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
}

local_var_error_msg <- local_var_resp$ResponseAsText()
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
ApiResponse$new("API client error", local_var_resp)
Expand Down Expand Up @@ -218,7 +221,7 @@ PathApi <- R6::R6Class(
#' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
#' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
Deserialize = function(local_var_resp, return_type = NULL) {
text <- local_var_resp$response_as_text()
text <- local_var_resp$ResponseAsText()
if (is.na(text)) {
return(local_var_resp$response)
} else if (is.null(return_type)) {
Expand Down
Loading

0 comments on commit 09a5f4e

Please sign in to comment.