From 6df2dd23498d99eef5baad34420793d2d43090f6 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 18 May 2022 01:01:36 +0800 Subject: [PATCH 1/2] better code format for r client --- .../src/main/resources/r/ApiResponse.mustache | 4 +- .../src/main/resources/r/api.mustache | 112 +++---- .../src/main/resources/r/api_client.mustache | 163 ++++----- .../main/resources/r/partial_header.mustache | 8 +- samples/client/petstore/R/R/api_client.R | 162 ++++----- samples/client/petstore/R/R/api_response.R | 4 +- samples/client/petstore/R/R/category.R | 1 - .../client/petstore/R/R/model_api_response.R | 1 - samples/client/petstore/R/R/order.R | 1 - samples/client/petstore/R/R/pet.R | 1 - samples/client/petstore/R/R/pet_api.R | 317 +++++++++--------- samples/client/petstore/R/R/store_api.R | 155 +++++---- samples/client/petstore/R/R/tag.R | 1 - samples/client/petstore/R/R/user.R | 1 - samples/client/petstore/R/R/user_api.R | 275 ++++++++------- .../petstore/R/tests/testthat/test_petstore.R | 22 +- 16 files changed, 609 insertions(+), 619 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache index 28571b104a08..d037b95f2ac8 100644 --- a/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache +++ b/modules/openapi-generator/src/main/resources/r/ApiResponse.mustache @@ -6,11 +6,11 @@ #' @field response The raw response from the endpoint. #' @export ApiResponse <- R6::R6Class( - 'ApiResponse', + "ApiResponse", public = list( content = NULL, response = NULL, - initialize = function(content, response){ + initialize = function(content, response) { self$content <- content self$response <- response } diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 434a777b4207..0d123905c45c 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -4,7 +4,7 @@ #' @title {{baseName}} operations #' @description {{importPath}} #' @format An \code{R6Class} generator object -#' @field apiClient Handles the client-server communication. +#' @field api_client Handles the client-server communication. #' #' @section Methods: {{! Adding the below changes for generating documentation for the api methods. }} @@ -97,17 +97,17 @@ {{#isBasic}} #' #Configure HTTP basic authorization: {{{name}}} #' # provide your username in the user-serial format -#' api.instance$apiClient$username <- ''; +#' api.instance$api_client$username <- ''; #' # provide your api key generated using the developer portal -#' api.instance$apiClient$password <- ''; +#' api.instance$api_client$password <- ''; {{/isBasic}} {{#isApiKey}} #' #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}} {{#isOAuth}} #' # 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}} {{/authMethods}} {{/hasAuthMethods}} @@ -149,34 +149,34 @@ {{classname}} <- R6::R6Class( '{{classname}}', public = list( - apiClient = NULL, - initialize = function(apiClient){ - if (!missing(apiClient)) { - self$apiClient <- apiClient + api_client = NULL, + initialize = function(api_client) { + if (!missing(api_client)) { + self$api_client <- api_client } else { - self$apiClient <- ApiClient$new() + self$api_client <- ApiClient$new() } }, {{#operation}} - {{{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}}...) - resp <- apiResponse$response + {{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file=NULL, {{/returnType}}...) { + api_response <- self${{{operationId}}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}{{#returnType}}data_file=data_file, {{/returnType}}...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - 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(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() {{#requiredParams}} if (missing(`{{paramName}}`)) { @@ -189,14 +189,14 @@ } {{/requiredParams}} - {{#headerParams}} - headerParams['{{baseName}}'] <- `{{paramName}}` + {{#header_params}} + header_params['{{baseName}}'] <- `{{paramName}}` - {{/headerParams}} - {{#queryParams}} - queryParams['{{baseName}}'] <- {{paramName}} + {{/header_params}} + {{#query_params}} + query_params['{{baseName}}'] <- {{paramName}} - {{/queryParams}} + {{/query_params}} {{#hasFormParams}} body <- list( {{#formParams}} @@ -214,7 +214,7 @@ {{#bodyParams}} if (!missing(`{{paramName}}`)) { {{#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, ']') {{/isArray}} {{^isArray}} @@ -231,11 +231,11 @@ body <- NULL {{/hasFormParams}} {{/hasBodyParam}} - urlPath <- "{{path}}" + url_path <- "{{path}}" {{#hasPathParams}} {{#pathParams}} 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}} @@ -244,32 +244,32 @@ {{#isBasic}} {{#isBasicBasic}} # 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}} {{/isBasic}} {{#isApiKey}} # API key authentication {{#isKeyInHeader}} - if ("{{{keyParamName}}}" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["{{{keyParamName}}}"]) > 0) { - headerParams['{{keyParamName}}'] <- paste(unlist(self$apiClient$apiKeys["{{keyParamName}}"]), collapse='') + if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) { + header_params['{{keyParamName}}'] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse='') } {{/isKeyInHeader}} {{#isKeyInQuery}} - if ("{{{keyParamName}}}" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["{{{keyParamName}}}"]) > 0) { - queryParams['{{keyParamName}}'] <- paste(unlist(self$apiClient$apiKeys["{{keyParamName}}"]), collapse='') + if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) { + query_params['{{keyParamName}}'] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse='') } {{/isKeyInQuery}} {{/isApiKey}} {{#isOAuth}} # OAuth token - headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ") + header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") {{/isOAuth}} {{/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}}", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -293,8 +293,8 @@ } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")), - error = function(e){ + self$api_client$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")), + error = function(e) { {{#useDefaultExceptionHandling}} stop("Failed to deserialize response") {{/useDefaultExceptionHandling}} @@ -312,31 +312,31 @@ {{/returnType}} } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) { {{#returnExceptionOnFailure}} - errorMsg <- toString(content(resp)) - if(errorMsg == ""){ - errorMsg <- paste("Server returned " , httr::status_code(resp) , " response status code.") + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- paste("Server returned ", httr::status_code(resp), " response status code.") } {{#useDefaultExceptionHandling}} - stop(errorMsg) + stop(error_msg) {{/useDefaultExceptionHandling}} {{#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}} {{/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}} } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { {{#returnExceptionOnFailure}} - errorMsg <- toString(content(resp)) - if(errorMsg == ""){ - errorMsg <- "Api client exception encountered." + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api client exception encountered." } {{#useDefaultExceptionHandling}} - stop(errorMsg) + stop(error_msg) {{/useDefaultExceptionHandling}} {{#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}} {{/returnExceptionOnFailure}} {{^returnExceptionOnFailure}} @@ -344,15 +344,15 @@ {{/returnExceptionOnFailure}} } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { {{#returnExceptionOnFailure}} - errorMsg <- toString(content(resp)) - if(errorMsg == ""){ - errorMsg <- "Api server exception encountered." + error_msg <- toString(content(resp)) + if(error_msg == "") { + error_msg <- "Api server exception encountered." } {{#useDefaultExceptionHandling}} - stop(errorMsg) + stop(error_msg) {{/useDefaultExceptionHandling}} {{#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}} {{/returnExceptionOnFailure}} {{^returnExceptionOnFailure}} diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index 2d67faeef2f4..9a2aa57c8198 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -16,52 +16,55 @@ #' @title ApiClient #' @description ApiClient Class #' @format An \code{R6Class} generator object -#' @field basePath Base url -#' @field userAgent Default user agent -#' @field defaultHeaders +#' @field base_path Base url +#' @field user_agent Default user agent +#' @field default_headers #' @field username Username for HTTP basic authentication #' @field password Password for HTTP basic authentication -#' @field apiKeys -#' @field accessToken +#' @field api_keys +#' @field access_token #' @field timeout Default timeout in seconds -#' @field retryStatusCodes vector of status codes to retry -#' @field maxRetryAttempts maximum number of retries for the status codes +#' @field retry_status_codes vector of status codes to retry +#' @field max_retry_attempts maximum number of retries for the status codes #' @importFrom httr add_headers accept timeout content {{#useRlangExceptionHandling}} #' @importFrom rlang abort {{/useRlangExceptionHandling}} #' @export ApiClient <- R6::R6Class( - 'ApiClient', + "ApiClient", public = list( # base path of all requests - basePath = "{{{basePath}}}", + base_path = "{{{basePath}}}", # 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 - defaultHeaders = NULL, + default_headers = NULL, # username (HTTP basic authentication) username = NULL, # password (HTTP basic authentication) password = NULL, # API keys - apiKeys = NULL, + api_keys = NULL, # Access token - accessToken = NULL, + access_token = NULL, # Time Out (seconds) timeout = NULL, # Vector of status codes to retry - retryStatusCodes=NULL, + retry_status_codes = NULL, # Maximum number of retry attempts for the retry status codes - maxRetryAttempts = NULL, + max_retry_attempts = NULL, # constructor - initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL, timeout=NULL, retryStatusCodes=NULL, maxRetryAttempts=NULL){ - if (!is.null(basePath)) { - self$basePath <- basePath + initialize = function(base_path=NULL, user_agent=NULL, default_headers=NULL, + username=NULL, password=NULL, api_keys=NULL, + 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)) { - self$defaultHeaders <- defaultHeaders + if (!is.null(default_headers)) { + self$default_headers <- default_headers } if (!is.null(username)) { @@ -72,49 +75,49 @@ ApiClient <- R6::R6Class( self$password <- password } - if (!is.null(accessToken)) { - self$accessToken <- accessToken + if (!is.null(access_token)) { + self$access_token <- access_token } - if (!is.null(apiKeys)) { - self$apiKeys <- apiKeys + if (!is.null(api_keys)) { + self$api_keys <- api_keys } else { - self$apiKeys <- list() + self$api_keys <- list() } - if (!is.null(userAgent)) { - self$`userAgent` <- userAgent + if (!is.null(user_agent)) { + self$`user_agent` <- user_agent } if (!is.null(timeout)) { self$timeout <- timeout } - if (!is.null(retryStatusCodes)) { - self$retryStatusCodes <- retryStatusCodes + if (!is.null(retry_status_codes)) { + self$retry_status_codes <- retry_status_codes } - if (!is.null(maxRetryAttempts)) { - self$maxRetryAttempts <- maxRetryAttempts + if (!is.null(max_retry_attempts)) { + 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, ...) - statusCode <- httr::status_code(resp) + resp <- self$Execute(url, method, query_params, header_params, body, ...) + status_code <- httr::status_code(resp) - if (is.null(self$maxRetryAttempts)) { - self$maxRetryAttempts = 3 + if (is.null(self$max_retry_attempts)) { + self$max_retry_attempts <- 3 } - if (!is.null(self$retryStatusCodes)) { + if (!is.null(self$retry_status_codes)) { - for (i in 1 : self$maxRetryAttempts) { - if (statusCode %in% self$retryStatusCodes) { + for (i in 1 : self$max_retry_attempts) { + if (status_code %in% self$retry_status_codes) { Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) - resp <- self$Execute(url, method, queryParams, headerParams, body, ...) - statusCode <- httr::status_code(resp) + resp <- self$Execute(url, method, query_params, header_params, body, ...) + status_code <- httr::status_code(resp) } else { break; } @@ -124,78 +127,78 @@ ApiClient <- R6::R6Class( resp }, - Execute = function(url, method, queryParams, headerParams, body, ...){ - headers <- httr::add_headers(c(headerParams, self$defaultHeaders)) + Execute = function(url, method, query_params, header_params, body, ...) { + headers <- httr::add_headers(c(header_params, self$default_headers)) {{! Adding timeout that can be set at the apiClient object level}} - httpTimeout <- NULL + http_timeout <- NULL if (!is.null(self$timeout)) { - httpTimeout <- httr::timeout(self$timeout) + http_timeout <- httr::timeout(self$timeout) } 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") { - 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") { - 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") { - 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") { - 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") { - 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 { - 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}} - stop(errMsg) + stop(err_msg) {{/useDefaultExceptionHandling}} {{#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}} } }, # Deserialize the content of api response to the given type. - deserialize = function(resp, returnType, pkgEnv) { - respObj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - self$deserializeObj(respObj, returnType, pkgEnv) + deserialize = function(resp, return_type, pkg_env) { + resp_obj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) + self$deserializeObj(resp_obj, return_type, pkg_env) }, # Deserialize the response from jsonlite object based on the given type # 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) { - returnObj <- NULL - primitiveTypes <- c("character", "numeric", "integer", "logical", "complex") + deserializeObj = function(obj, return_type, pkg_env) { + return_obj <- NULL + primitive_types <- c("character", "numeric", "integer", "logical", "complex") # To handle the "map" type - if (startsWith(returnType, "map(")) { - innerReturnType <- regmatches(returnType, regexec(pattern = "map\\((.*)\\)", returnType))[[1]][2] - returnObj <- lapply(names(obj), function(name) { - self$deserializeObj(obj[[name]], innerReturnType, pkgEnv) + if (startsWith(return_type, "map(")) { + inner_return_type <- regmatches(return_type, regexec(pattern = "map\\((.*)\\)", return_type))[[1]][2] + return_obj <- lapply(names(obj), function(name) { + self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) - names(returnObj) <- names(obj) + names(return_obj) <- names(obj) } # To handle the "array" type - else if (startsWith(returnType, "array[")) { - innerReturnType <- regmatches(returnType, regexec(pattern = "array\\[(.*)\\]", returnType))[[1]][2] - if (c(innerReturnType) %in% primitiveTypes) { - returnObj <- vector("list", length = length(obj)) + else if (startsWith(return_type, "array[")) { + inner_return_type <- regmatches(return_type, regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + if (c(inner_return_type) %in% primitive_types) { + return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { 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 { - if(!is.null(nrow(obj))){ - returnObj <- vector("list", length = nrow(obj)) + if (!is.null(nrow(obj))) { + return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { 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" - else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { - returnType <- get(returnType, envir = as.environment(pkgEnv)) - returnObj <- returnType$new() - returnObj$fromJSON( + else if (exists(return_type, pkg_env) && !(c(return_type) %in% primitive_types)) { + return_type <- get(return_type, envir = as.environment(pkg_env)) + return_obj <- return_type$new() + return_obj$fromJSON( jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) ) } # To handle primitive type else { - returnObj <- obj + return_obj <- obj } - returnObj + return_obj } ) ) diff --git a/modules/openapi-generator/src/main/resources/r/partial_header.mustache b/modules/openapi-generator/src/main/resources/r/partial_header.mustache index 9634cbe52f21..5c70b65ef06d 100644 --- a/modules/openapi-generator/src/main/resources/r/partial_header.mustache +++ b/modules/openapi-generator/src/main/resources/r/partial_header.mustache @@ -6,6 +6,10 @@ # {{{.}}} # {{/appDescription}} -# {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}} -# {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}} +{{#version}} +# The version of the OpenAPI document: {{{.}}} +{{/version}} +{{#infoEmail}} +# Contact: {{{.}}} +{{/infoEmail}} # Generated by: https://openapi-generator.tech diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 533e8ea9daed..4da8ff915451 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech @@ -23,49 +22,52 @@ #' @title ApiClient #' @description ApiClient Class #' @format An \code{R6Class} generator object -#' @field basePath Base url -#' @field userAgent Default user agent -#' @field defaultHeaders +#' @field base_path Base url +#' @field user_agent Default user agent +#' @field default_headers #' @field username Username for HTTP basic authentication #' @field password Password for HTTP basic authentication -#' @field apiKeys -#' @field accessToken +#' @field api_keys +#' @field access_token #' @field timeout Default timeout in seconds -#' @field retryStatusCodes vector of status codes to retry -#' @field maxRetryAttempts maximum number of retries for the status codes +#' @field retry_status_codes vector of status codes to retry +#' @field max_retry_attempts maximum number of retries for the status codes #' @importFrom httr add_headers accept timeout content #' @export ApiClient <- R6::R6Class( - 'ApiClient', + "ApiClient", public = list( # base path of all requests - basePath = "http://petstore.swagger.io/v2", + base_path = "http://petstore.swagger.io/v2", # user agent in the HTTP request - userAgent = "PetstoreAgent", + user_agent = "PetstoreAgent", # default headers in the HTTP request - defaultHeaders = NULL, + default_headers = NULL, # username (HTTP basic authentication) username = NULL, # password (HTTP basic authentication) password = NULL, # API keys - apiKeys = NULL, + api_keys = NULL, # Access token - accessToken = NULL, + access_token = NULL, # Time Out (seconds) timeout = NULL, # Vector of status codes to retry - retryStatusCodes=NULL, + retry_status_codes = NULL, # Maximum number of retry attempts for the retry status codes - maxRetryAttempts = NULL, + max_retry_attempts = NULL, # constructor - initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL, timeout=NULL, retryStatusCodes=NULL, maxRetryAttempts=NULL){ - if (!is.null(basePath)) { - self$basePath <- basePath + initialize = function(base_path=NULL, user_agent=NULL, default_headers=NULL, + username=NULL, password=NULL, api_keys=NULL, + 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)) { - self$defaultHeaders <- defaultHeaders + if (!is.null(default_headers)) { + self$default_headers <- default_headers } if (!is.null(username)) { @@ -76,49 +78,49 @@ ApiClient <- R6::R6Class( self$password <- password } - if (!is.null(accessToken)) { - self$accessToken <- accessToken + if (!is.null(access_token)) { + self$access_token <- access_token } - if (!is.null(apiKeys)) { - self$apiKeys <- apiKeys + if (!is.null(api_keys)) { + self$api_keys <- api_keys } else { - self$apiKeys <- list() + self$api_keys <- list() } - if (!is.null(userAgent)) { - self$`userAgent` <- userAgent + if (!is.null(user_agent)) { + self$`user_agent` <- user_agent } if (!is.null(timeout)) { self$timeout <- timeout } - if (!is.null(retryStatusCodes)) { - self$retryStatusCodes <- retryStatusCodes + if (!is.null(retry_status_codes)) { + self$retry_status_codes <- retry_status_codes } - if (!is.null(maxRetryAttempts)) { - self$maxRetryAttempts <- maxRetryAttempts + if (!is.null(max_retry_attempts)) { + 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, ...) - statusCode <- httr::status_code(resp) + resp <- self$Execute(url, method, query_params, header_params, body, ...) + status_code <- httr::status_code(resp) - if (is.null(self$maxRetryAttempts)) { - self$maxRetryAttempts = 3 + if (is.null(self$max_retry_attempts)) { + self$max_retry_attempts <- 3 } - if (!is.null(self$retryStatusCodes)) { + if (!is.null(self$retry_status_codes)) { - for (i in 1 : self$maxRetryAttempts) { - if (statusCode %in% self$retryStatusCodes) { + for (i in 1 : self$max_retry_attempts) { + if (status_code %in% self$retry_status_codes) { Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1)) - resp <- self$Execute(url, method, queryParams, headerParams, body, ...) - statusCode <- httr::status_code(resp) + resp <- self$Execute(url, method, query_params, header_params, body, ...) + status_code <- httr::status_code(resp) } else { break; } @@ -128,72 +130,72 @@ ApiClient <- R6::R6Class( resp }, - Execute = function(url, method, queryParams, headerParams, body, ...){ - headers <- httr::add_headers(c(headerParams, self$defaultHeaders)) + Execute = function(url, method, query_params, header_params, body, ...) { + headers <- httr::add_headers(c(header_params, self$default_headers)) - httpTimeout <- NULL + http_timeout <- NULL if (!is.null(self$timeout)) { - httpTimeout <- httr::timeout(self$timeout) + http_timeout <- httr::timeout(self$timeout) } 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") { - 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") { - 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") { - 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") { - 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") { - 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 { - errMsg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." - stop(errMsg) + err_msg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." + stop(err_msg) } }, # Deserialize the content of api response to the given type. - deserialize = function(resp, returnType, pkgEnv) { - respObj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - self$deserializeObj(respObj, returnType, pkgEnv) + deserialize = function(resp, return_type, pkg_env) { + resp_obj <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) + self$deserializeObj(resp_obj, return_type, pkg_env) }, # Deserialize the response from jsonlite object based on the given type # 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) { - returnObj <- NULL - primitiveTypes <- c("character", "numeric", "integer", "logical", "complex") + deserializeObj = function(obj, return_type, pkg_env) { + return_obj <- NULL + primitive_types <- c("character", "numeric", "integer", "logical", "complex") # To handle the "map" type - if (startsWith(returnType, "map(")) { - innerReturnType <- regmatches(returnType, regexec(pattern = "map\\((.*)\\)", returnType))[[1]][2] - returnObj <- lapply(names(obj), function(name) { - self$deserializeObj(obj[[name]], innerReturnType, pkgEnv) + if (startsWith(return_type, "map(")) { + inner_return_type <- regmatches(return_type, regexec(pattern = "map\\((.*)\\)", return_type))[[1]][2] + return_obj <- lapply(names(obj), function(name) { + self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) - names(returnObj) <- names(obj) + names(return_obj) <- names(obj) } # To handle the "array" type - else if (startsWith(returnType, "array[")) { - innerReturnType <- regmatches(returnType, regexec(pattern = "array\\[(.*)\\]", returnType))[[1]][2] - if (c(innerReturnType) %in% primitiveTypes) { - returnObj <- vector("list", length = length(obj)) + else if (startsWith(return_type, "array[")) { + inner_return_type <- regmatches(return_type, regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + if (c(inner_return_type) %in% primitive_types) { + return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { 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 { - if(!is.null(nrow(obj))){ - returnObj <- vector("list", length = nrow(obj)) + if (!is.null(nrow(obj))) { + return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { 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" - else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) { - returnType <- get(returnType, envir = as.environment(pkgEnv)) - returnObj <- returnType$new() - returnObj$fromJSON( + else if (exists(return_type, pkg_env) && !(c(return_type) %in% primitive_types)) { + return_type <- get(return_type, envir = as.environment(pkg_env)) + return_obj <- return_type$new() + return_obj$fromJSON( jsonlite::toJSON(obj, digits = NA, auto_unbox = TRUE) ) } # To handle primitive type else { - returnObj <- obj + return_obj <- obj } - returnObj + return_obj } ) ) diff --git a/samples/client/petstore/R/R/api_response.R b/samples/client/petstore/R/R/api_response.R index 28571b104a08..d037b95f2ac8 100644 --- a/samples/client/petstore/R/R/api_response.R +++ b/samples/client/petstore/R/R/api_response.R @@ -6,11 +6,11 @@ #' @field response The raw response from the endpoint. #' @export ApiResponse <- R6::R6Class( - 'ApiResponse', + "ApiResponse", public = list( content = NULL, response = NULL, - initialize = function(content, response){ + initialize = function(content, response) { self$content <- content self$response <- response } diff --git a/samples/client/petstore/R/R/category.R b/samples/client/petstore/R/R/category.R index 059b64e37482..2685bd0809fb 100644 --- a/samples/client/petstore/R/R/category.R +++ b/samples/client/petstore/R/R/category.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/model_api_response.R b/samples/client/petstore/R/R/model_api_response.R index a1c16133557b..2e7a63a919a4 100644 --- a/samples/client/petstore/R/R/model_api_response.R +++ b/samples/client/petstore/R/R/model_api_response.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/order.R b/samples/client/petstore/R/R/order.R index d3e2e46b4937..51f6e7630338 100644 --- a/samples/client/petstore/R/R/order.R +++ b/samples/client/petstore/R/R/order.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 1960b16906a0..5e4cbfe45424 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index f687a9b5edf4..c871e57b6d9c 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class #' @title Pet operations #' @description petstore.Pet #' @format An \code{R6Class} generator object -#' @field apiClient Handles the client-server communication. +#' @field api_client Handles the client-server communication. #' #' @section Methods: #' \describe{ @@ -207,7 +206,7 @@ #' api.instance <- PetApi$new() #' #' # 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.body) #' @@ -222,7 +221,7 @@ #' api.instance <- PetApi$new() #' #' # 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) #' @@ -236,7 +235,7 @@ #' api.instance <- PetApi$new() #' #' # 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) #' @@ -250,7 +249,7 @@ #' api.instance <- PetApi$new() #' #' # 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) #' @@ -264,7 +263,7 @@ #' api.instance <- PetApi$new() #' #' #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) #' @@ -278,7 +277,7 @@ #' api.instance <- PetApi$new() #' #' # 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.body) #' @@ -294,7 +293,7 @@ #' api.instance <- PetApi$new() #' #' # 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) #' @@ -310,7 +309,7 @@ #' api.instance <- PetApi$new() #' #' # 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) #' @@ -322,33 +321,33 @@ PetApi <- R6::R6Class( 'PetApi', public = list( - apiClient = NULL, - initialize = function(apiClient){ - if (!missing(apiClient)) { - self$apiClient <- apiClient + api_client = NULL, + initialize = function(api_client) { + if (!missing(api_client)) { + self$api_client <- api_client } else { - self$apiClient <- ApiClient$new() + self$api_client <- ApiClient$new() } }, - AddPet = function(body, ...){ - apiResponse <- self$AddPetWithHttpInfo(body, ...) - resp <- apiResponse$response + AddPet = function(body, ...) { + api_response <- self$AddPetWithHttpInfo(body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - AddPetWithHttpInfo = function(body, ...){ + AddPetWithHttpInfo = function(body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") @@ -360,112 +359,108 @@ PetApi <- R6::R6Class( body <- NULL } - urlPath <- "/pet" + url_path <- "/pet" # 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - DeletePet = function(pet.id, api.key=NULL, ...){ - apiResponse <- self$DeletePetWithHttpInfo(pet.id, api.key, ...) - resp <- apiResponse$response + DeletePet = function(pet.id, api.key=NULL, ...) { + api_response <- self$DeletePetWithHttpInfo(pet.id, api.key, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - DeletePetWithHttpInfo = function(pet.id, api.key=NULL, ...){ + DeletePetWithHttpInfo = function(pet.id, api.key=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`pet.id`)) { stop("Missing required parameter `pet.id`.") } - headerParams['api_key'] <- `api.key` - body <- NULL - urlPath <- "/pet/{petId}" + url_path <- "/pet/{petId}" 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 - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - FindPetsByStatus = function(status, data_file=NULL, ...){ - apiResponse <- self$FindPetsByStatusWithHttpInfo(status, data_file=data_file, ...) - resp <- apiResponse$response + FindPetsByStatus = function(status, data_file=NULL, ...) { + api_response <- self$FindPetsByStatusWithHttpInfo(status, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - FindPetsByStatusWithHttpInfo = function(status, data_file=NULL, ...){ + FindPetsByStatusWithHttpInfo = function(status, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`status`)) { stop("Missing required parameter `status`.") } - queryParams['status'] <- status - body <- NULL - urlPath <- "/pet/findByStatus" + url_path <- "/pet/findByStatus" # 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -476,54 +471,52 @@ PetApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - FindPetsByTags = function(tags, data_file=NULL, ...){ - apiResponse <- self$FindPetsByTagsWithHttpInfo(tags, data_file=data_file, ...) - resp <- apiResponse$response + FindPetsByTags = function(tags, data_file=NULL, ...) { + api_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - FindPetsByTagsWithHttpInfo = function(tags, data_file=NULL, ...){ + FindPetsByTagsWithHttpInfo = function(tags, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`tags`)) { stop("Missing required parameter `tags`.") } - queryParams['tags'] <- tags - body <- NULL - urlPath <- "/pet/findByTags" + url_path <- "/pet/findByTags" # 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -534,58 +527,58 @@ PetApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "array[Pet]", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - GetPetById = function(pet.id, data_file=NULL, ...){ - apiResponse <- self$GetPetByIdWithHttpInfo(pet.id, data_file=data_file, ...) - resp <- apiResponse$response + GetPetById = function(pet.id, data_file=NULL, ...) { + api_response <- self$GetPetByIdWithHttpInfo(pet.id, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - GetPetByIdWithHttpInfo = function(pet.id, data_file=NULL, ...){ + GetPetByIdWithHttpInfo = function(pet.id, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`pet.id`)) { stop("Missing required parameter `pet.id`.") } body <- NULL - urlPath <- "/pet/{petId}" + url_path <- "/pet/{petId}" 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 - if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { - headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') + if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) { + 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -596,38 +589,38 @@ PetApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Pet", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - UpdatePet = function(body, ...){ - apiResponse <- self$UpdatePetWithHttpInfo(body, ...) - resp <- apiResponse$response + UpdatePet = function(body, ...) { + api_response <- self$UpdatePetWithHttpInfo(body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - UpdatePetWithHttpInfo = function(body, ...){ + UpdatePetWithHttpInfo = function(body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") @@ -639,45 +632,45 @@ PetApi <- R6::R6Class( body <- NULL } - urlPath <- "/pet" + url_path <- "/pet" # 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - UpdatePetWithForm = function(pet.id, name=NULL, status=NULL, ...){ - apiResponse <- self$UpdatePetWithFormWithHttpInfo(pet.id, name, status, ...) - resp <- apiResponse$response + UpdatePetWithForm = function(pet.id, name=NULL, status=NULL, ...) { + api_response <- self$UpdatePetWithFormWithHttpInfo(pet.id, name, status, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - UpdatePetWithFormWithHttpInfo = function(pet.id, name=NULL, status=NULL, ...){ + UpdatePetWithFormWithHttpInfo = function(pet.id, name=NULL, status=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`pet.id`)) { stop("Missing required parameter `pet.id`.") @@ -688,49 +681,49 @@ PetApi <- R6::R6Class( "status" = status ) - urlPath <- "/pet/{petId}" + url_path <- "/pet/{petId}" 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 - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - UploadFile = function(pet.id, additional.metadata=NULL, file=NULL, data_file=NULL, ...){ - apiResponse <- self$UploadFileWithHttpInfo(pet.id, additional.metadata, file, data_file=data_file, ...) - resp <- apiResponse$response + UploadFile = function(pet.id, additional.metadata=NULL, file=NULL, data_file=NULL, ...) { + api_response <- self$UploadFileWithHttpInfo(pet.id, additional.metadata, file, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - 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(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`pet.id`)) { stop("Missing required parameter `pet.id`.") @@ -741,18 +734,18 @@ PetApi <- R6::R6Class( "file" = httr::upload_file(file) ) - urlPath <- "/pet/{petId}/uploadImage" + url_path <- "/pet/{petId}/uploadImage" 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 - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -763,14 +756,14 @@ PetApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index ce7e31505a9e..6f63fc58761f 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class #' @title Store operations #' @description petstore.Store #' @format An \code{R6Class} generator object -#' @field apiClient Handles the client-server communication. +#' @field api_client Handles the client-server communication. #' #' @section Methods: #' \describe{ @@ -131,7 +130,7 @@ #' api.instance <- StoreApi$new() #' #' #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() #' @@ -165,92 +164,92 @@ StoreApi <- R6::R6Class( 'StoreApi', public = list( - apiClient = NULL, - initialize = function(apiClient){ - if (!missing(apiClient)) { - self$apiClient <- apiClient + api_client = NULL, + initialize = function(api_client) { + if (!missing(api_client)) { + self$api_client <- api_client } else { - self$apiClient <- ApiClient$new() + self$api_client <- ApiClient$new() } }, - DeleteOrder = function(order.id, ...){ - apiResponse <- self$DeleteOrderWithHttpInfo(order.id, ...) - resp <- apiResponse$response + DeleteOrder = function(order.id, ...) { + api_response <- self$DeleteOrderWithHttpInfo(order.id, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - DeleteOrderWithHttpInfo = function(order.id, ...){ + DeleteOrderWithHttpInfo = function(order.id, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`order.id`)) { stop("Missing required parameter `order.id`.") } body <- NULL - urlPath <- "/store/order/{orderId}" + url_path <- "/store/order/{orderId}" 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - GetInventory = function(data_file=NULL, ...){ - apiResponse <- self$GetInventoryWithHttpInfo(data_file=data_file, ...) - resp <- apiResponse$response + GetInventory = function(data_file=NULL, ...) { + api_response <- self$GetInventoryWithHttpInfo(data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - GetInventoryWithHttpInfo = function(data_file=NULL, ...){ + GetInventoryWithHttpInfo = function(data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() body <- NULL - urlPath <- "/store/inventory" + url_path <- "/store/inventory" # API key authentication - if ("api_key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["api_key"]) > 0) { - headerParams['api_key'] <- paste(unlist(self$apiClient$apiKeys["api_key"]), collapse='') + if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) { + 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -261,54 +260,54 @@ StoreApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "map(integer)", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "map(integer)", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - GetOrderById = function(order.id, data_file=NULL, ...){ - apiResponse <- self$GetOrderByIdWithHttpInfo(order.id, data_file=data_file, ...) - resp <- apiResponse$response + GetOrderById = function(order.id, data_file=NULL, ...) { + api_response <- self$GetOrderByIdWithHttpInfo(order.id, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - GetOrderByIdWithHttpInfo = function(order.id, data_file=NULL, ...){ + GetOrderByIdWithHttpInfo = function(order.id, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`order.id`)) { stop("Missing required parameter `order.id`.") } body <- NULL - urlPath <- "/store/order/{orderId}" + url_path <- "/store/order/{orderId}" 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -319,38 +318,38 @@ StoreApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - PlaceOrder = function(body, data_file=NULL, ...){ - apiResponse <- self$PlaceOrderWithHttpInfo(body, data_file=data_file, ...) - resp <- apiResponse$response + PlaceOrder = function(body, data_file=NULL, ...) { + api_response <- self$PlaceOrderWithHttpInfo(body, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - PlaceOrderWithHttpInfo = function(body, data_file=NULL, ...){ + PlaceOrderWithHttpInfo = function(body, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") @@ -362,12 +361,12 @@ StoreApi <- R6::R6Class( 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -378,14 +377,14 @@ StoreApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "Order", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/tag.R b/samples/client/petstore/R/R/tag.R index ba2def34c43b..a58c5e4e3a21 100644 --- a/samples/client/petstore/R/R/tag.R +++ b/samples/client/petstore/R/R/tag.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/user.R b/samples/client/petstore/R/R/user.R index 47ffaea0d88f..b707af603278 100644 --- a/samples/client/petstore/R/R/user.R +++ b/samples/client/petstore/R/R/user.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index cfaf17a01532..d37e986a90c0 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -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. # # The version of the OpenAPI document: 1.0.0 -# # Generated by: https://openapi-generator.tech #' @docType class #' @title User operations #' @description petstore.User #' @format An \code{R6Class} generator object -#' @field apiClient Handles the client-server communication. +#' @field api_client Handles the client-server communication. #' #' @section Methods: #' \describe{ @@ -282,33 +281,33 @@ UserApi <- R6::R6Class( 'UserApi', public = list( - apiClient = NULL, - initialize = function(apiClient){ - if (!missing(apiClient)) { - self$apiClient <- apiClient + api_client = NULL, + initialize = function(api_client) { + if (!missing(api_client)) { + self$api_client <- api_client } else { - self$apiClient <- ApiClient$new() + self$api_client <- ApiClient$new() } }, - CreateUser = function(body, ...){ - apiResponse <- self$CreateUserWithHttpInfo(body, ...) - resp <- apiResponse$response + CreateUser = function(body, ...) { + api_response <- self$CreateUserWithHttpInfo(body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - CreateUserWithHttpInfo = function(body, ...){ + CreateUserWithHttpInfo = function(body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") @@ -320,204 +319,204 @@ UserApi <- R6::R6Class( body <- NULL } - urlPath <- "/user" + url_path <- "/user" - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - CreateUsersWithArrayInput = function(body, ...){ - apiResponse <- self$CreateUsersWithArrayInputWithHttpInfo(body, ...) - resp <- apiResponse$response + CreateUsersWithArrayInput = function(body, ...) { + api_response <- self$CreateUsersWithArrayInputWithHttpInfo(body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - CreateUsersWithArrayInputWithHttpInfo = function(body, ...){ + CreateUsersWithArrayInputWithHttpInfo = function(body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") } if (!missing(`body`)) { - body.items = paste(unlist(lapply(body, function(param){param$toJSONString()})), collapse = ",") + body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",") body <- paste0('[', body.items, ']') } else { body <- NULL } - urlPath <- "/user/createWithArray" + url_path <- "/user/createWithArray" - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - CreateUsersWithListInput = function(body, ...){ - apiResponse <- self$CreateUsersWithListInputWithHttpInfo(body, ...) - resp <- apiResponse$response + CreateUsersWithListInput = function(body, ...) { + api_response <- self$CreateUsersWithListInputWithHttpInfo(body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - CreateUsersWithListInputWithHttpInfo = function(body, ...){ + CreateUsersWithListInputWithHttpInfo = function(body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`body`)) { stop("Missing required parameter `body`.") } if (!missing(`body`)) { - body.items = paste(unlist(lapply(body, function(param){param$toJSONString()})), collapse = ",") + body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",") body <- paste0('[', body.items, ']') } else { body <- NULL } - urlPath <- "/user/createWithList" + url_path <- "/user/createWithList" - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - DeleteUser = function(username, ...){ - apiResponse <- self$DeleteUserWithHttpInfo(username, ...) - resp <- apiResponse$response + DeleteUser = function(username, ...) { + api_response <- self$DeleteUserWithHttpInfo(username, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - DeleteUserWithHttpInfo = function(username, ...){ + DeleteUserWithHttpInfo = function(username, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`username`)) { stop("Missing required parameter `username`.") } body <- NULL - urlPath <- "/user/{username}" + url_path <- "/user/{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 = "DELETE", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - GetUserByName = function(username, data_file=NULL, ...){ - apiResponse <- self$GetUserByNameWithHttpInfo(username, data_file=data_file, ...) - resp <- apiResponse$response + GetUserByName = function(username, data_file=NULL, ...) { + api_response <- self$GetUserByNameWithHttpInfo(username, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - GetUserByNameWithHttpInfo = function(username, data_file=NULL, ...){ + GetUserByNameWithHttpInfo = function(username, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`username`)) { stop("Missing required parameter `username`.") } body <- NULL - urlPath <- "/user/{username}" + url_path <- "/user/{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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -528,38 +527,38 @@ UserApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "User", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "User", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - LoginUser = function(username, password, data_file=NULL, ...){ - apiResponse <- self$LoginUserWithHttpInfo(username, password, data_file=data_file, ...) - resp <- apiResponse$response + LoginUser = function(username, password, data_file=NULL, ...) { + api_response <- self$LoginUserWithHttpInfo(username, password, data_file=data_file, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - LoginUserWithHttpInfo = function(username, password, data_file=NULL, ...){ + LoginUserWithHttpInfo = function(username, password, data_file=NULL, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`username`)) { stop("Missing required parameter `username`.") @@ -569,17 +568,13 @@ UserApi <- R6::R6Class( stop("Missing required parameter `password`.") } - queryParams['username'] <- username - - queryParams['password'] <- password - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) @@ -590,77 +585,77 @@ UserApi <- R6::R6Class( } deserializedRespObj <- tryCatch( - self$apiClient$deserialize(resp, "character", loadNamespace("petstore")), - error = function(e){ + self$api_client$deserialize(resp, "character", loadNamespace("petstore")), + error = function(e) { stop("Failed to deserialize response") } ) ApiResponse$new(deserializedRespObj, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - LogoutUser = function(...){ - apiResponse <- self$LogoutUserWithHttpInfo(...) - resp <- apiResponse$response + LogoutUser = function(...) { + api_response <- self$LogoutUserWithHttpInfo(...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - LogoutUserWithHttpInfo = function(...){ + LogoutUserWithHttpInfo = function(...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() body <- NULL - urlPath <- "/user/logout" + url_path <- "/user/logout" - 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", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { ApiResponse$new("API server error", resp) } }, - UpdateUser = function(username, body, ...){ - apiResponse <- self$UpdateUserWithHttpInfo(username, body, ...) - resp <- apiResponse$response + UpdateUser = function(username, body, ...) { + api_response <- self$UpdateUserWithHttpInfo(username, body, ...) + resp <- api_response$response 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) { - apiResponse + api_response } 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) { - apiResponse + api_response } }, - UpdateUserWithHttpInfo = function(username, body, ...){ + UpdateUserWithHttpInfo = function(username, body, ...) { args <- list(...) - queryParams <- list() - headerParams <- c() + query_params <- list() + header_params <- c() if (missing(`username`)) { stop("Missing required parameter `username`.") @@ -676,23 +671,23 @@ UserApi <- R6::R6Class( body <- NULL } - urlPath <- "/user/{username}" + url_path <- "/user/{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 = "PUT", - queryParams = queryParams, - headerParams = headerParams, + query_params = query_params, + header_params = header_params, body = body, ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { ApiResponse$new(NULL, resp) } 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) { ApiResponse$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 6e7cde566e14..c32091b01a66 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -3,10 +3,10 @@ petApi <- PetApi$new() petId <- 123321 pet <- Pet$new("name_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, 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" ) @@ -21,7 +21,7 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", { pet0 <- Pet$new() jsonpet <- pet0$toJSON() pet2 <- pet0$fromJSON( - jsonlite::toJSON(jsonpet, auto_unbox=TRUE) + jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) expect_equal(pet0, pet2) jsonpet <- pet0$toJSONString() @@ -38,16 +38,16 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", { pet1 <- Pet$new("name_test", list("photo_test", "second test"), - category = Category$new(id=450, name="test_cat"), + category = Category$new(id = 450, name = "test_cat"), id = petId, 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" ) jsonpet <- pet1$toJSON() pet2 <- pet1$fromJSON( - jsonlite::toJSON(jsonpet, auto_unbox=TRUE) + jsonlite::toJSON(jsonpet, auto_unbox = TRUE) ) expect_equal(pet1, pet2) @@ -65,9 +65,9 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", { }) test_that("Test Category", { - c1 <- Category$new(id=450, name="test_cat") + c1 <- Category$new(id = 450, name = "test_cat") 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) c2$fromJSONString(c1$toJSONString()) expect_equal(c1, c2) @@ -82,18 +82,18 @@ test_that("GetPetById", { list("photo_test", "second test") ) 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( 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 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 <- petApi$GetPetById(petId, data_file = "get_pet_by_id.json") response <- read_json("get_pet_by_id.json") expect_true(!is.null(response)) expect_equal(response$id, petId) From 48795deff29e79510677268499bdfde4685dd1eb Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 18 May 2022 02:07:51 +0800 Subject: [PATCH 2/2] more code format improvement --- .../src/main/resources/r/api.mustache | 24 ++++----- .../src/main/resources/r/api_test.mustache | 5 +- .../src/main/resources/r/model_test.mustache | 5 +- samples/client/petstore/R/R/pet_api.R | 50 +++++++++---------- samples/client/petstore/R/R/store_api.R | 28 +++++------ samples/client/petstore/R/R/user_api.R | 22 ++++---- .../petstore/R/tests/testthat/test_petstore.R | 28 +++++------ 7 files changed, 80 insertions(+), 82 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index 0d123905c45c..b0bf90a47463 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -147,7 +147,7 @@ {{/useRlangExceptionHandling}} #' @export {{classname}} <- R6::R6Class( - '{{classname}}', + "{{classname}}", public = list( api_client = NULL, initialize = function(api_client) { @@ -160,7 +160,7 @@ }, {{#operation}} {{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#returnType}}data_file=NULL, {{/returnType}}...) { - api_response <- 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 <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -173,7 +173,7 @@ } }, - {{{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(...) query_params <- list() header_params <- c() @@ -190,11 +190,11 @@ {{/requiredParams}} {{#header_params}} - header_params['{{baseName}}'] <- `{{paramName}}` + header_params["{{baseName}}"] <- `{{paramName}}` {{/header_params}} {{#query_params}} - query_params['{{baseName}}'] <- {{paramName}} + query_params["{{baseName}}"] <- {{paramName}} {{/query_params}} {{#hasFormParams}} @@ -215,7 +215,7 @@ if (!missing(`{{paramName}}`)) { {{#isArray}} body.items = paste(unlist(lapply({{paramName}}, function(param) {param$toJSONString()})), collapse = ",") - body <- paste0('[', body.items, ']') + body <- paste0("[", body.items, "]") {{/isArray}} {{^isArray}} body <- `{{paramName}}`$toJSONString() @@ -244,25 +244,25 @@ {{#isBasic}} {{#isBasicBasic}} # HTTP basic auth - header_params['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep=":")))) + header_params["Authorization"] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$api_client$username, self$api_client$password, sep = ":")))) {{/isBasicBasic}} {{/isBasic}} {{#isApiKey}} # API key authentication {{#isKeyInHeader}} if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) { - header_params['{{keyParamName}}'] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse='') + header_params["{{keyParamName}}"] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse = "") } {{/isKeyInHeader}} {{#isKeyInQuery}} if ("{{{keyParamName}}}" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["{{{keyParamName}}}"]) > 0) { - query_params['{{keyParamName}}'] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse='') + query_params["{{keyParamName}}"] <- paste(unlist(self$api_client$api_keys["{{keyParamName}}"]), collapse = "") } {{/isKeyInQuery}} {{/isApiKey}} {{#isOAuth}} # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") {{/isOAuth}} {{/authMethods}} @@ -292,7 +292,7 @@ write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "{{returnType}}", loadNamespace("{{packageName}}")), error = function(e) { {{#useDefaultExceptionHandling}} @@ -303,7 +303,7 @@ {{/useRlangExceptionHandling}} } ) - ApiResponse$new(deserializedRespObj, resp) + ApiResponse$new(deserialized_resp_obj, resp) {{/isPrimitiveType}} {{/returnType}} {{^returnType}} diff --git a/modules/openapi-generator/src/main/resources/r/api_test.mustache b/modules/openapi-generator/src/main/resources/r/api_test.mustache index c78273ede382..ab7b11ffb44d 100644 --- a/modules/openapi-generator/src/main/resources/r/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_test.mustache @@ -3,10 +3,10 @@ context("Test {{{classname}}}") -api.instance <- {{{classname}}}$new() - +api_instance <- {{{classname}}}$new() {{#operations}} {{#operation}} + test_that("{{{operationId}}}", { # tests for {{operationId}} # base path: {{{basePath}}} @@ -24,6 +24,5 @@ test_that("{{{operationId}}}", { # uncomment below to test the operation #expect_equal(result, "EXPECTED_RESULT") }) - {{/operation}} {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/r/model_test.mustache b/modules/openapi-generator/src/main/resources/r/model_test.mustache index a6e8115fe2b8..7d879590ce62 100644 --- a/modules/openapi-generator/src/main/resources/r/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/r/model_test.mustache @@ -8,9 +8,9 @@ context("Test {{{classname}}}") {{#vars}} {{#-first}} -model.instance <- {{{classname}}}$new() - +model_instance <- {{{classname}}}$new() {{/-first}} + test_that("{{{name}}}", { # tests for the property `{{{name}}}` ({{dataType}}) {{#description}} @@ -20,7 +20,6 @@ test_that("{{{name}}}", { # uncomment below to test the property #expect_equal(model.instance$`{{{name}}}`, "EXPECTED_RESULT") }) - {{/vars}} {{/isEnum}} {{/model}} diff --git a/samples/client/petstore/R/R/pet_api.R b/samples/client/petstore/R/R/pet_api.R index c871e57b6d9c..612c78e466ae 100644 --- a/samples/client/petstore/R/R/pet_api.R +++ b/samples/client/petstore/R/R/pet_api.R @@ -319,7 +319,7 @@ #' @importFrom base64enc base64encode #' @export PetApi <- R6::R6Class( - 'PetApi', + "PetApi", public = list( api_client = NULL, initialize = function(api_client) { @@ -361,7 +361,7 @@ PetApi <- R6::R6Class( url_path <- "/pet" # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "POST", @@ -410,7 +410,7 @@ PetApi <- R6::R6Class( } # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "DELETE", @@ -430,7 +430,7 @@ PetApi <- R6::R6Class( } }, FindPetsByStatus = function(status, data_file=NULL, ...) { - api_response <- self$FindPetsByStatusWithHttpInfo(status, data_file=data_file, ...) + api_response <- self$FindPetsByStatusWithHttpInfo(status, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -443,7 +443,7 @@ PetApi <- R6::R6Class( } }, - FindPetsByStatusWithHttpInfo = function(status, data_file=NULL, ...) { + FindPetsByStatusWithHttpInfo = function(status, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -455,7 +455,7 @@ PetApi <- R6::R6Class( body <- NULL url_path <- "/pet/findByStatus" # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "GET", @@ -470,13 +470,13 @@ PetApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -486,7 +486,7 @@ PetApi <- R6::R6Class( } }, FindPetsByTags = function(tags, data_file=NULL, ...) { - api_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file=data_file, ...) + api_response <- self$FindPetsByTagsWithHttpInfo(tags, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -499,7 +499,7 @@ PetApi <- R6::R6Class( } }, - FindPetsByTagsWithHttpInfo = function(tags, data_file=NULL, ...) { + FindPetsByTagsWithHttpInfo = function(tags, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -511,7 +511,7 @@ PetApi <- R6::R6Class( body <- NULL url_path <- "/pet/findByTags" # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "GET", @@ -526,13 +526,13 @@ PetApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "array[Pet]", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -542,7 +542,7 @@ PetApi <- R6::R6Class( } }, GetPetById = function(pet.id, data_file=NULL, ...) { - api_response <- self$GetPetByIdWithHttpInfo(pet.id, data_file=data_file, ...) + api_response <- self$GetPetByIdWithHttpInfo(pet.id, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -555,7 +555,7 @@ PetApi <- R6::R6Class( } }, - GetPetByIdWithHttpInfo = function(pet.id, data_file=NULL, ...) { + GetPetByIdWithHttpInfo = function(pet.id, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -572,7 +572,7 @@ PetApi <- R6::R6Class( # API key authentication if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) { - header_params['api_key'] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse='') + header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "") } resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), @@ -588,13 +588,13 @@ PetApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Pet", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -634,7 +634,7 @@ PetApi <- R6::R6Class( url_path <- "/pet" # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "PUT", @@ -687,7 +687,7 @@ PetApi <- R6::R6Class( } # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "POST", @@ -707,7 +707,7 @@ PetApi <- R6::R6Class( } }, UploadFile = function(pet.id, additional.metadata=NULL, file=NULL, data_file=NULL, ...) { - api_response <- 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 <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -720,7 +720,7 @@ PetApi <- R6::R6Class( } }, - 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(...) query_params <- list() header_params <- c() @@ -740,7 +740,7 @@ PetApi <- R6::R6Class( } # OAuth token - header_params['Authorization'] <- paste("Bearer", self$api_client$access_token, sep=" ") + header_params["Authorization"] <- paste("Bearer", self$api_client$access_token, sep = " ") resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), method = "POST", @@ -755,13 +755,13 @@ PetApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "ModelApiResponse", loadNamespace("petstore")), error = function(e) { 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) { 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) { diff --git a/samples/client/petstore/R/R/store_api.R b/samples/client/petstore/R/R/store_api.R index 6f63fc58761f..a18cc02ec798 100644 --- a/samples/client/petstore/R/R/store_api.R +++ b/samples/client/petstore/R/R/store_api.R @@ -162,7 +162,7 @@ #' @importFrom base64enc base64encode #' @export StoreApi <- R6::R6Class( - 'StoreApi', + "StoreApi", public = list( api_client = NULL, initialize = function(api_client) { @@ -221,7 +221,7 @@ StoreApi <- R6::R6Class( } }, GetInventory = function(data_file=NULL, ...) { - api_response <- self$GetInventoryWithHttpInfo(data_file=data_file, ...) + api_response <- self$GetInventoryWithHttpInfo(data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -234,7 +234,7 @@ StoreApi <- R6::R6Class( } }, - GetInventoryWithHttpInfo = function(data_file=NULL, ...) { + GetInventoryWithHttpInfo = function(data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -243,7 +243,7 @@ StoreApi <- R6::R6Class( url_path <- "/store/inventory" # API key authentication if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) { - header_params['api_key'] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse='') + header_params["api_key"] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse = "") } resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path), @@ -259,13 +259,13 @@ StoreApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "map(integer)", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -275,7 +275,7 @@ StoreApi <- R6::R6Class( } }, GetOrderById = function(order.id, data_file=NULL, ...) { - api_response <- self$GetOrderByIdWithHttpInfo(order.id, data_file=data_file, ...) + api_response <- self$GetOrderByIdWithHttpInfo(order.id, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -288,7 +288,7 @@ StoreApi <- R6::R6Class( } }, - GetOrderByIdWithHttpInfo = function(order.id, data_file=NULL, ...) { + GetOrderByIdWithHttpInfo = function(order.id, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -317,13 +317,13 @@ StoreApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -333,7 +333,7 @@ StoreApi <- R6::R6Class( } }, PlaceOrder = function(body, data_file=NULL, ...) { - api_response <- self$PlaceOrderWithHttpInfo(body, data_file=data_file, ...) + api_response <- self$PlaceOrderWithHttpInfo(body, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -346,7 +346,7 @@ StoreApi <- R6::R6Class( } }, - PlaceOrderWithHttpInfo = function(body, data_file=NULL, ...) { + PlaceOrderWithHttpInfo = function(body, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -376,13 +376,13 @@ StoreApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "Order", loadNamespace("petstore")), error = function(e) { 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) { 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) { diff --git a/samples/client/petstore/R/R/user_api.R b/samples/client/petstore/R/R/user_api.R index d37e986a90c0..1d14bc790c9b 100644 --- a/samples/client/petstore/R/R/user_api.R +++ b/samples/client/petstore/R/R/user_api.R @@ -279,7 +279,7 @@ #' @importFrom base64enc base64encode #' @export UserApi <- R6::R6Class( - 'UserApi', + "UserApi", public = list( api_client = NULL, initialize = function(api_client) { @@ -363,7 +363,7 @@ UserApi <- R6::R6Class( if (!missing(`body`)) { body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",") - body <- paste0('[', body.items, ']') + body <- paste0("[", body.items, "]") } else { body <- NULL } @@ -412,7 +412,7 @@ UserApi <- R6::R6Class( if (!missing(`body`)) { body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",") - body <- paste0('[', body.items, ']') + body <- paste0("[", body.items, "]") } else { body <- NULL } @@ -484,7 +484,7 @@ UserApi <- R6::R6Class( } }, GetUserByName = function(username, data_file=NULL, ...) { - api_response <- self$GetUserByNameWithHttpInfo(username, data_file=data_file, ...) + api_response <- self$GetUserByNameWithHttpInfo(username, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -497,7 +497,7 @@ UserApi <- R6::R6Class( } }, - GetUserByNameWithHttpInfo = function(username, data_file=NULL, ...) { + GetUserByNameWithHttpInfo = function(username, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -526,13 +526,13 @@ UserApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "User", loadNamespace("petstore")), error = function(e) { 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) { 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) { @@ -542,7 +542,7 @@ UserApi <- R6::R6Class( } }, LoginUser = function(username, password, data_file=NULL, ...) { - api_response <- self$LoginUserWithHttpInfo(username, password, data_file=data_file, ...) + api_response <- self$LoginUserWithHttpInfo(username, password, data_file = data_file, ...) resp <- api_response$response if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { api_response$content @@ -555,7 +555,7 @@ UserApi <- R6::R6Class( } }, - LoginUserWithHttpInfo = function(username, password, data_file=NULL, ...) { + LoginUserWithHttpInfo = function(username, password, data_file = NULL, ...) { args <- list(...) query_params <- list() header_params <- c() @@ -584,13 +584,13 @@ UserApi <- R6::R6Class( write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file) } - deserializedRespObj <- tryCatch( + deserialized_resp_obj <- tryCatch( self$api_client$deserialize(resp, "character", loadNamespace("petstore")), error = function(e) { 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) { 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) { diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index c32091b01a66..82ccdcbaf624 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -1,19 +1,19 @@ context("basic functionality") -petApi <- PetApi$new() -petId <- 123321 +pet_api <- PetApi$new() +pet_id <- 123321 pet <- Pet$new("name_test", photoUrls = list("photo_test", "second test"), category = Category$new(id = 450, name = "test_cat"), - id = petId, + id = pet_id, tags = list( Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown") ), status = "available" ) -result <- petApi$AddPet(pet) +result <- pet_api$AddPet(pet) test_that("AddPet", { - expect_equal(petId, 123321) + expect_equal(pet_id, 123321) expect_equal(result, NULL) }) @@ -39,7 +39,7 @@ test_that("Test toJSON toJSON fromJSON fromJSONString", { pet1 <- Pet$new("name_test", list("photo_test", "second test"), category = Category$new(id = 450, name = "test_cat"), - id = petId, + id = pet_id, tags = list( Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown") ), @@ -74,8 +74,8 @@ test_that("Test Category", { }) test_that("GetPetById", { - response <- petApi$GetPetById(petId) - expect_equal(response$id, petId) + response <- pet_api$GetPetById(pet_id) + expect_equal(response$id, pet_id) expect_equal(response$name, "name_test") expect_equal( response$photoUrls, @@ -87,16 +87,16 @@ test_that("GetPetById", { expect_equal(pet$tags, response$tags) expect_equal( 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 to ensure json is saved to the file `get_pet_by_id.json` - pet_response <- 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") expect_true(!is.null(response)) - expect_equal(response$id, petId) + expect_equal(response$id, pet_id) expect_equal(response$name, "name_test") }) @@ -105,9 +105,9 @@ test_that("GetPetById with data_file", { # pet <- Pet$new(pet.id, NULL, "name_test2", # list("photo_test2", "second test2"), # 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$name, "name_test2") @@ -118,6 +118,6 @@ test_that("GetPetById with data_file", { #}) #test_that("updatePetWithForm", { -# response <- petApi$updatePetWithForm(petId, "test", "sold") +# response <- pet_api$updatePetWithForm(pet_id, "test", "sold") # expect_equal(response, "Pet updated") #})