William Cheng d810d7c534
R echo client tests (#17629)
* add r echo api client sample

* add r workflow

* fix

* add env

* set r version

* install curl

* install dep

* fix

* comment out installation
2024-01-18 09:05:35 +08:00

212 lines
8.0 KiB
R

#' Echo Server API
#'
#' Echo Server API
#'
#' The version of the OpenAPI document: 0.1.0
#' Contact: team@openapitools.org
#' Generated by: https://openapi-generator.tech
#'
#' @docType class
#' @title Path operations
#' @description PathApi
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath } \emph{ Test path parameter(s) }
#' Test path parameter(s)
#'
#' \itemize{
#' \item \emph{ @param } path_string character
#' \item \emph{ @param } path_integer integer
#' \item \emph{ @param } enum_nonref_string_path Enum < [success, failure, unclassified] >
#' \item \emph{ @param } enum_ref_string_path \link{StringEnumRef}
#'
#'
#' \item status code : 200 | Successful operation
#'
#' \item return type : character
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' #################### TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath ####################
#'
#' library(openapi)
#' var_path_string <- "path_string_example" # character |
#' var_path_integer <- 56 # integer |
#' var_enum_nonref_string_path <- "enum_nonref_string_path_example" # character |
#' var_enum_ref_string_path <- StringEnumRef$new() # StringEnumRef |
#'
#' #Test path parameter(s)
#' api_instance <- PathApi$new()
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(var_path_string, var_path_integer, var_enum_nonref_string_path, var_enum_ref_string_pathdata_file = "result.txt")
#' result <- api_instance$TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(var_path_string, var_path_integer, var_enum_nonref_string_path, var_enum_ref_string_path)
#' dput(result)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
PathApi <- R6::R6Class(
"PathApi",
public = list(
api_client = NULL,
#' Initialize a new PathApi.
#'
#' @description
#' Initialize a new PathApi.
#'
#' @param api_client An instance of API client.
#' @export
initialize = function(api_client) {
if (!missing(api_client)) {
self$api_client <- api_client
} else {
self$api_client <- ApiClient$new()
}
},
#' Test path parameter(s)
#'
#' @description
#' Test path parameter(s)
#'
#' @param path_string
#' @param path_integer
#' @param enum_nonref_string_path
#' @param enum_ref_string_path
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return character
#' @export
TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath = function(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = NULL, ...) {
local_var_response <- self$TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = data_file, ...)
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
local_var_response$content
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
local_var_response
} else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
local_var_response
} else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
local_var_response
}
},
#' Test path parameter(s)
#'
#' @description
#' Test path parameter(s)
#'
#' @param path_string
#' @param path_integer
#' @param enum_nonref_string_path
#' @param enum_ref_string_path
#' @param data_file (optional) name of the data file to save the result
#' @param ... Other optional arguments
#' @return API response (character) with additional information such as HTTP status code, headers
#' @export
TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo = function(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = NULL, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
form_params <- list()
file_params <- list()
local_var_body <- NULL
oauth_scopes <- NULL
is_oauth <- FALSE
if (missing(`path_string`)) {
stop("Missing required parameter `path_string`.")
}
if (missing(`path_integer`)) {
stop("Missing required parameter `path_integer`.")
}
if (missing(`enum_nonref_string_path`)) {
stop("Missing required parameter `enum_nonref_string_path`.")
}
if (missing(`enum_ref_string_path`)) {
stop("Missing required parameter `enum_ref_string_path`.")
}
local_var_url_path <- "/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}"
if (!missing(`path_string`)) {
local_var_url_path <- gsub("\\{path_string\\}", URLencode(as.character(`path_string`), reserved = TRUE), local_var_url_path)
}
if (!missing(`path_integer`)) {
local_var_url_path <- gsub("\\{path_integer\\}", URLencode(as.character(`path_integer`), reserved = TRUE), local_var_url_path)
}
if (!missing(`enum_nonref_string_path`)) {
local_var_url_path <- gsub("\\{enum_nonref_string_path\\}", URLencode(as.character(`enum_nonref_string_path`), reserved = TRUE), local_var_url_path)
}
if (!missing(`enum_ref_string_path`)) {
local_var_url_path <- gsub("\\{enum_ref_string_path\\}", URLencode(as.character(`enum_ref_string_path`), reserved = TRUE), local_var_url_path)
}
# The Accept request HTTP header
local_var_accepts <- list("text/plain")
# The Content-Type representation header
local_var_content_types <- list()
local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
method = "GET",
query_params = query_params,
header_params = header_params,
form_params = form_params,
file_params = file_params,
accepts = local_var_accepts,
content_types = local_var_content_types,
body = local_var_body,
is_oauth = is_oauth,
oauth_scopes = oauth_scopes,
...)
if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
# save response in a file
if (!is.null(data_file)) {
write(local_var_resp$response, data_file)
}
deserialized_resp_obj <- tryCatch(
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
error = function(e) {
stop("Failed to deserialize response")
}
)
local_var_resp$content <- deserialized_resp_obj
local_var_resp
} else 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)
} else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
if (is.null(local_var_resp$response) || local_var_resp$response == "") {
local_var_resp$response <- "API server error"
}
local_var_resp
}
}
)
)