[R] improve code format (#12387)

* better code format for r client

* more code format improvement
This commit is contained in:
William Cheng 2022-05-25 18:02:52 +08:00 committed by GitHub
parent 621f87b5e6
commit 7b08aa408d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 704 additions and 721 deletions

View File

@ -6,11 +6,11 @@
#' @field response The raw response from the endpoint. #' @field response The raw response from the endpoint.
#' @export #' @export
ApiResponse <- R6::R6Class( ApiResponse <- R6::R6Class(
'ApiResponse', "ApiResponse",
public = list( public = list(
content = NULL, content = NULL,
response = NULL, response = NULL,
initialize = function(content, response){ initialize = function(content, response) {
self$content <- content self$content <- content
self$response <- response self$response <- response
} }

View File

@ -4,7 +4,7 @@
#' @title {{baseName}} operations #' @title {{baseName}} operations
#' @description {{importPath}} #' @description {{importPath}}
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication. #' @field api_client Handles the client-server communication.
#' #'
#' @section Methods: #' @section Methods:
{{! Adding the below changes for generating documentation for the api methods. }} {{! Adding the below changes for generating documentation for the api methods. }}
@ -97,17 +97,17 @@
{{#isBasic}} {{#isBasic}}
#' #Configure HTTP basic authorization: {{{name}}} #' #Configure HTTP basic authorization: {{{name}}}
#' # provide your username in the user-serial format #' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; #' api.instance$api_client$username <- '<user-serial>';
#' # provide your api key generated using the developer portal #' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>'; #' api.instance$api_client$password <- '<api_key>';
{{/isBasic}} {{/isBasic}}
{{#isApiKey}} {{#isApiKey}}
#' #Configure API key authorization: {{{name}}} #' #Configure API key authorization: {{{name}}}
#' api.instance$apiClient$apiKeys['{{{keyParamName}}}'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['{{{keyParamName}}}'] <- 'TODO_YOUR_API_KEY';
{{/isApiKey}} {{/isApiKey}}
{{#isOAuth}} {{#isOAuth}}
#' # Configure OAuth2 access token for authorization: {{{name}}} #' # Configure OAuth2 access token for authorization: {{{name}}}
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
{{/isOAuth}} {{/isOAuth}}
{{/authMethods}} {{/authMethods}}
{{/hasAuthMethods}} {{/hasAuthMethods}}
@ -147,36 +147,36 @@
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
#' @export #' @export
{{classname}} <- R6::R6Class( {{classname}} <- R6::R6Class(
'{{classname}}', "{{classname}}",
public = list( public = list(
apiClient = NULL, api_client = NULL,
initialize = function(apiClient){ initialize = function(api_client) {
if (!missing(apiClient)) { if (!missing(api_client)) {
self$apiClient <- apiClient self$api_client <- api_client
} }
else { else {
self$apiClient <- ApiClient$new() self$api_client <- ApiClient$new()
} }
}, },
{{#operation}} {{#operation}}
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file=NULL, {{/returnType}}...){ {{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file=NULL, {{/returnType}}...) {
apiResponse <- self${{{operationId}}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}{{#returnType}}data_file=data_file, {{/returnType}}...) api_response <- self${{{operationId}}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}{{#returnType}}data_file = data_file, {{/returnType}}...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
{{{operationId}}}WithHttpInfo = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file=NULL, {{/returnType}}...){ {{{operationId}}}WithHttpInfo = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file = NULL, {{/returnType}}...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
{{#requiredParams}} {{#requiredParams}}
if (missing(`{{paramName}}`)) { if (missing(`{{paramName}}`)) {
@ -189,14 +189,14 @@
} }
{{/requiredParams}} {{/requiredParams}}
{{#headerParams}} {{#header_params}}
headerParams['{{baseName}}'] <- `{{paramName}}` header_params["{{baseName}}"] <- `{{paramName}}`
{{/headerParams}} {{/header_params}}
{{#queryParams}} {{#query_params}}
queryParams['{{baseName}}'] <- {{paramName}} query_params["{{baseName}}"] <- {{paramName}}
{{/queryParams}} {{/query_params}}
{{#hasFormParams}} {{#hasFormParams}}
body <- list( body <- list(
{{#formParams}} {{#formParams}}
@ -214,8 +214,8 @@
{{#bodyParams}} {{#bodyParams}}
if (!missing(`{{paramName}}`)) { if (!missing(`{{paramName}}`)) {
{{#isArray}} {{#isArray}}
body.items = paste(unlist(lapply({{paramName}}, function(param){param$toJSONString()})), collapse = ",") body.items = paste(unlist(lapply({{paramName}}, function(param) {param$toJSONString()})), collapse = ",")
body <- paste0('[', body.items, ']') body <- paste0("[", body.items, "]")
{{/isArray}} {{/isArray}}
{{^isArray}} {{^isArray}}
body <- `{{paramName}}`$toJSONString() body <- `{{paramName}}`$toJSONString()
@ -231,11 +231,11 @@
body <- NULL body <- NULL
{{/hasFormParams}} {{/hasFormParams}}
{{/hasBodyParam}} {{/hasBodyParam}}
urlPath <- "{{path}}" url_path <- "{{path}}"
{{#hasPathParams}} {{#hasPathParams}}
{{#pathParams}} {{#pathParams}}
if (!missing(`{{paramName}}`)) { if (!missing(`{{paramName}}`)) {
urlPath <- gsub(paste0("\\{", "{{baseName}}", "\\}"), URLencode(as.character(`{{paramName}}`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "{{baseName}}", "\\}"), URLencode(as.character(`{{paramName}}`), reserved = TRUE), url_path)
} }
{{/pathParams}} {{/pathParams}}
@ -244,32 +244,32 @@
{{#isBasic}} {{#isBasic}}
{{#isBasicBasic}} {{#isBasicBasic}}
# HTTP basic auth # HTTP basic auth
headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, sep=":")))) header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":"))))
{{/isBasicBasic}} {{/isBasicBasic}}
{{/isBasic}} {{/isBasic}}
{{#isApiKey}} {{#isApiKey}}
# API key authentication # API key authentication
{{#isKeyInHeader}} {{#isKeyInHeader}}
if ("{{{keyParamName}}}" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["{{{keyParamName}}}"]) > 0) { if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) {
headerParams['{{keyParamName}}'] <- paste(unlist(self$apiClient$apiKeys["{{keyParamName}}"]), collapse='') header_params["{{keyParamName}}"] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse = "")
} }
{{/isKeyInHeader}} {{/isKeyInHeader}}
{{#isKeyInQuery}} {{#isKeyInQuery}}
if ("{{{keyParamName}}}" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["{{{keyParamName}}}"]) > 0) { if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) {
queryParams['{{keyParamName}}'] <- paste(unlist(self$apiClient$apiKeys["{{keyParamName}}"]), collapse='') query_params["{{keyParamName}}"] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse = "")
} }
{{/isKeyInQuery}} {{/isKeyInQuery}}
{{/isApiKey}} {{/isApiKey}}
{{#isOAuth}} {{#isOAuth}}
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
{{/isOAuth}} {{/isOAuth}}
{{/authMethods}} {{/authMethods}}
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "{{httpMethod}}", method = "{{httpMethod}}",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -292,9 +292,9 @@
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")), self$api_client$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")),
error = function(e){ error = function(e) {
{{#useDefaultExceptionHandling}} {{#useDefaultExceptionHandling}}
stop("Failed to deserialize response") stop("Failed to deserialize response")
{{/useDefaultExceptionHandling}} {{/useDefaultExceptionHandling}}
@ -303,7 +303,7 @@
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/returnType}} {{/returnType}}
{{^returnType}} {{^returnType}}
@ -312,31 +312,31 @@
{{/returnType}} {{/returnType}}
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
{{#returnExceptionOnFailure}} {{#returnExceptionOnFailure}}
errorMsg <- toString(content(resp)) error_msg <- toString(content(resp))
if(errorMsg == ""){ if(error_msg == "") {
errorMsg <- paste("Server returned " , httr::status_code(resp) , " response status code.") error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.")
} }
{{#useDefaultExceptionHandling}} {{#useDefaultExceptionHandling}}
stop(errorMsg) stop(error_msg)
{{/useDefaultExceptionHandling}} {{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}} {{#useRlangExceptionHandling}}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}} {{/returnExceptionOnFailure}}
{{^returnExceptionOnFailure}} {{^returnExceptionOnFailure}}
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
{{/returnExceptionOnFailure}} {{/returnExceptionOnFailure}}
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
{{#returnExceptionOnFailure}} {{#returnExceptionOnFailure}}
errorMsg <- toString(content(resp)) error_msg <- toString(content(resp))
if(errorMsg == ""){ if(error_msg == "") {
errorMsg <- "Api client exception encountered." error_msg <- "Api client exception encountered."
} }
{{#useDefaultExceptionHandling}} {{#useDefaultExceptionHandling}}
stop(errorMsg) stop(error_msg)
{{/useDefaultExceptionHandling}} {{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}} {{#useRlangExceptionHandling}}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}} {{/returnExceptionOnFailure}}
{{^returnExceptionOnFailure}} {{^returnExceptionOnFailure}}
@ -344,15 +344,15 @@
{{/returnExceptionOnFailure}} {{/returnExceptionOnFailure}}
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
{{#returnExceptionOnFailure}} {{#returnExceptionOnFailure}}
errorMsg <- toString(content(resp)) error_msg <- toString(content(resp))
if(errorMsg == ""){ if(error_msg == "") {
errorMsg <- "Api server exception encountered." error_msg <- "Api server exception encountered."
} }
{{#useDefaultExceptionHandling}} {{#useDefaultExceptionHandling}}
stop(errorMsg) stop(error_msg)
{{/useDefaultExceptionHandling}} {{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}} {{#useRlangExceptionHandling}}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp)) rlang::abort(message = error_msg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}} {{/returnExceptionOnFailure}}
{{^returnExceptionOnFailure}} {{^returnExceptionOnFailure}}

View File

@ -16,52 +16,55 @@
#' @title ApiClient #' @title ApiClient
#' @description ApiClient Class #' @description ApiClient Class
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field basePath Base url #' @field base_path Base url
#' @field userAgent Default user agent #' @field user_agent Default user agent
#' @field defaultHeaders #' @field default_headers
#' @field username Username for HTTP basic authentication #' @field username Username for HTTP basic authentication
#' @field password Password for HTTP basic authentication #' @field password Password for HTTP basic authentication
#' @field apiKeys #' @field api_keys
#' @field accessToken #' @field access_token
#' @field timeout Default timeout in seconds #' @field timeout Default timeout in seconds
#' @field retryStatusCodes vector of status codes to retry #' @field retry_status_codes vector of status codes to retry
#' @field maxRetryAttempts maximum number of retries for the status codes #' @field max_retry_attempts maximum number of retries for the status codes
#' @importFrom httr add_headers accept timeout content #' @importFrom httr add_headers accept timeout content
{{#useRlangExceptionHandling}} {{#useRlangExceptionHandling}}
#' @importFrom rlang abort #' @importFrom rlang abort
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
#' @export #' @export
ApiClient <- R6::R6Class( ApiClient <- R6::R6Class(
'ApiClient', "ApiClient",
public = list( public = list(
# base path of all requests # base path of all requests
basePath = "{{{basePath}}}", base_path = "{{{basePath}}}",
# user agent in the HTTP request # user agent in the HTTP request
userAgent = "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}", user_agent = "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}",
# default headers in the HTTP request # default headers in the HTTP request
defaultHeaders = NULL, default_headers = NULL,
# username (HTTP basic authentication) # username (HTTP basic authentication)
username = NULL, username = NULL,
# password (HTTP basic authentication) # password (HTTP basic authentication)
password = NULL, password = NULL,
# API keys # API keys
apiKeys = NULL, api_keys = NULL,
# Access token # Access token
accessToken = NULL, access_token = NULL,
# Time Out (seconds) # Time Out (seconds)
timeout = NULL, timeout = NULL,
# Vector of status codes to retry # Vector of status codes to retry
retryStatusCodes=NULL, retry_status_codes = NULL,
# Maximum number of retry attempts for the retry status codes # Maximum number of retry attempts for the retry status codes
maxRetryAttempts = NULL, max_retry_attempts = NULL,
# constructor # constructor
initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL, timeout=NULL, retryStatusCodes=NULL, maxRetryAttempts=NULL){ initialize = function(base_path=NULL, user_agent=NULL, default_headers=NULL,
if (!is.null(basePath)) { username=NULL, password=NULL, api_keys=NULL,
self$basePath <- basePath access_token=NULL, timeout=NULL,
retry_status_codes=NULL, max_retry_attempts=NULL) {
if (!is.null(base_path)) {
self$base_path <- base_path
} }
if (!is.null(defaultHeaders)) { if (!is.null(default_headers)) {
self$defaultHeaders <- defaultHeaders self$default_headers <- default_headers
} }
if (!is.null(username)) { if (!is.null(username)) {
@ -72,49 +75,49 @@ ApiClient <- R6::R6Class(
self$password <- password self$password <- password
} }
if (!is.null(accessToken)) { if (!is.null(access_token)) {
self$accessToken <- accessToken self$access_token <- access_token
} }
if (!is.null(apiKeys)) { if (!is.null(api_keys)) {
self$apiKeys <- apiKeys self$api_keys <- api_keys
} else { } else {
self$apiKeys <- list() self$api_keys <- list()
} }
if (!is.null(userAgent)) { if (!is.null(user_agent)) {
self$`userAgent` <- userAgent self$`user_agent` <- user_agent
} }
if (!is.null(timeout)) { if (!is.null(timeout)) {
self$timeout <- timeout self$timeout <- timeout
} }
if (!is.null(retryStatusCodes)) { if (!is.null(retry_status_codes)) {
self$retryStatusCodes <- retryStatusCodes self$retry_status_codes <- retry_status_codes
} }
if (!is.null(maxRetryAttempts)) { if (!is.null(max_retry_attempts)) {
self$maxRetryAttempts <- maxRetryAttempts self$max_retry_attempts <- max_retry_attempts
} }
}, },
CallApi = function(url, method, queryParams, headerParams, body, ...){ CallApi = function(url, method, query_params, header_params, body, ...) {
resp <- self$Execute(url, method, queryParams, headerParams, body, ...) resp <- self$Execute(url, method, query_params, header_params, body, ...)
statusCode <- httr::status_code(resp) status_code <- httr::status_code(resp)
if (is.null(self$maxRetryAttempts)) { if (is.null(self$max_retry_attempts)) {
self$maxRetryAttempts = 3 self$max_retry_attempts <- 3
} }
if (!is.null(self$retryStatusCodes)) { if (!is.null(self$retry_status_codes)) {
for (i in 1 : self$maxRetryAttempts) { for (i in 1 : self$max_retry_attempts) {
if (statusCode %in% self$retryStatusCodes) { if (status_code %in% self$retry_status_codes) {
Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1))
resp <- self$Execute(url, method, queryParams, headerParams, body, ...) resp <- self$Execute(url, method, query_params, header_params, body, ...)
statusCode <- httr::status_code(resp) status_code <- httr::status_code(resp)
} else { } else {
break; break;
} }
@ -124,78 +127,78 @@ ApiClient <- R6::R6Class(
resp resp
}, },
Execute = function(url, method, queryParams, headerParams, body, ...){ Execute = function(url, method, query_params, header_params, body, ...) {
headers <- httr::add_headers(c(headerParams, self$defaultHeaders)) headers <- httr::add_headers(c(header_params, self$default_headers))
{{! Adding timeout that can be set at the apiClient object level}} {{! Adding timeout that can be set at the apiClient object level}}
httpTimeout <- NULL http_timeout <- NULL
if (!is.null(self$timeout)) { if (!is.null(self$timeout)) {
httpTimeout <- httr::timeout(self$timeout) http_timeout <- httr::timeout(self$timeout)
} }
if (method == "GET") { if (method == "GET") {
httr::GET(url, query = queryParams, headers, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::GET(url, query = query_params, headers, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "POST") { } else if (method == "POST") {
httr::POST(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::POST(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "PUT") { } else if (method == "PUT") {
httr::PUT(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::PUT(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "PATCH") { } else if (method == "PATCH") {
httr::PATCH(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::PATCH(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "HEAD") { } else if (method == "HEAD") {
httr::HEAD(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::HEAD(url, query = query_params, headers, http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "DELETE") { } else if (method == "DELETE") {
httr::DELETE(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::DELETE(url, query = query_params, headers, http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else { } else {
errMsg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." err_msg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`."
{{#useDefaultExceptionHandling}} {{#useDefaultExceptionHandling}}
stop(errMsg) stop(err_msg)
{{/useDefaultExceptionHandling}} {{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}} {{#useRlangExceptionHandling}}
rlang::abort(message = errMsg, .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = errMsg)) rlang::abort(message = err_msg, .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = err_msg))
{{/useRlangExceptionHandling}} {{/useRlangExceptionHandling}}
} }
}, },
# Deserialize the content of api response to the given type. # Deserialize the content of api response to the given type.
deserialize = function(resp, returnType, pkgEnv) { deserialize = function(resp, return_type, pkg_env) {
respObj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) resp_obj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
self$deserializeObj(respObj, returnType, pkgEnv) self$deserializeObj(resp_obj, return_type, pkg_env)
}, },
# Deserialize the response from jsonlite object based on the given type # Deserialize the response from jsonlite object based on the given type
# by handling complex and nested types by iterating recursively # by handling complex and nested types by iterating recursively
# Example returnTypes will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc., # Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc.,
deserializeObj = function(obj, returnType, pkgEnv) { deserializeObj = function(obj, return_type, pkg_env) {
returnObj <- NULL return_obj <- NULL
primitiveTypes <- c("character", "numeric", "integer", "logical", "complex") primitive_types <- c("character", "numeric", "integer", "logical", "complex")
# To handle the "map" type # To handle the "map" type
if (startsWith(returnType, "map(")) { if (startsWith(return_type, "map(")) {
innerReturnType <- regmatches(returnType, regexec(pattern = "map\\((.*)\\)", returnType))[[1]][2] inner_return_type <- regmatches(return_type, regexec(pattern = "map\\((.*)\\)", return_type))[[1]][2]
returnObj <- lapply(names(obj), function(name) { return_obj <- lapply(names(obj), function(name) {
self$deserializeObj(obj[[name]], innerReturnType, pkgEnv) self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
}) })
names(returnObj) <- names(obj) names(return_obj) <- names(obj)
} }
# To handle the "array" type # To handle the "array" type
else if (startsWith(returnType, "array[")) { else if (startsWith(return_type, "array[")) {
innerReturnType <- regmatches(returnType, regexec(pattern = "array\\[(.*)\\]", returnType))[[1]][2] inner_return_type <- regmatches(return_type, regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
if (c(innerReturnType) %in% primitiveTypes) { if (c(inner_return_type) %in% primitive_types) {
returnObj <- vector("list", length = length(obj)) return_obj <- vector("list", length = length(obj))
if (length(obj) > 0) { if (length(obj) > 0) {
for (row in 1:length(obj)) { for (row in 1:length(obj)) {
returnObj[[row]] <- self$deserializeObj(obj[row], innerReturnType, pkgEnv) return_obj[[row]] <- self$deserializeObj(obj[row], inner_return_type, pkg_env)
} }
} }
} else { } else {
if(!is.null(nrow(obj))){ if (!is.null(nrow(obj))) {
returnObj <- vector("list", length = nrow(obj)) return_obj <- vector("list", length = nrow(obj))
if (nrow(obj) > 0) { if (nrow(obj) > 0) {
for (row in 1:nrow(obj)) { for (row in 1:nrow(obj)) {
returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) return_obj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], inner_return_type, pkg_env)
} }
} }
} }
@ -203,19 +206,19 @@ ApiClient <- R6::R6Class(
} }
# To handle model objects which are not array or map containers. Ex:"Pet" # To handle model objects which are not array or map containers. Ex:"Pet"
else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { else if (exists(return_type, pkg_env) && !(c(return_type) %in% primitive_types)) {
returnType <- get(returnType, envir = as.environment(pkgEnv)) return_type <- get(return_type, envir = as.environment(pkg_env))
returnObj <- returnType$new() return_obj <- return_type$new()
returnObj$fromJSON( return_obj$fromJSON(
jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE)
) )
} }
# To handle primitive type # To handle primitive type
else { else {
returnObj <- obj return_obj <- obj
} }
returnObj return_obj
} }
) )
) )

View File

@ -3,10 +3,10 @@
context("Test {{{classname}}}") context("Test {{{classname}}}")
api.instance <- {{{classname}}}$new() api_instance <- {{{classname}}}$new()
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
test_that("{{{operationId}}}", { test_that("{{{operationId}}}", {
# tests for {{operationId}} # tests for {{operationId}}
# base path: {{{basePath}}} # base path: {{{basePath}}}
@ -24,6 +24,5 @@ test_that("{{{operationId}}}", {
# uncomment below to test the operation # uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT") #expect_equal(result, "EXPECTED_RESULT")
}) })
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

@ -8,9 +8,9 @@ context("Test {{{classname}}}")
{{#vars}} {{#vars}}
{{#-first}} {{#-first}}
model.instance <- {{{classname}}}$new() model_instance <- {{{classname}}}$new()
{{/-first}} {{/-first}}
test_that("{{{name}}}", { test_that("{{{name}}}", {
# tests for the property `{{{name}}}` ({{dataType}}) # tests for the property `{{{name}}}` ({{dataType}})
{{#description}} {{#description}}
@ -20,7 +20,6 @@ test_that("{{{name}}}", {
# uncomment below to test the property # uncomment below to test the property
#expect_equal(model.instance$`{{{name}}}`, "EXPECTED_RESULT") #expect_equal(model.instance$`{{{name}}}`, "EXPECTED_RESULT")
}) })
{{/vars}} {{/vars}}
{{/isEnum}} {{/isEnum}}
{{/model}} {{/model}}

View File

@ -6,6 +6,10 @@
# {{{.}}} # {{{.}}}
# #
{{/appDescription}} {{/appDescription}}
# {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}} {{#version}}
# {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}} # The version of the OpenAPI document: {{{.}}}
{{/version}}
{{#infoEmail}}
# Contact: {{{.}}}
{{/infoEmail}}
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
@ -23,49 +22,52 @@
#' @title ApiClient #' @title ApiClient
#' @description ApiClient Class #' @description ApiClient Class
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field basePath Base url #' @field base_path Base url
#' @field userAgent Default user agent #' @field user_agent Default user agent
#' @field defaultHeaders #' @field default_headers
#' @field username Username for HTTP basic authentication #' @field username Username for HTTP basic authentication
#' @field password Password for HTTP basic authentication #' @field password Password for HTTP basic authentication
#' @field apiKeys #' @field api_keys
#' @field accessToken #' @field access_token
#' @field timeout Default timeout in seconds #' @field timeout Default timeout in seconds
#' @field retryStatusCodes vector of status codes to retry #' @field retry_status_codes vector of status codes to retry
#' @field maxRetryAttempts maximum number of retries for the status codes #' @field max_retry_attempts maximum number of retries for the status codes
#' @importFrom httr add_headers accept timeout content #' @importFrom httr add_headers accept timeout content
#' @export #' @export
ApiClient <- R6::R6Class( ApiClient <- R6::R6Class(
'ApiClient', "ApiClient",
public = list( public = list(
# base path of all requests # base path of all requests
basePath = "http://petstore.swagger.io/v2", base_path = "http://petstore.swagger.io/v2",
# user agent in the HTTP request # user agent in the HTTP request
userAgent = "PetstoreAgent", user_agent = "PetstoreAgent",
# default headers in the HTTP request # default headers in the HTTP request
defaultHeaders = NULL, default_headers = NULL,
# username (HTTP basic authentication) # username (HTTP basic authentication)
username = NULL, username = NULL,
# password (HTTP basic authentication) # password (HTTP basic authentication)
password = NULL, password = NULL,
# API keys # API keys
apiKeys = NULL, api_keys = NULL,
# Access token # Access token
accessToken = NULL, access_token = NULL,
# Time Out (seconds) # Time Out (seconds)
timeout = NULL, timeout = NULL,
# Vector of status codes to retry # Vector of status codes to retry
retryStatusCodes=NULL, retry_status_codes = NULL,
# Maximum number of retry attempts for the retry status codes # Maximum number of retry attempts for the retry status codes
maxRetryAttempts = NULL, max_retry_attempts = NULL,
# constructor # constructor
initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL, timeout=NULL, retryStatusCodes=NULL, maxRetryAttempts=NULL){ initialize = function(base_path=NULL, user_agent=NULL, default_headers=NULL,
if (!is.null(basePath)) { username=NULL, password=NULL, api_keys=NULL,
self$basePath <- basePath access_token=NULL, timeout=NULL,
retry_status_codes=NULL, max_retry_attempts=NULL) {
if (!is.null(base_path)) {
self$base_path <- base_path
} }
if (!is.null(defaultHeaders)) { if (!is.null(default_headers)) {
self$defaultHeaders <- defaultHeaders self$default_headers <- default_headers
} }
if (!is.null(username)) { if (!is.null(username)) {
@ -76,49 +78,49 @@ ApiClient <- R6::R6Class(
self$password <- password self$password <- password
} }
if (!is.null(accessToken)) { if (!is.null(access_token)) {
self$accessToken <- accessToken self$access_token <- access_token
} }
if (!is.null(apiKeys)) { if (!is.null(api_keys)) {
self$apiKeys <- apiKeys self$api_keys <- api_keys
} else { } else {
self$apiKeys <- list() self$api_keys <- list()
} }
if (!is.null(userAgent)) { if (!is.null(user_agent)) {
self$`userAgent` <- userAgent self$`user_agent` <- user_agent
} }
if (!is.null(timeout)) { if (!is.null(timeout)) {
self$timeout <- timeout self$timeout <- timeout
} }
if (!is.null(retryStatusCodes)) { if (!is.null(retry_status_codes)) {
self$retryStatusCodes <- retryStatusCodes self$retry_status_codes <- retry_status_codes
} }
if (!is.null(maxRetryAttempts)) { if (!is.null(max_retry_attempts)) {
self$maxRetryAttempts <- maxRetryAttempts self$max_retry_attempts <- max_retry_attempts
} }
}, },
CallApi = function(url, method, queryParams, headerParams, body, ...){ CallApi = function(url, method, query_params, header_params, body, ...) {
resp <- self$Execute(url, method, queryParams, headerParams, body, ...) resp <- self$Execute(url, method, query_params, header_params, body, ...)
statusCode <- httr::status_code(resp) status_code <- httr::status_code(resp)
if (is.null(self$maxRetryAttempts)) { if (is.null(self$max_retry_attempts)) {
self$maxRetryAttempts = 3 self$max_retry_attempts <- 3
} }
if (!is.null(self$retryStatusCodes)) { if (!is.null(self$retry_status_codes)) {
for (i in 1 : self$maxRetryAttempts) { for (i in 1 : self$max_retry_attempts) {
if (statusCode %in% self$retryStatusCodes) { if (status_code %in% self$retry_status_codes) {
Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1))
resp <- self$Execute(url, method, queryParams, headerParams, body, ...) resp <- self$Execute(url, method, query_params, header_params, body, ...)
statusCode <- httr::status_code(resp) status_code <- httr::status_code(resp)
} else { } else {
break; break;
} }
@ -128,72 +130,72 @@ ApiClient <- R6::R6Class(
resp resp
}, },
Execute = function(url, method, queryParams, headerParams, body, ...){ Execute = function(url, method, query_params, header_params, body, ...) {
headers <- httr::add_headers(c(headerParams, self$defaultHeaders)) headers <- httr::add_headers(c(header_params, self$default_headers))
httpTimeout <- NULL http_timeout <- NULL
if (!is.null(self$timeout)) { if (!is.null(self$timeout)) {
httpTimeout <- httr::timeout(self$timeout) http_timeout <- httr::timeout(self$timeout)
} }
if (method == "GET") { if (method == "GET") {
httr::GET(url, query = queryParams, headers, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::GET(url, query = query_params, headers, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "POST") { } else if (method == "POST") {
httr::POST(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::POST(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "PUT") { } else if (method == "PUT") {
httr::PUT(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::PUT(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "PATCH") { } else if (method == "PATCH") {
httr::PATCH(url, query = queryParams, headers, body = body, httr::content_type("application/json"), httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::PATCH(url, query = query_params, headers, body = body, httr::content_type("application/json"), http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "HEAD") { } else if (method == "HEAD") {
httr::HEAD(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::HEAD(url, query = query_params, headers, http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else if (method == "DELETE") { } else if (method == "DELETE") {
httr::DELETE(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...) httr::DELETE(url, query = query_params, headers, http_timeout, http_timeout, httr::user_agent(self$`user_agent`), ...)
} else { } else {
errMsg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." err_msg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`."
stop(errMsg) stop(err_msg)
} }
}, },
# Deserialize the content of api response to the given type. # Deserialize the content of api response to the given type.
deserialize = function(resp, returnType, pkgEnv) { deserialize = function(resp, return_type, pkg_env) {
respObj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) resp_obj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
self$deserializeObj(respObj, returnType, pkgEnv) self$deserializeObj(resp_obj, return_type, pkg_env)
}, },
# Deserialize the response from jsonlite object based on the given type # Deserialize the response from jsonlite object based on the given type
# by handling complex and nested types by iterating recursively # by handling complex and nested types by iterating recursively
# Example returnTypes will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc., # Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc.,
deserializeObj = function(obj, returnType, pkgEnv) { deserializeObj = function(obj, return_type, pkg_env) {
returnObj <- NULL return_obj <- NULL
primitiveTypes <- c("character", "numeric", "integer", "logical", "complex") primitive_types <- c("character", "numeric", "integer", "logical", "complex")
# To handle the "map" type # To handle the "map" type
if (startsWith(returnType, "map(")) { if (startsWith(return_type, "map(")) {
innerReturnType <- regmatches(returnType, regexec(pattern = "map\\((.*)\\)", returnType))[[1]][2] inner_return_type <- regmatches(return_type, regexec(pattern = "map\\((.*)\\)", return_type))[[1]][2]
returnObj <- lapply(names(obj), function(name) { return_obj <- lapply(names(obj), function(name) {
self$deserializeObj(obj[[name]], innerReturnType, pkgEnv) self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
}) })
names(returnObj) <- names(obj) names(return_obj) <- names(obj)
} }
# To handle the "array" type # To handle the "array" type
else if (startsWith(returnType, "array[")) { else if (startsWith(return_type, "array[")) {
innerReturnType <- regmatches(returnType, regexec(pattern = "array\\[(.*)\\]", returnType))[[1]][2] inner_return_type <- regmatches(return_type, regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
if (c(innerReturnType) %in% primitiveTypes) { if (c(inner_return_type) %in% primitive_types) {
returnObj <- vector("list", length = length(obj)) return_obj <- vector("list", length = length(obj))
if (length(obj) > 0) { if (length(obj) > 0) {
for (row in 1:length(obj)) { for (row in 1:length(obj)) {
returnObj[[row]] <- self$deserializeObj(obj[row], innerReturnType, pkgEnv) return_obj[[row]] <- self$deserializeObj(obj[row], inner_return_type, pkg_env)
} }
} }
} else { } else {
if(!is.null(nrow(obj))){ if (!is.null(nrow(obj))) {
returnObj <- vector("list", length = nrow(obj)) return_obj <- vector("list", length = nrow(obj))
if (nrow(obj) > 0) { if (nrow(obj) > 0) {
for (row in 1:nrow(obj)) { for (row in 1:nrow(obj)) {
returnObj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], innerReturnType, pkgEnv) return_obj[[row]] <- self$deserializeObj(obj[row, , drop = FALSE], inner_return_type, pkg_env)
} }
} }
} }
@ -201,19 +203,19 @@ ApiClient <- R6::R6Class(
} }
# To handle model objects which are not array or map containers. Ex:"Pet" # To handle model objects which are not array or map containers. Ex:"Pet"
else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { else if (exists(return_type, pkg_env) && !(c(return_type) %in% primitive_types)) {
returnType <- get(returnType, envir = as.environment(pkgEnv)) return_type <- get(return_type, envir = as.environment(pkg_env))
returnObj <- returnType$new() return_obj <- return_type$new()
returnObj$fromJSON( return_obj$fromJSON(
jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE)
) )
} }
# To handle primitive type # To handle primitive type
else { else {
returnObj <- obj return_obj <- obj
} }
returnObj return_obj
} }
) )
) )

View File

@ -6,11 +6,11 @@
#' @field response The raw response from the endpoint. #' @field response The raw response from the endpoint.
#' @export #' @export
ApiResponse <- R6::R6Class( ApiResponse <- R6::R6Class(
'ApiResponse', "ApiResponse",
public = list( public = list(
content = NULL, content = NULL,
response = NULL, response = NULL,
initialize = function(content, response){ initialize = function(content, response) {
self$content <- content self$content <- content
self$response <- response self$response <- response
} }

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,14 +3,13 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class
#' @title Fake operations #' @title Fake operations
#' @description petstore.Fake #' @description petstore.Fake
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication. #' @field api_client Handles the client-server communication.
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
@ -54,51 +53,47 @@
#' @importFrom base64enc base64encode #' @importFrom base64enc base64encode
#' @export #' @export
FakeApi <- R6::R6Class( FakeApi <- R6::R6Class(
'FakeApi', "FakeApi",
public = list( public = list(
apiClient = NULL, api_client = NULL,
initialize = function(apiClient){ initialize = function(api_client) {
if (!missing(apiClient)) { if (!missing(api_client)) {
self$apiClient <- apiClient self$api_client <- api_client
} }
else { else {
self$apiClient <- ApiClient$new() self$api_client <- ApiClient$new()
} }
}, },
FakeDataFile = function(dummy, var_data_file=NULL, data_file=NULL, ...){ FakeDataFile = function(dummy, var_data_file=NULL, data_file=NULL, ...) {
apiResponse <- self$FakeDataFileWithHttpInfo(dummy, var_data_file, data_file=data_file, ...) api_response <- self$FakeDataFileWithHttpInfo(dummy, var_data_file, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
FakeDataFileWithHttpInfo = function(dummy, var_data_file=NULL, data_file=NULL, ...){ FakeDataFileWithHttpInfo = function(dummy, var_data_file=NULL, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`dummy`)) { if (missing(`dummy`)) {
stop("Missing required parameter `dummy`.") stop("Missing required parameter `dummy`.")
} }
headerParams['dummy'] <- `dummy`
headerParams['data_file'] <- `var_data_file`
body <- NULL body <- NULL
urlPath <- "/fake/data_file" url_path <- "/fake/data_file"
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -108,15 +103,15 @@ FakeApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "User", loadNamespace("petstore")), self$api_client$deserialize(resp, "User", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,14 +3,13 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class
#' @title Pet operations #' @title Pet operations
#' @description petstore.Pet #' @description petstore.Pet
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication. #' @field api_client Handles the client-server communication.
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
@ -223,7 +222,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$AddPet(var.pet) #' result <- api.instance$AddPet(var.pet)
#' #'
@ -238,7 +237,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$DeletePet(var.pet_id, api_key=var.api_key) #' result <- api.instance$DeletePet(var.pet_id, api_key=var.api_key)
#' #'
@ -252,7 +251,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$FindPetsByStatus(var.status) #' result <- api.instance$FindPetsByStatus(var.status)
#' #'
@ -266,7 +265,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$FindPetsByTags(var.tags) #' result <- api.instance$FindPetsByTags(var.tags)
#' #'
@ -280,7 +279,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$GetPetById(var.pet_id) #' result <- api.instance$GetPetById(var.pet_id)
#' #'
@ -294,7 +293,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$UpdatePet(var.pet) #' result <- api.instance$UpdatePet(var.pet)
#' #'
@ -310,7 +309,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status) #' result <- api.instance$UpdatePetWithForm(var.pet_id, name=var.name, status=var.status)
#' #'
@ -326,7 +325,7 @@
#' api.instance <- PetApi$new() #' api.instance <- PetApi$new()
#' #'
#' # Configure OAuth2 access token for authorization: petstore_auth #' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN'; #' api.instance$api_client$access_token <- 'TODO_YOUR_ACCESS_TOKEN';
#' #'
#' result <- api.instance$UploadFile(var.pet_id, additional_metadata=var.additional_metadata, file=var.file) #' result <- api.instance$UploadFile(var.pet_id, additional_metadata=var.additional_metadata, file=var.file)
#' #'
@ -336,35 +335,35 @@
#' @importFrom base64enc base64encode #' @importFrom base64enc base64encode
#' @export #' @export
PetApi <- R6::R6Class( PetApi <- R6::R6Class(
'PetApi', "PetApi",
public = list( public = list(
apiClient = NULL, api_client = NULL,
initialize = function(apiClient){ initialize = function(api_client) {
if (!missing(apiClient)) { if (!missing(api_client)) {
self$apiClient <- apiClient self$api_client <- api_client
} }
else { else {
self$apiClient <- ApiClient$new() self$api_client <- ApiClient$new()
} }
}, },
AddPet = function(pet, data_file=NULL, ...){ AddPet = function(pet, data_file=NULL, ...) {
apiResponse <- self$AddPetWithHttpInfo(pet, data_file=data_file, ...) api_response <- self$AddPetWithHttpInfo(pet, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
AddPetWithHttpInfo = function(pet, data_file=NULL, ...){ AddPetWithHttpInfo = function(pet, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet`)) { if (missing(`pet`)) {
stop("Missing required parameter `pet`.") stop("Missing required parameter `pet`.")
@ -376,14 +375,14 @@ PetApi <- R6::R6Class(
body <- NULL body <- NULL
} }
urlPath <- "/pet" url_path <- "/pet"
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -393,106 +392,102 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "Pet", loadNamespace("petstore")), self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
DeletePet = function(pet_id, api_key=NULL, ...){ DeletePet = function(pet_id, api_key=NULL, ...) {
apiResponse <- self$DeletePetWithHttpInfo(pet_id, api_key, ...) api_response <- self$DeletePetWithHttpInfo(pet_id, api_key, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
DeletePetWithHttpInfo = function(pet_id, api_key=NULL, ...){ DeletePetWithHttpInfo = function(pet_id, api_key=NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet_id`)) { if (missing(`pet_id`)) {
stop("Missing required parameter `pet_id`.") stop("Missing required parameter `pet_id`.")
} }
headerParams['api_key'] <- `api_key`
body <- NULL body <- NULL
urlPath <- "/pet/{petId}" url_path <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), url_path)
} }
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "DELETE", method = "DELETE",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
FindPetsByStatus = function(status, data_file=NULL, ...){ FindPetsByStatus = function(status, data_file=NULL, ...) {
apiResponse <- self$FindPetsByStatusWithHttpInfo(status, data_file=data_file, ...) api_response <- self$FindPetsByStatusWithHttpInfo(status, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
FindPetsByStatusWithHttpInfo = function(status, data_file=NULL, ...){ FindPetsByStatusWithHttpInfo = function(status, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`status`)) { if (missing(`status`)) {
stop("Missing required parameter `status`.") stop("Missing required parameter `status`.")
} }
queryParams['status'] <- status
body <- NULL body <- NULL
urlPath <- "/pet/findByStatus" url_path <- "/pet/findByStatus"
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -502,55 +497,53 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
FindPetsByTags = function(tags, data_file=NULL, ...){ FindPetsByTags = function(tags, data_file=NULL, ...) {
apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, data_file=data_file, ...) api_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
FindPetsByTagsWithHttpInfo = function(tags, data_file=NULL, ...){ FindPetsByTagsWithHttpInfo = function(tags, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`tags`)) { if (missing(`tags`)) {
stop("Missing required parameter `tags`.") stop("Missing required parameter `tags`.")
} }
queryParams['tags'] <- tags
body <- NULL body <- NULL
urlPath <- "/pet/findByTags" url_path <- "/pet/findByTags"
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -560,59 +553,59 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
GetPetById = function(pet_id, data_file=NULL, ...){ GetPetById = function(pet_id, data_file=NULL, ...) {
apiResponse <- self$GetPetByIdWithHttpInfo(pet_id, data_file=data_file, ...) api_response <- self$GetPetByIdWithHttpInfo(pet_id, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
GetPetByIdWithHttpInfo = function(pet_id, data_file=NULL, ...){ GetPetByIdWithHttpInfo = function(pet_id, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet_id`)) { if (missing(`pet_id`)) {
stop("Missing required parameter `pet_id`.") stop("Missing required parameter `pet_id`.")
} }
body <- NULL body <- NULL
urlPath <- "/pet/{petId}" url_path <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), url_path)
} }
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -622,39 +615,39 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "Pet", loadNamespace("petstore")), self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
UpdatePet = function(pet, data_file=NULL, ...){ UpdatePet = function(pet, data_file=NULL, ...) {
apiResponse <- self$UpdatePetWithHttpInfo(pet, data_file=data_file, ...) api_response <- self$UpdatePetWithHttpInfo(pet, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
UpdatePetWithHttpInfo = function(pet, data_file=NULL, ...){ UpdatePetWithHttpInfo = function(pet, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet`)) { if (missing(`pet`)) {
stop("Missing required parameter `pet`.") stop("Missing required parameter `pet`.")
@ -666,14 +659,14 @@ PetApi <- R6::R6Class(
body <- NULL body <- NULL
} }
urlPath <- "/pet" url_path <- "/pet"
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "PUT", method = "PUT",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -683,39 +676,39 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "Pet", loadNamespace("petstore")), self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
UpdatePetWithForm = function(pet_id, name=NULL, status=NULL, ...){ UpdatePetWithForm = function(pet_id, name=NULL, status=NULL, ...) {
apiResponse <- self$UpdatePetWithFormWithHttpInfo(pet_id, name, status, ...) api_response <- self$UpdatePetWithFormWithHttpInfo(pet_id, name, status, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
UpdatePetWithFormWithHttpInfo = function(pet_id, name=NULL, status=NULL, ...){ UpdatePetWithFormWithHttpInfo = function(pet_id, name=NULL, status=NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet_id`)) { if (missing(`pet_id`)) {
stop("Missing required parameter `pet_id`.") stop("Missing required parameter `pet_id`.")
@ -726,49 +719,49 @@ PetApi <- R6::R6Class(
"status" = status "status" = status
) )
urlPath <- "/pet/{petId}" url_path <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), url_path)
} }
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
UploadFile = function(pet_id, additional_metadata=NULL, file=NULL, data_file=NULL, ...){ UploadFile = function(pet_id, additional_metadata=NULL, file=NULL, data_file=NULL, ...) {
apiResponse <- self$UploadFileWithHttpInfo(pet_id, additional_metadata, file, data_file=data_file, ...) api_response <- self$UploadFileWithHttpInfo(pet_id, additional_metadata, file, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
UploadFileWithHttpInfo = function(pet_id, additional_metadata=NULL, file=NULL, data_file=NULL, ...){ UploadFileWithHttpInfo = function(pet_id, additional_metadata=NULL, file=NULL, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`pet_id`)) { if (missing(`pet_id`)) {
stop("Missing required parameter `pet_id`.") stop("Missing required parameter `pet_id`.")
@ -779,18 +772,18 @@ PetApi <- R6::R6Class(
"file" = httr::upload_file(file) "file" = httr::upload_file(file)
) )
urlPath <- "/pet/{petId}/uploadImage" url_path <- "/pet/{petId}/uploadImage"
if (!missing(`pet_id`)) { if (!missing(`pet_id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "petId", "\\}"), URLencode(as.character(`pet_id`), reserved = TRUE), url_path)
} }
# OAuth token # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -800,15 +793,15 @@ PetApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), self$api_client$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -3,14 +3,13 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class
#' @title Store operations #' @title Store operations
#' @description petstore.Store #' @description petstore.Store
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication. #' @field api_client Handles the client-server communication.
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
@ -131,7 +130,7 @@
#' api.instance <- StoreApi$new() #' api.instance <- StoreApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$GetInventory() #' result <- api.instance$GetInventory()
#' #'
@ -163,94 +162,94 @@
#' @importFrom base64enc base64encode #' @importFrom base64enc base64encode
#' @export #' @export
StoreApi <- R6::R6Class( StoreApi <- R6::R6Class(
'StoreApi', "StoreApi",
public = list( public = list(
apiClient = NULL, api_client = NULL,
initialize = function(apiClient){ initialize = function(api_client) {
if (!missing(apiClient)) { if (!missing(api_client)) {
self$apiClient <- apiClient self$api_client <- api_client
} }
else { else {
self$apiClient <- ApiClient$new() self$api_client <- ApiClient$new()
} }
}, },
DeleteOrder = function(order_id, ...){ DeleteOrder = function(order_id, ...) {
apiResponse <- self$DeleteOrderWithHttpInfo(order_id, ...) api_response <- self$DeleteOrderWithHttpInfo(order_id, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
DeleteOrderWithHttpInfo = function(order_id, ...){ DeleteOrderWithHttpInfo = function(order_id, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`order_id`)) { if (missing(`order_id`)) {
stop("Missing required parameter `order_id`.") stop("Missing required parameter `order_id`.")
} }
body <- NULL body <- NULL
urlPath <- "/store/order/{orderId}" url_path <- "/store/order/{orderId}"
if (!missing(`order_id`)) { if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), url_path)
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "DELETE", method = "DELETE",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
GetInventory = function(data_file=NULL, ...){ GetInventory = function(data_file=NULL, ...) {
apiResponse <- self$GetInventoryWithHttpInfo(data_file=data_file, ...) api_response <- self$GetInventoryWithHttpInfo(data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
GetInventoryWithHttpInfo = function(data_file=NULL, ...){ GetInventoryWithHttpInfo = function(data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
body <- NULL body <- NULL
urlPath <- "/store/inventory" url_path <- "/store/inventory"
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -260,55 +259,55 @@ StoreApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "map(integer)", loadNamespace("petstore")), self$api_client$deserialize(resp, "map(integer)", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
GetOrderById = function(order_id, data_file=NULL, ...){ GetOrderById = function(order_id, data_file=NULL, ...) {
apiResponse <- self$GetOrderByIdWithHttpInfo(order_id, data_file=data_file, ...) api_response <- self$GetOrderByIdWithHttpInfo(order_id, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
GetOrderByIdWithHttpInfo = function(order_id, data_file=NULL, ...){ GetOrderByIdWithHttpInfo = function(order_id, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`order_id`)) { if (missing(`order_id`)) {
stop("Missing required parameter `order_id`.") stop("Missing required parameter `order_id`.")
} }
body <- NULL body <- NULL
urlPath <- "/store/order/{orderId}" url_path <- "/store/order/{orderId}"
if (!missing(`order_id`)) { if (!missing(`order_id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order_id`), reserved = TRUE), url_path)
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -318,39 +317,39 @@ StoreApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), self$api_client$deserialize(resp, "Order", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
PlaceOrder = function(order, data_file=NULL, ...){ PlaceOrder = function(order, data_file=NULL, ...) {
apiResponse <- self$PlaceOrderWithHttpInfo(order, data_file=data_file, ...) api_response <- self$PlaceOrderWithHttpInfo(order, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
PlaceOrderWithHttpInfo = function(order, data_file=NULL, ...){ PlaceOrderWithHttpInfo = function(order, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`order`)) { if (missing(`order`)) {
stop("Missing required parameter `order`.") stop("Missing required parameter `order`.")
@ -362,12 +361,12 @@ StoreApi <- R6::R6Class(
body <- NULL body <- NULL
} }
urlPath <- "/store/order" url_path <- "/store/order"
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -377,15 +376,15 @@ StoreApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), self$api_client$deserialize(resp, "Order", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,7 +3,6 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class

View File

@ -3,14 +3,13 @@
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
# #
# The version of the OpenAPI document: 1.0.0 # The version of the OpenAPI document: 1.0.0
#
# Generated by: https://openapi-generator.tech # Generated by: https://openapi-generator.tech
#' @docType class #' @docType class
#' @title User operations #' @title User operations
#' @description petstore.User #' @description petstore.User
#' @format An \code{R6Class} generator object #' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication. #' @field api_client Handles the client-server communication.
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
@ -196,7 +195,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$CreateUser(var.user) #' result <- api.instance$CreateUser(var.user)
#' #'
@ -210,7 +209,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$CreateUsersWithArrayInput(var.user) #' result <- api.instance$CreateUsersWithArrayInput(var.user)
#' #'
@ -224,7 +223,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$CreateUsersWithListInput(var.user) #' result <- api.instance$CreateUsersWithListInput(var.user)
#' #'
@ -238,7 +237,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$DeleteUser(var.username) #' result <- api.instance$DeleteUser(var.username)
#' #'
@ -274,7 +273,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$LogoutUser() #' result <- api.instance$LogoutUser()
#' #'
@ -289,7 +288,7 @@
#' api.instance <- UserApi$new() #' api.instance <- UserApi$new()
#' #'
#' #Configure API key authorization: api_key #' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY'; #' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#' #'
#' result <- api.instance$UpdateUser(var.username, var.user) #' result <- api.instance$UpdateUser(var.username, var.user)
#' #'
@ -299,35 +298,35 @@
#' @importFrom base64enc base64encode #' @importFrom base64enc base64encode
#' @export #' @export
UserApi <- R6::R6Class( UserApi <- R6::R6Class(
'UserApi', "UserApi",
public = list( public = list(
apiClient = NULL, api_client = NULL,
initialize = function(apiClient){ initialize = function(api_client) {
if (!missing(apiClient)) { if (!missing(api_client)) {
self$apiClient <- apiClient self$api_client <- api_client
} }
else { else {
self$apiClient <- ApiClient$new() self$api_client <- ApiClient$new()
} }
}, },
CreateUser = function(user, ...){ CreateUser = function(user, ...) {
apiResponse <- self$CreateUserWithHttpInfo(user, ...) api_response <- self$CreateUserWithHttpInfo(user, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
CreateUserWithHttpInfo = function(user, ...){ CreateUserWithHttpInfo = function(user, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`user`)) { if (missing(`user`)) {
stop("Missing required parameter `user`.") stop("Missing required parameter `user`.")
@ -339,220 +338,220 @@ UserApi <- R6::R6Class(
body <- NULL body <- NULL
} }
urlPath <- "/user" url_path <- "/user"
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
CreateUsersWithArrayInput = function(user, ...){ CreateUsersWithArrayInput = function(user, ...) {
apiResponse <- self$CreateUsersWithArrayInputWithHttpInfo(user, ...) api_response <- self$CreateUsersWithArrayInputWithHttpInfo(user, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
CreateUsersWithArrayInputWithHttpInfo = function(user, ...){ CreateUsersWithArrayInputWithHttpInfo = function(user, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`user`)) { if (missing(`user`)) {
stop("Missing required parameter `user`.") stop("Missing required parameter `user`.")
} }
if (!missing(`user`)) { if (!missing(`user`)) {
body.items = paste(unlist(lapply(user, function(param){param$toJSONString()})), collapse = ",") body.items = paste(unlist(lapply(user, function(param) {param$toJSONString()})), collapse = ",")
body <- paste0('[', body.items, ']') body <- paste0("[", body.items, "]")
} else { } else {
body <- NULL body <- NULL
} }
urlPath <- "/user/createWithArray" url_path <- "/user/createWithArray"
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
CreateUsersWithListInput = function(user, ...){ CreateUsersWithListInput = function(user, ...) {
apiResponse <- self$CreateUsersWithListInputWithHttpInfo(user, ...) api_response <- self$CreateUsersWithListInputWithHttpInfo(user, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
CreateUsersWithListInputWithHttpInfo = function(user, ...){ CreateUsersWithListInputWithHttpInfo = function(user, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`user`)) { if (missing(`user`)) {
stop("Missing required parameter `user`.") stop("Missing required parameter `user`.")
} }
if (!missing(`user`)) { if (!missing(`user`)) {
body.items = paste(unlist(lapply(user, function(param){param$toJSONString()})), collapse = ",") body.items = paste(unlist(lapply(user, function(param) {param$toJSONString()})), collapse = ",")
body <- paste0('[', body.items, ']') body <- paste0("[", body.items, "]")
} else { } else {
body <- NULL body <- NULL
} }
urlPath <- "/user/createWithList" url_path <- "/user/createWithList"
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "POST", method = "POST",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
DeleteUser = function(username, ...){ DeleteUser = function(username, ...) {
apiResponse <- self$DeleteUserWithHttpInfo(username, ...) api_response <- self$DeleteUserWithHttpInfo(username, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
DeleteUserWithHttpInfo = function(username, ...){ DeleteUserWithHttpInfo = function(username, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`username`)) { if (missing(`username`)) {
stop("Missing required parameter `username`.") stop("Missing required parameter `username`.")
} }
body <- NULL body <- NULL
urlPath <- "/user/{username}" url_path <- "/user/{username}"
if (!missing(`username`)) { if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
} }
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "DELETE", method = "DELETE",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
GetUserByName = function(username, data_file=NULL, ...){ GetUserByName = function(username, data_file=NULL, ...) {
apiResponse <- self$GetUserByNameWithHttpInfo(username, data_file=data_file, ...) api_response <- self$GetUserByNameWithHttpInfo(username, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
GetUserByNameWithHttpInfo = function(username, data_file=NULL, ...){ GetUserByNameWithHttpInfo = function(username, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`username`)) { if (missing(`username`)) {
stop("Missing required parameter `username`.") stop("Missing required parameter `username`.")
} }
body <- NULL body <- NULL
urlPath <- "/user/{username}" url_path <- "/user/{username}"
if (!missing(`username`)) { if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -562,39 +561,39 @@ UserApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "User", loadNamespace("petstore")), self$api_client$deserialize(resp, "User", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
LoginUser = function(username, password, data_file=NULL, ...){ LoginUser = function(username, password, data_file=NULL, ...) {
apiResponse <- self$LoginUserWithHttpInfo(username, password, data_file=data_file, ...) api_response <- self$LoginUserWithHttpInfo(username, password, data_file = data_file, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
LoginUserWithHttpInfo = function(username, password, data_file=NULL, ...){ LoginUserWithHttpInfo = function(username, password, data_file = NULL, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`username`)) { if (missing(`username`)) {
stop("Missing required parameter `username`.") stop("Missing required parameter `username`.")
@ -604,17 +603,13 @@ UserApi <- R6::R6Class(
stop("Missing required parameter `password`.") stop("Missing required parameter `password`.")
} }
queryParams['username'] <- username
queryParams['password'] <- password
body <- NULL body <- NULL
urlPath <- "/user/login" url_path <- "/user/login"
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
@ -624,82 +619,82 @@ UserApi <- R6::R6Class(
write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
} }
deserializedRespObj <- tryCatch( deserialized_resp_obj <- tryCatch(
self$apiClient$deserialize(resp, "character", loadNamespace("petstore")), self$api_client$deserialize(resp, "character", loadNamespace("petstore")),
error = function(e){ error = function(e) {
stop("Failed to deserialize response") stop("Failed to deserialize response")
} }
) )
ApiResponse$new(deserializedRespObj, resp) ApiResponse$new(deserialized_resp_obj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
LogoutUser = function(...){ LogoutUser = function(...) {
apiResponse <- self$LogoutUserWithHttpInfo(...) api_response <- self$LogoutUserWithHttpInfo(...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
LogoutUserWithHttpInfo = function(...){ LogoutUserWithHttpInfo = function(...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
body <- NULL body <- NULL
urlPath <- "/user/logout" url_path <- "/user/logout"
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "GET", method = "GET",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
ApiResponse$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
UpdateUser = function(username, user, ...){ UpdateUser = function(username, user, ...) {
apiResponse <- self$UpdateUserWithHttpInfo(username, user, ...) api_response <- self$UpdateUserWithHttpInfo(username, user, ...)
resp <- apiResponse$response resp <- api_response$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content api_response$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse api_response
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse api_response
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse api_response
} }
}, },
UpdateUserWithHttpInfo = function(username, user, ...){ UpdateUserWithHttpInfo = function(username, user, ...) {
args <- list(...) args <- list(...)
queryParams <- list() query_params <- list()
headerParams <- c() header_params <- c()
if (missing(`username`)) { if (missing(`username`)) {
stop("Missing required parameter `username`.") stop("Missing required parameter `username`.")
@ -715,27 +710,27 @@ UserApi <- R6::R6Class(
body <- NULL body <- NULL
} }
urlPath <- "/user/{username}" url_path <- "/user/{username}"
if (!missing(`username`)) { if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), urlPath) url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
} }
# API key authentication # API key authentication
if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "")
} }
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath), resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
method = "PUT", method = "PUT",
queryParams = queryParams, query_params = query_params,
headerParams = headerParams, header_params = header_params,
body = body, body = body,
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
ApiResponse$new(NULL, resp) ApiResponse$new(NULL, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp) ApiResponse$new(paste("Server returned ", httr::status_code(resp), " response status code."), resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -1,19 +1,19 @@
context("basic functionality") context("basic functionality")
petApi <- PetApi$new() pet_api <- PetApi$new()
petId <- 123321 pet_id <- 123321
pet <- Pet$new("name_test", pet <- Pet$new("name_test",
photoUrls = list("photo_test", "second test"), photoUrls = list("photo_test", "second test"),
category = Category$new(id=450, name="test_cat"), category = Category$new(id = 450, name = "test_cat"),
id = petId, id = pet_id,
tags = list( tags = list(
Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown") Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown")
), ),
status = "available" status = "available"
) )
result <- petApi$AddPet(pet) result <- pet_api$AddPet(pet)
test_that("AddPet", { test_that("AddPet", {
expect_equal(petId, 123321) expect_equal(pet_id, 123321)
#expect_equal(result, NULL) #expect_equal(result, NULL)
}) })
@ -21,7 +21,7 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", {
pet0 <- Pet$new() pet0 <- Pet$new()
jsonpet <- pet0$toJSON() jsonpet <- pet0$toJSON()
pet2 <- pet0$fromJSON( pet2 <- pet0$fromJSON(
jsonlite::toJSON(jsonpet, auto_unbox=TRUE) jsonlite::toJSON(jsonpet, auto_unbox = TRUE)
) )
expect_equal(pet0, pet2) expect_equal(pet0, pet2)
jsonpet <- pet0$toJSONString() jsonpet <- pet0$toJSONString()
@ -38,16 +38,16 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", {
pet1 <- Pet$new("name_test", pet1 <- Pet$new("name_test",
list("photo_test", "second test"), list("photo_test", "second test"),
category = Category$new(id=450, name="test_cat"), category = Category$new(id = 450, name = "test_cat"),
id = petId, id = pet_id,
tags = list( tags = list(
Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown") Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown")
), ),
status = "available" status = "available"
) )
jsonpet <- pet1$toJSON() jsonpet <- pet1$toJSON()
pet2 <- pet1$fromJSON( pet2 <- pet1$fromJSON(
jsonlite::toJSON(jsonpet, auto_unbox=TRUE) jsonlite::toJSON(jsonpet, auto_unbox = TRUE)
) )
expect_equal(pet1, pet2) expect_equal(pet1, pet2)
@ -65,38 +65,38 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", {
}) })
test_that("Test Category", { test_that("Test Category", {
c1 <- Category$new(id=450, name="test_cat") c1 <- Category$new(id = 450, name = "test_cat")
c2 <- Category$new() c2 <- Category$new()
c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox=TRUE)) c2$fromJSON(jsonlite::toJSON(c1$toJSON(), auto_unbox = TRUE))
expect_equal(c1, c2) expect_equal(c1, c2)
c2$fromJSONString(c1$toJSONString()) c2$fromJSONString(c1$toJSONString())
expect_equal(c1, c2) expect_equal(c1, c2)
}) })
test_that("GetPetById", { test_that("GetPetById", {
response <- petApi$GetPetById(petId) response <- pet_api$GetPetById(pet_id)
expect_equal(response$id, petId) expect_equal(response$id, pet_id)
expect_equal(response$name, "name_test") expect_equal(response$name, "name_test")
expect_equal( expect_equal(
response$photoUrls, response$photoUrls,
list("photo_test", "second test") list("photo_test", "second test")
) )
expect_equal(response$status, "available") expect_equal(response$status, "available")
expect_equal(response$category, Category$new(id=450, name="test_cat")) expect_equal(response$category, Category$new(id = 450, name = "test_cat"))
expect_equal(pet$tags, response$tags) expect_equal(pet$tags, response$tags)
expect_equal( expect_equal(
response$tags, response$tags,
list(Tag$new(id=123, name="tag_test"), Tag$new(id=456, name="unknown")) list(Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown"))
) )
}) })
test_that("GetPetById with data_file", { test_that("GetPetById with data_file", {
# test to ensure json is saved to the file `get_pet_by_id.json` # test to ensure json is saved to the file `get_pet_by_id.json`
petResponse <- petApi$GetPetById(petId, data_file="get_pet_by_id.json") pet_response <- pet_api$GetPetById(pet_id, data_file = "get_pet_by_id.json")
response <- read_json("get_pet_by_id.json") response <- read_json("get_pet_by_id.json")
expect_true(!is.null(response)) expect_true(!is.null(response))
expect_equal(response$id, petId) expect_equal(response$id, pet_id)
expect_equal(response$name, "name_test") expect_equal(response$name, "name_test")
}) })
@ -105,9 +105,9 @@ test_that("GetPetById with data_file", {
# pet <- Pet$new(pet.id, NULL, "name_test2", # pet <- Pet$new(pet.id, NULL, "name_test2",
# list("photo_test2", "second test2"), # list("photo_test2", "second test2"),
# NULL, NULL) # NULL, NULL)
# result <-petApi$AddPet(pet) # result <-pet_api$AddPet(pet)
# #
# response <- petApi$GetPetById(pet.id) # response <- pet_api$GetPetById(pet.id)
# #
# expect_equal(response$id, pet.id) # expect_equal(response$id, pet.id)
# expect_equal(response$name, "name_test2") # expect_equal(response$name, "name_test2")
@ -118,6 +118,6 @@ test_that("GetPetById with data_file", {
#}) #})
#test_that("updatePetWithForm", { #test_that("updatePetWithForm", {
# response <- petApi$updatePetWithForm(petId, "test", "sold") # response <- pet_api$updatePetWithForm(pet_id, "test", "sold")
# expect_equal(response, "Pet updated") # expect_equal(response, "Pet updated")
#}) #})