feat(r): Added handling exception with ApiException class and better documentation (#3217)

* feat(r): Added handling exception with ApiException class and document generation

* feat(r):enhancements to exception handling and documentation

* fix(r): fixes and reverting the man folder

* fix(r): minor fix of import statement

* fix(r): generated the docs file

* fix(r) minor doc casing fixes
This commit is contained in:
Ramanth Addala
2019-07-03 19:35:21 +05:30
committed by William Cheng
parent dda2f3c141
commit 0cb921251d
22 changed files with 1177 additions and 116 deletions

View File

@@ -5,6 +5,6 @@ If Not Exist %executable% (
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R --additional-properties packageName=petstore
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R --additional-properties packageName=petstore,returnExceptionOnFailure=false,exceptionPackage=default
java %JAVA_OPTS% -jar %executable% %ags%

View File

@@ -10,3 +10,5 @@ sidebar_label: r
|packageName|R package name (convention: lowercase).| |openapi|
|packageVersion|R package version.| |1.0.0|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|returnExceptionOnFailure|Throw an exception on non success response codes| |false|
|exceptionPackage|Specify the exception handling package|<dl><dt>**default**</dt><dd>Use stop() for raising exceptions.</dd><dt>**rlang**</dt><dd>Use rlang package for exceptions.</dd><dl>|default|

View File

@@ -306,4 +306,6 @@ public class CodegenConstants {
public static final String SNAPSHOT_VERSION = "snapshotVersion";
public static final String SNAPSHOT_VERSION_DESC = "Uses a SNAPSHOT version.";
public static final String EXCEPTION_ON_FAILURE = "returnExceptionOnFailure";
public static final String EXCEPTION_ON_FAILURE_DESC = "Throw an exception on non success response codes";
}

View File

@@ -42,6 +42,18 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
protected String testFolder = "tests/testthat";
protected boolean returnExceptionOnFailure = false;
protected String exceptionPackage = "default";
protected Map<String, String> exceptionPackages = new LinkedHashMap<String, String>();
public static final String EXCEPTION_PACKAGE = "exceptionPackage";
public static final String USE_DEFAULT_EXCEPTION = "useDefaultExceptionHandling";
public static final String USE_RLANG_EXCEPTION = "useRlangExceptionHandling";
public static final String DEFAULT = "default";
public static final String RLANG = "rlang";
protected boolean useDefaultExceptionHandling = false;
protected boolean useRlangExceptionHandling = false;
public CodegenType getTag() {
return CodegenType.CLIENT;
@@ -114,7 +126,16 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
.defaultValue("1.0.0"));
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(CodegenConstants.EXCEPTION_ON_FAILURE, CodegenConstants.EXCEPTION_ON_FAILURE_DESC)
.defaultValue(Boolean.FALSE.toString()));
exceptionPackages.put(DEFAULT, "Use stop() for raising exceptions.");
exceptionPackages.put(RLANG, "Use rlang package for exceptions.");
CliOption exceptionPackage = new CliOption(EXCEPTION_PACKAGE, "Specify the exception handling package");
exceptionPackage.setEnum(exceptionPackages);
exceptionPackage.setDefault(DEFAULT);
cliOptions.add(exceptionPackage);
}
@Override
@@ -133,8 +154,27 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
setPackageVersion("1.0.0");
}
if (additionalProperties.containsKey(CodegenConstants.EXCEPTION_ON_FAILURE)) {
boolean booleanValue = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCEPTION_ON_FAILURE).toString());
setReturnExceptionOnFailure(booleanValue);
} else {
setReturnExceptionOnFailure(false);
}
if (additionalProperties.containsKey(EXCEPTION_PACKAGE)) {
String exceptionPackage = additionalProperties.get(EXCEPTION_PACKAGE).toString();
setExceptionPackageToUse(exceptionPackage);
} else {
setExceptionPackageToUse(DEFAULT);
}
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
additionalProperties.put(CodegenConstants.EXCEPTION_ON_FAILURE, returnExceptionOnFailure);
additionalProperties.put(USE_DEFAULT_EXCEPTION, this.useDefaultExceptionHandling);
additionalProperties.put(USE_RLANG_EXCEPTION, this.useRlangExceptionHandling);
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
@@ -384,6 +424,19 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
this.packageVersion = packageVersion;
}
public void setReturnExceptionOnFailure(boolean returnExceptionOnFailure) {
this.returnExceptionOnFailure = returnExceptionOnFailure;
}
public void setExceptionPackageToUse(String exceptionPackage) {
if(DEFAULT.equals(exceptionPackage))
this.useDefaultExceptionHandling = true;
if(RLANG.equals(exceptionPackage)){
supportingFiles.add(new SupportingFile("api_exception.mustache", File.separator + "R", "api_exception.R"));
this.useRlangExceptionHandling = true;
}
}
@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection

View File

@@ -1,6 +1,9 @@
#' ApiResponse Class
#'
#' ApiResponse Class
#' @docType class
#' @title ApiResponse
#' @description ApiResponse Class
#' @format An \code{R6Class} generator object
#' @field content The deserialized response body.
#' @field response The raw response from the endpoint.
#' @export
ApiResponse <- R6::R6Class(
'ApiResponse',

View File

@@ -1,23 +1,150 @@
{{>partial_header}}
{{#operations}}
#' @docType class
#' @title {{baseName}} operations
#' @description {{importPath}}
#'
#' @field path Stores url path of the request.
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
{{! Adding the below changes for generating documentation for the api methods. }}
#' \describe{
{{#operation}}
#' \strong{ {{operationId}} } \emph{ {{summary}} }
#' {{notes}}
#'
#' {{operationId}} {{summary}}
#' \itemize{
{{#allParams}}
{{#isEnum}}
#' \item \emph{ @param } {{paramName}} Enum < {{#allowableValues}}{{values}}{{/allowableValues}} >
{{/isEnum}}
{{^isEnum}}
{{#isContainer}}
{{#isListContainer}}
{{#items}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} list( {{dataType}} )
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} list( \link[{{packageName}}:{{baseType}}]{ {{dataType}} } )
{{/isPrimitiveType}}
{{/items}}
{{/isListContainer}}
{{#isMapContainer}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} named list( {{dataType}} )
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} named list( \link[{{packageName}}:{{baseType}}]{ {{dataType}} } )
{{/isPrimitiveType}}
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} {{dataType}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} \link[{{packageName}}:{{baseType}}]{ {{dataType}} }
{{/isPrimitiveType}}
{{/isContainer}}
{{/isEnum}}
{{/allParams}}
{{#returnType}}
{{^returnTypeIsPrimitive}}
#' \item \emph{ @returnType } \link[{{packageName}}:{{returnBaseType}}]{ {{#returnContainer}}{{#isListContainer}}list({{returnBaseType}}){{/isListContainer}}{{#isMapContainer}}named list({{returnBaseType}}){{/isMapContainer}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{/returnContainer}} } \cr
{{/returnTypeIsPrimitive}}
{{/returnType}}
#'
{{#useRlangExceptionHandling}}
#' \item On encountering errors, an error of subclass ApiException will be thrown.
{{/useRlangExceptionHandling}}
#'
{{#responses}}
#' \item status code : {{code}} | {{message}}
#'
#'{{#dataType}} \item return type : {{dataType}} {{/dataType}}
#' \item response headers :
#'
#' \tabular{ll}{
{{#headers}}
#' {{name}} \tab {{description}} \cr
{{/headers}}
#' }
{{/responses}}
#' }
#'
{{/operation}}
#' }
#'
#'
#' @examples
#' \donttest{
{{#operation}}
#' #################### {{operationId}} ####################
#'
#' library({{{packageName}}})
{{#allParams}}
#' var.{{{paramName}}} <- {{{example}}} # {{{dataType}}} | {{{description}}}
{{/allParams}}
#'
{{#summary}}
#' #{{{.}}}
{{/summary}}
#' api.instance <- {{{classname}}}$new()
{{#hasAuthMethods}}
{{#authMethods}}
#'
{{#isBasic}}
#' #Configure HTTP basic authorization: {{{name}}}
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>';
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
{{/isBasic}}
{{#isApiKey}}
#' #Configure API key authorization: {{{name}}}
#' api.instance$apiClient$apiKeys['{{{keyParamName}}}'] <- 'TODO_YOUR_API_KEY';
{{/isApiKey}}
{{#isOAuth}}
#' # Configure OAuth2 access token for authorization: {{{name}}}
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
#'
{{#returnExceptionOnFailure}}
{{#useRlangExceptionHandling}}
#'result <- tryCatch(
#' api.instance${{{operationId}}}({{#requiredParams}}var.{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var.{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}}),
#' ApiException = function(ex) ex
#' )
#' # In case of error, print the error object
#' if(!is.null(result$ApiException)) {
#' cat(result$ApiException$toString())
#' } else {
{{#returnType}}
#' # deserialized response object
#' response.object <- result$content
{{/returnType}}
#' # response headers
#' response.headers <- result$response$headers
#' # response status code
#' response.status.code <- result$response$status_code
#' }
{{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}}
{{^useRlangExceptionHandling}}
#' result <- api.instance${{{operationId}}}({{#requiredParams}}var.{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var.{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}})
{{/useRlangExceptionHandling}}
#'
#'
{{/operation}}
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
{{#useRlangExceptionHandling}}
#' @importFrom rlang abort
{{/useRlangExceptionHandling}}
#' @export
{{classname}} <- R6::R6Class(
'{{classname}}',
@@ -51,7 +178,12 @@
{{#requiredParams}}
if (missing(`{{paramName}}`)) {
{{#useDefaultExceptionHandling}}
stop("Missing required parameter `{{{paramName}}}`.")
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = "Missing required parameter `{{{paramName}}}`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `{{{paramName}}}`."))
{{/useRlangExceptionHandling}}
}
{{/requiredParams}}
@@ -141,7 +273,17 @@
ApiResponse$new(content,resp)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
deserializedRespObj <- self$apiClient$deserialize(resp, "{{returnType}}", "package:{{packageName}}")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "{{returnType}}", "package:{{packageName}}"),
error = function(e){
{{#useDefaultExceptionHandling}}
stop("Failed to deserialize response")
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}}
}
)
ApiResponse$new(deserializedRespObj, resp)
{{/isPrimitiveType}}
{{/returnType}}
@@ -150,9 +292,37 @@
ApiResponse$new(NULL, resp)
{{/returnType}}
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
{{#returnExceptionOnFailure}}
errorMsg <- toString(content(resp))
if(errorMsg == ""){
errorMsg <- "Api client exception encountered."
}
{{#useDefaultExceptionHandling}}
stop(errorMsg)
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}}
{{^returnExceptionOnFailure}}
ApiResponse$new("API client error", resp)
{{/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."
}
{{#useDefaultExceptionHandling}}
stop(errorMsg)
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
{{/useRlangExceptionHandling}}
{{/returnExceptionOnFailure}}
{{^returnExceptionOnFailure}}
ApiResponse$new("API server error", resp)
{{/returnExceptionOnFailure}}
}
}{{#hasMore}},{{/hasMore}}
{{/operation}}

View File

@@ -12,14 +12,22 @@
#' Ref: https://openapi-generator.tech
#' Do not edit the class manually.
#'
#' @field basePath
#' @field userAgent
#' @docType class
#' @title ApiClient
#' @description ApiClient Class
#' @format An \code{R6Class} generator object
#' @field basePath Base url
#' @field userAgent Default user agent
#' @field defaultHeaders
#' @field username
#' @field password
#' @field username Username for HTTP basic authentication
#' @field password Password for HTTP basic authentication
#' @field apiKeys
#' @field accessToken
#' @importFrom httr
#' @field timeout Default timeout in seconds
#' @importFrom httr add_headers accept timeout content
{{#useRlangExceptionHandling}}
#' @importFrom rlang abort
{{/useRlangExceptionHandling}}
#' @export
ApiClient <- R6::R6Class(
'ApiClient',
@@ -98,26 +106,42 @@ ApiClient <- R6::R6Class(
} else if (method == "DELETE") {
httr::DELETE(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...)
} else {
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
errMsg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`."
{{#useDefaultExceptionHandling}}
stop(errMsg)
{{/useDefaultExceptionHandling}}
{{#useRlangExceptionHandling}}
rlang::abort(message = errMsg, .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = errMsg))
{{/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 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.,
deserializeObj = function(obj, returnType, pkgEnv) {
returnObj <- NULL
primitiveTypes <- 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)
})
names(returnObj) <- names(obj)
} else if (startsWith(returnType, "array[")) {
}
# 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))
@@ -134,11 +158,17 @@ ApiClient <- R6::R6Class(
}
}
}
} else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) {
}
# 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(jsonlite::toJSON(obj, digits = NA))
} else {
}
# To handle primitive type
else {
returnObj <- obj
}
returnObj

View File

@@ -0,0 +1,55 @@
{{! ApiException class for returning the ApiException object on encountering errors}}
#' @docType class
#' @title ApiException
#' @description ApiException Class
#' @format An \code{R6Class} generator object
#' @field status Status of the ApiException
#' @field reason Reason of the ApiException
#' @field body Body of the http response
#' @field headers Headers of the http response
#' @export
ApiException <- R6::R6Class(
"ApiException",
public = list(
status = NULL,
reason = NULL,
body = NULL,
headers = NULL,
initialize = function(status = NULL, reason = NULL, http_response = NULL) {
if (!is.null(http_response)) {
self$status <- http_response$status_code
errorMsg <- toString(content(http_response))
if(errorMsg == ""){
errorMsg <- "Api exception encountered."
}
self$body <- errorMsg
self$headers <- http_response$headers
self$reason <- httr::http_status(http_response)$reason
} else {
self$status <- status
self$reason <- reason
self$body <- NULL
self$headers <- NULL
}
},
# returns the string format of ApiException
toString = function() {
errorMsg <- ""
errorMsg <- paste("status : ", self$status, "\n", sep = "")
errorMsg <- paste(errorMsg, "Reason : ", self$reason, "\n", sep = "")
if (!is.null(self$headers)) {
errorMsg <- paste(errorMsg, "Headers : ", "\n", sep = "")
for (name in names(self$headers)) {
errorMsg <- paste(errorMsg, name, " : ", self$headers[[name]], "\n", sep = " ")
}
}
if (!is.null(self$body)) {
errorMsg <- paste(errorMsg, "Body : ", "\n", sep = "")
errorMsg <- paste(errorMsg, self$body,"\n")
}
errorMsg
}
)
)

View File

@@ -8,5 +8,5 @@ Encoding: UTF-8
License: Unlicense
LazyData: true
Suggests: testthat
Imports: jsonlite, httr, R6, caTools
Imports: jsonlite, httr, R6, caTools{{#useRlangExceptionHandling}}, rlang{{/useRlangExceptionHandling}}
RoxygenNote: 6.0.1.9000

View File

@@ -1,11 +1,13 @@
{{#models}}
{{#model}}
{{>partial_header}}
#' {{classname}} Class
#'
#' @docType class
#' @title {{classname}}
#' @description {{classname}} Class
#' @format An \code{R6Class} generator object
{{#vars}}
#' @field {{baseName}} {{title}}
#' @field {{baseName}} {{title}} {{^isPrimitiveType}} \link[{{packageName}}:{{complexType}}]{ {{/isPrimitiveType}} {{#isContainer}} {{#isListContainer}}list({{#items}}{{dataType}}{{/items}}){{/isListContainer}}{{#isMapContainer}}named list({{#items}}{{dataType}}{{/items}}){{/isMapContainer}} {{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}} {{^isPrimitiveType}} } {{/isPrimitiveType}} {{^required}}[optional]{{/required}}
#'
{{/vars}}
#'
#' @importFrom R6 R6Class

View File

@@ -19,14 +19,19 @@
#' Ref: https://openapi-generator.tech
#' Do not edit the class manually.
#'
#' @field basePath
#' @field userAgent
#' @docType class
#' @title ApiClient
#' @description ApiClient Class
#' @format An \code{R6Class} generator object
#' @field basePath Base url
#' @field userAgent Default user agent
#' @field defaultHeaders
#' @field username
#' @field password
#' @field username Username for HTTP basic authentication
#' @field password Password for HTTP basic authentication
#' @field apiKeys
#' @field accessToken
#' @importFrom httr
#' @field timeout Default timeout in seconds
#' @importFrom httr add_headers accept timeout content
#' @export
ApiClient <- R6::R6Class(
'ApiClient',
@@ -104,26 +109,37 @@ ApiClient <- R6::R6Class(
} else if (method == "DELETE") {
httr::DELETE(url, query = queryParams, headers, httpTimeout, httpTimeout, httr::user_agent(self$`userAgent`), ...)
} else {
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
errMsg <- "Http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`."
stop(errMsg)
}
},
# 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 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.,
deserializeObj = function(obj, returnType, pkgEnv) {
returnObj <- NULL
primitiveTypes <- 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)
})
names(returnObj) <- names(obj)
} else if (startsWith(returnType, "array[")) {
}
# 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))
@@ -140,11 +156,17 @@ ApiClient <- R6::R6Class(
}
}
}
} else if (exists(returnType, pkgEnv) && !(c(returnType) %in% primitiveTypes)) {
}
# 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(jsonlite::toJSON(obj, digits = NA))
} else {
}
# To handle primitive type
else {
returnObj <- obj
}
returnObj

View File

@@ -1,6 +1,9 @@
#' ApiResponse Class
#'
#' ApiResponse Class
#' @docType class
#' @title ApiResponse
#' @description ApiResponse Class
#' @format An \code{R6Class} generator object
#' @field content The deserialized response body.
#' @field response The raw response from the endpoint.
#' @export
ApiResponse <- R6::R6Class(
'ApiResponse',

View File

@@ -6,11 +6,14 @@
#
# Generated by: https://openapi-generator.tech
#' Category Class
#' @docType class
#' @title Category
#' @description Category Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#'
#' @field name character [optional]
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,12 +6,16 @@
#
# Generated by: https://openapi-generator.tech
#' ModelApiResponse Class
#' @docType class
#' @title ModelApiResponse
#' @description ModelApiResponse Class
#' @format An \code{R6Class} generator object
#' @field code integer [optional]
#'
#' @field type character [optional]
#'
#' @field message character [optional]
#'
#' @field code
#' @field type
#' @field message
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,15 +6,22 @@
#
# Generated by: https://openapi-generator.tech
#' Order Class
#' @docType class
#' @title Order
#' @description Order Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#'
#' @field petId integer [optional]
#'
#' @field quantity integer [optional]
#'
#' @field shipDate character [optional]
#'
#' @field status character [optional]
#'
#' @field complete character [optional]
#'
#' @field id
#' @field petId
#' @field quantity
#' @field shipDate
#' @field status
#' @field complete
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,15 +6,22 @@
#
# Generated by: https://openapi-generator.tech
#' Pet Class
#' @docType class
#' @title Pet
#' @description Pet Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#'
#' @field category \link[petstore:Category]{ Category } [optional]
#'
#' @field name character
#'
#' @field photoUrls list(character)
#'
#' @field tags \link[petstore:Tag]{ list(Tag) } [optional]
#'
#' @field status character [optional]
#'
#' @field id
#' @field category
#' @field name
#' @field photoUrls
#' @field tags
#' @field status
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,42 +6,317 @@
#
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Pet operations
#' @description petstore.Pet
#'
#' @field path Stores url path of the request.
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#' \strong{ AddPet } \emph{ Add a new pet to the store }
#'
#'
#' AddPet Add a new pet to the store
#' \itemize{
#' \item \emph{ @param } body \link[petstore:Pet]{ Pet }
#'
#'
#' DeletePet Deletes a pet
#' \item status code : 405 | Invalid input
#'
#'
#' FindPetsByStatus Finds Pets by status
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ DeletePet } \emph{ Deletes a pet }
#'
#'
#' \itemize{
#' \item \emph{ @param } pet.id integer
#' \item \emph{ @param } api.key character
#'
#'
#' FindPetsByTags Finds Pets by tags
#' \item status code : 400 | Invalid pet value
#'
#'
#' GetPetById Find pet by ID
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ FindPetsByStatus } \emph{ Finds Pets by status }
#' Multiple status values can be provided with comma separated strings
#'
#' \itemize{
#' \item \emph{ @param } status Enum < [available, pending, sold] >
#' \item \emph{ @returnType } \link[petstore:Pet]{ list(Pet) } \cr
#'
#'
#' UpdatePet Update an existing pet
#' \item status code : 200 | successful operation
#'
#' \item return type : array[Pet]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid status value
#'
#'
#' UpdatePetWithForm Updates a pet in the store with form data
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ FindPetsByTags } \emph{ Finds Pets by tags }
#' Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
#'
#' \itemize{
#' \item \emph{ @param } tags list( character )
#' \item \emph{ @returnType } \link[petstore:Pet]{ list(Pet) } \cr
#'
#'
#' UploadFile uploads an image
#' \item status code : 200 | successful operation
#'
#' \item return type : array[Pet]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid tag value
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetPetById } \emph{ Find pet by ID }
#' Returns a single pet
#'
#' \itemize{
#' \item \emph{ @param } pet.id integer
#' \item \emph{ @returnType } \link[petstore:Pet]{ Pet } \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdatePet } \emph{ Update an existing pet }
#'
#'
#' \itemize{
#' \item \emph{ @param } body \link[petstore:Pet]{ Pet }
#'
#'
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Pet not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 405 | Validation exception
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdatePetWithForm } \emph{ Updates a pet in the store with form data }
#'
#'
#' \itemize{
#' \item \emph{ @param } pet.id integer
#' \item \emph{ @param } name character
#' \item \emph{ @param } status character
#'
#'
#' \item status code : 405 | Invalid input
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UploadFile } \emph{ uploads an image }
#'
#'
#' \itemize{
#' \item \emph{ @param } pet.id integer
#' \item \emph{ @param } additional.metadata character
#' \item \emph{ @param } file data.frame
#' \item \emph{ @returnType } \link[petstore:ApiResponse]{ ModelApiResponse } \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : ModelApiResponse
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \donttest{
#' #################### AddPet ####################
#'
#' library(petstore)
#' var.body <- Pet$new() # Pet | Pet object that needs to be added to the store
#'
#' #Add a new pet to the store
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$AddPet(var.body)
#'
#'
#' #################### DeletePet ####################
#'
#' library(petstore)
#' var.pet.id <- 56 # integer | Pet id to delete
#' var.api.key <- 'api.key_example' # character |
#'
#' #Deletes a pet
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$DeletePet(var.pet.id, api.key=var.api.key)
#'
#'
#' #################### FindPetsByStatus ####################
#'
#' library(petstore)
#' var.status <- ['status_example'] # array[character] | Status values that need to be considered for filter
#'
#' #Finds Pets by status
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$FindPetsByStatus(var.status)
#'
#'
#' #################### FindPetsByTags ####################
#'
#' library(petstore)
#' var.tags <- ['tags_example'] # array[character] | Tags to filter by
#'
#' #Finds Pets by tags
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$FindPetsByTags(var.tags)
#'
#'
#' #################### GetPetById ####################
#'
#' library(petstore)
#' var.pet.id <- 56 # integer | ID of pet to return
#'
#' #Find pet by ID
#' api.instance <- PetApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$GetPetById(var.pet.id)
#'
#'
#' #################### UpdatePet ####################
#'
#' library(petstore)
#' var.body <- Pet$new() # Pet | Pet object that needs to be added to the store
#'
#' #Update an existing pet
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$UpdatePet(var.body)
#'
#'
#' #################### UpdatePetWithForm ####################
#'
#' library(petstore)
#' var.pet.id <- 56 # integer | ID of pet that needs to be updated
#' var.name <- 'name_example' # character | Updated name of the pet
#' var.status <- 'status_example' # character | Updated status of the pet
#'
#' #Updates a pet in the store with form data
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$UpdatePetWithForm(var.pet.id, name=var.name, status=var.status)
#'
#'
#' #################### UploadFile ####################
#'
#' library(petstore)
#' var.pet.id <- 56 # integer | ID of pet to update
#' var.additional.metadata <- 'additional.metadata_example' # character | Additional data to pass to server
#' var.file <- File.new('/path/to/file') # data.frame | file to upload
#'
#' #uploads an image
#' api.instance <- PetApi$new()
#'
#' # Configure OAuth2 access token for authorization: petstore_auth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$UploadFile(var.pet.id, additional.metadata=var.additional.metadata, file=var.file)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
PetApi <- R6::R6Class(
@@ -183,7 +458,12 @@ PetApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "array[Pet]", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "array[Pet]", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -226,7 +506,12 @@ PetApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "array[Pet]", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "array[Pet]", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -273,7 +558,12 @@ PetApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "Pet", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "Pet", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -418,7 +708,12 @@ PetApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "ModelApiResponse", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "ModelApiResponse", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)

View File

@@ -6,30 +6,160 @@
#
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Store operations
#' @description petstore.Store
#'
#' @field path Stores url path of the request.
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#' \strong{ DeleteOrder } \emph{ Delete purchase order by ID }
#' For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
#'
#' DeleteOrder Delete purchase order by ID
#' \itemize{
#' \item \emph{ @param } order.id character
#'
#'
#' GetInventory Returns pet inventories by status
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' GetOrderById Find purchase order by ID
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Order not found
#'
#'
#' PlaceOrder Place an order for a pet
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetInventory } \emph{ Returns pet inventories by status }
#' Returns a map of status codes to quantities
#'
#' \itemize{
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : map(integer)
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetOrderById } \emph{ Find purchase order by ID }
#' For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
#'
#' \itemize{
#' \item \emph{ @param } order.id integer
#' \item \emph{ @returnType } \link[petstore:Order]{ Order } \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Order
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Order not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ PlaceOrder } \emph{ Place an order for a pet }
#'
#'
#' \itemize{
#' \item \emph{ @param } body \link[petstore:Order]{ Order }
#' \item \emph{ @returnType } \link[petstore:Order]{ Order } \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Order
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid Order
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \donttest{
#' #################### DeleteOrder ####################
#'
#' library(petstore)
#' var.order.id <- 'order.id_example' # character | ID of the order that needs to be deleted
#'
#' #Delete purchase order by ID
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$DeleteOrder(var.order.id)
#'
#'
#' #################### GetInventory ####################
#'
#' library(petstore)
#'
#' #Returns pet inventories by status
#' api.instance <- StoreApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['api_key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$GetInventory()
#'
#'
#' #################### GetOrderById ####################
#'
#' library(petstore)
#' var.order.id <- 56 # integer | ID of pet that needs to be fetched
#'
#' #Find purchase order by ID
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$GetOrderById(var.order.id)
#'
#'
#' #################### PlaceOrder ####################
#'
#' library(petstore)
#' var.body <- Order$new() # Order | order placed for purchasing the pet
#'
#' #Place an order for a pet
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$PlaceOrder(var.body)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
StoreApi <- R6::R6Class(
@@ -117,7 +247,12 @@ StoreApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "map(integer)", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "map(integer)", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -160,7 +295,12 @@ StoreApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "Order", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "Order", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -205,7 +345,12 @@ StoreApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "Order", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "Order", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)

View File

@@ -6,11 +6,14 @@
#
# Generated by: https://openapi-generator.tech
#' Tag Class
#' @docType class
#' @title Tag
#' @description Tag Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#'
#' @field name character [optional]
#'
#' @field id
#' @field name
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,17 +6,26 @@
#
# Generated by: https://openapi-generator.tech
#' User Class
#' @docType class
#' @title User
#' @description User Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#'
#' @field username character [optional]
#'
#' @field firstName character [optional]
#'
#' @field lastName character [optional]
#'
#' @field email character [optional]
#'
#' @field password character [optional]
#'
#' @field phone character [optional]
#'
#' @field userStatus integer [optional]
#'
#' @field id
#' @field username
#' @field firstName
#' @field lastName
#' @field email
#' @field password
#' @field phone
#' @field userStatus
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON

View File

@@ -6,42 +6,277 @@
#
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title User operations
#' @description petstore.User
#'
#' @field path Stores url path of the request.
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#' \strong{ CreateUser } \emph{ Create user }
#' This can only be done by the logged in user.
#'
#' CreateUser Create user
#' \itemize{
#' \item \emph{ @param } body \link[petstore:User]{ User }
#'
#'
#' CreateUsersWithArrayInput Creates list of users with given input array
#' \item status code : 0 | successful operation
#'
#'
#' CreateUsersWithListInput Creates list of users with given input array
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ CreateUsersWithArrayInput } \emph{ Creates list of users with given input array }
#'
#'
#' \itemize{
#' \item \emph{ @param } body list( \link[petstore:User]{ User } )
#'
#'
#' DeleteUser Delete user
#' \item status code : 0 | successful operation
#'
#'
#' GetUserByName Get user by user name
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ CreateUsersWithListInput } \emph{ Creates list of users with given input array }
#'
#'
#' \itemize{
#' \item \emph{ @param } body list( \link[petstore:User]{ User } )
#'
#'
#' LoginUser Logs user into the system
#' \item status code : 0 | successful operation
#'
#'
#' LogoutUser Logs out current logged in user session
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ DeleteUser } \emph{ Delete user }
#' This can only be done by the logged in user.
#'
#' \itemize{
#' \item \emph{ @param } username character
#'
#'
#' UpdateUser Updated user
#' \item status code : 400 | Invalid username supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetUserByName } \emph{ Get user by user name }
#'
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @returnType } \link[petstore:User]{ User } \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : User
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid username supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ LoginUser } \emph{ Logs user into the system }
#'
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @param } password character
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : character
#' \item response headers :
#'
#' \tabular{ll}{
#' X-Rate-Limit \tab calls per hour allowed by the user \cr
#' X-Expires-After \tab date in UTC when toekn expires \cr
#' }
#' \item status code : 400 | Invalid username/password supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ LogoutUser } \emph{ Logs out current logged in user session }
#'
#'
#' \itemize{
#'
#'
#' \item status code : 0 | successful operation
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdateUser } \emph{ Updated user }
#' This can only be done by the logged in user.
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @param } body \link[petstore:User]{ User }
#'
#'
#' \item status code : 400 | Invalid user supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \donttest{
#' #################### CreateUser ####################
#'
#' library(petstore)
#' var.body <- User$new() # User | Created user object
#'
#' #Create user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUser(var.body)
#'
#'
#' #################### CreateUsersWithArrayInput ####################
#'
#' library(petstore)
#' var.body <- [User$new()] # array[User] | List of user object
#'
#' #Creates list of users with given input array
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUsersWithArrayInput(var.body)
#'
#'
#' #################### CreateUsersWithListInput ####################
#'
#' library(petstore)
#' var.body <- [User$new()] # array[User] | List of user object
#'
#' #Creates list of users with given input array
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUsersWithListInput(var.body)
#'
#'
#' #################### DeleteUser ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The name that needs to be deleted
#'
#' #Delete user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$DeleteUser(var.username)
#'
#'
#' #################### GetUserByName ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The name that needs to be fetched. Use user1 for testing.
#'
#' #Get user by user name
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$GetUserByName(var.username)
#'
#'
#' #################### LoginUser ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The user name for login
#' var.password <- 'password_example' # character | The password for login in clear text
#'
#' #Logs user into the system
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$LoginUser(var.username, var.password)
#'
#'
#' #################### LogoutUser ####################
#'
#' library(petstore)
#'
#' #Logs out current logged in user session
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$LogoutUser()
#'
#'
#' #################### UpdateUser ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | name that need to be deleted
#' var.body <- User$new() # User | Updated user object
#'
#' #Updated user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$UpdateUser(var.username, var.body)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
UserApi <- R6::R6Class(
@@ -267,7 +502,12 @@ UserApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "User", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "User", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)
@@ -314,7 +554,12 @@ UserApi <- R6::R6Class(
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- self$apiClient$deserialize(resp, "character", "package:petstore")
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "character", "package:petstore"),
error = function(e){
stop("Failed to deserialize response")
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
ApiResponse$new("API client error", resp)

View File

@@ -15,6 +15,7 @@ Rscript -e "install.packages('httr', repos='$REPO', lib='$R_LIBS_USER')"
Rscript -e "install.packages('testthat', repos='$REPO', lib='$R_LIBS_USER')"
Rscript -e "install.packages('R6', repos='$REPO', lib='$R_LIBS_USER')"
Rscript -e "install.packages('caTools', repos='$REPO', lib='$R_LIBS_USER')"
Rscript -e "install.packages('rlang', repos='$REPO', lib='$R_LIBS_USER')"
R CMD build .
R CMD check *tar.gz --no-manual