R client refactoring (#2215)

* [R] fix namespace, use 2-space indentation (#2105)

* fix namespace, indentation

* use 2-space indentation in model files

* update gitignore

* use PascalCase for function naming (#2106)

* [R] improve .travis.yml, .Rbuildignore (#2109)

* update travis

* enhance travis.yml

* update travis, .Rbuildignore

* [R] Add auto-generated documentations, change parameter naming (#2114)

* add auto-generated doc for r client

* remove module name

* replace nil with void

* [R] fix object serialization to JSON (#2129)

* fix object serialization

* fix array property seriziation

* fix deserializing array of string

* fix array of object deserialization

* [R] Fix return type (#2140)

* fix return type

* update r petstore sample

* add auto-generated tests (#2141)

* rename file to conform to style guide (#2142)

* add authenticaiton support to R (#2153)

[R] Add authentication support, minor ApiClient refactor

* rename test files

* [R] various improvements and bug fixes (#2162)

* fix api keys in headers

* use optional parameter in function signature

* fix property naming

* fix doc assignment operator

* [R] fix base64 encode (#2171)

* fix base64 encode

* fix basic http auth

* fix typo, update instruction (#2203)

* rename test files to conform to style guide (#2206)

* [R] improve class constructor (#2208)

* update constructor with optional parameter, default value

* update r petstore sample

* clean up files

* regenerate files

* Revert "rename test files to conform to style guide (#2206)"

This reverts commit 90a6302a6565d208a6ab298fda41a47836a63d9c.

* fix query parameter in api client (#2214)
This commit is contained in:
William Cheng 2019-02-23 23:51:11 +08:00 committed by GitHub
parent 7486438491
commit e6658278ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 3129 additions and 1104 deletions

2
.gitignore vendored
View File

@ -193,6 +193,8 @@ samples/client/petstore/haskell-http-client/docs/quick-jump.css
# R # R
.Rproj.user .Rproj.user
samples/client/petstore/R/**/petstore.Rcheck/
samples/client/petstore/R/**/*.tar.gz
# elixir # elixir
samples/client/petstore/elixir/_build/ samples/client/petstore/elixir/_build/

View File

@ -17,8 +17,10 @@
package org.openapitools.codegen.languages; package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*; import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.ModelUtils;
@ -27,6 +29,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
import static org.openapitools.codegen.utils.StringUtils.camelize; import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore; import static org.openapitools.codegen.utils.StringUtils.underscore;
@ -38,6 +41,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String packageVersion = "1.0.0"; protected String packageVersion = "1.0.0";
protected String apiDocPath = "docs/"; protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/"; protected String modelDocPath = "docs/";
protected String testFolder = "tests/testthat";
public CodegenType getTag() { public CodegenType getTag() {
return CodegenType.CLIENT; return CodegenType.CLIENT;
@ -54,8 +58,8 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
public RClientCodegen() { public RClientCodegen() {
super(); super();
outputFolder = "generated-code/r"; outputFolder = "generated-code/r";
modelTemplateFiles.put("model.mustache", ".r"); modelTemplateFiles.put("model.mustache", ".R");
apiTemplateFiles.put("api.mustache", ".r"); apiTemplateFiles.put("api.mustache", ".R");
modelDocTemplateFiles.put("model_doc.mustache", ".md"); modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md"); apiDocTemplateFiles.put("api_doc.mustache", ".md");
@ -70,7 +74,9 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
// reserved words: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Reserved.html // reserved words: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Reserved.html
"if", "else", "repeat", "while", "function", "for", "in", "if", "else", "repeat", "while", "function", "for", "in",
"next", "break", "TRUE", "FALSE", "NULL", "Inf", "NaN", "next", "break", "TRUE", "FALSE", "NULL", "Inf", "NaN",
"NA", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_" "NA", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_",
// reserved words in API client
"ApiResponse"
) )
); );
@ -130,11 +136,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put("apiDocPath", apiDocPath); additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath); additionalProperties.put("modelDocPath", modelDocPath);
apiTestTemplateFiles.clear(); // TODO: add api test template modelTestTemplateFiles.put("model_test.mustache", ".R");
modelTestTemplateFiles.clear(); // TODO: add model test template apiTestTemplateFiles.put("api_test.mustache", ".R");
apiDocTemplateFiles.clear(); // TODO: add api doc template modelDocTemplateFiles.put("model_doc.mustache", ".md");
modelDocTemplateFiles.clear(); // TODO: add model doc template apiDocTemplateFiles.put("api_doc.mustache", ".md");
modelPackage = packageName; modelPackage = packageName;
apiPackage = packageName; apiPackage = packageName;
@ -145,10 +151,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("description.mustache", "", "DESCRIPTION")); supportingFiles.add(new SupportingFile("description.mustache", "", "DESCRIPTION"));
supportingFiles.add(new SupportingFile("Rbuildignore.mustache", "", ".Rbuildignore")); supportingFiles.add(new SupportingFile("Rbuildignore.mustache", "", ".Rbuildignore"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml")); supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("response.mustache", "/R", "Response.r")); supportingFiles.add(new SupportingFile("ApiResponse.mustache", File.separator + "R", "api_response.R"));
supportingFiles.add(new SupportingFile("element.mustache", "/R", "Element.r")); //supportingFiles.add(new SupportingFile("element.mustache", File.separator + "R", "Element.R"));
supportingFiles.add(new SupportingFile("api_client.mustache", "/R", "ApiClient.r")); supportingFiles.add(new SupportingFile("api_client.mustache", File.separator + "R", "api_client.R"));
supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE"));
supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R"));
} }
@Override @Override
@ -180,7 +187,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
} }
@Override @Override
public String toVarName(String name) { public String toParamName(String name) {
// replace - with _ e.g. created-at => created_at // replace - with _ e.g. created-at => created_at
name = sanitizeName(name.replaceAll("-", "_")); name = sanitizeName(name.replaceAll("-", "_"));
@ -200,21 +207,22 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
if (name.matches("^\\d.*")) if (name.matches("^\\d.*"))
name = "Var" + name; name = "Var" + name;
return name.replace("_", ".");
}
@Override
public String toVarName(String name) {
// don't do anything as we'll put property name inside ` `, e.g. `date-time`
return name; return name;
} }
@Override @Override
public String toParamName(String name) { public String toModelFilename(String name) {
return toVarName(name); return underscore(toModelName(name));
} }
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
return toModelFilename(name);
}
@Override
public String toModelFilename(String name) {
if (!StringUtils.isEmpty(modelNamePrefix)) { if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name; name = modelNamePrefix + "_" + name;
} }
@ -246,7 +254,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// e.g. PetApi.r => pet_api.r // e.g. PetApi.r => pet_api.r
return camelize(name + "_api"); return underscore(name + "_api");
} }
@Override @Override
@ -327,7 +335,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
sanitizedOperationId = "call_" + sanitizedOperationId; sanitizedOperationId = "call_" + sanitizedOperationId;
} }
return underscore(sanitizedOperationId); return camelize(sanitizedOperationId);
} }
@Override @Override
@ -450,4 +458,179 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
return enumName; return enumName;
} }
} }
@Override
public void setParameterExampleValue(CodegenParameter p) {
String example;
if (p.defaultValue == null) {
example = p.example;
} else {
p.example = p.defaultValue;
return;
}
String type = p.baseType;
if (type == null) {
type = p.dataType;
}
if ("character".equals(type)) {
if (example == null) {
example = p.paramName + "_example";
}
example = "'" + escapeText(example) + "'";
} else if ("integer".equals(type)) {
if (example == null) {
example = "56";
}
} else if ("numeric".equals(type)) {
if (example == null) {
example = "3.4";
}
} else if ("data.frame".equals(type)) {
if (example == null) {
example = "/path/to/file";
}
example = "File.new('" + escapeText(example) + "')";
} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = type + "$new()";
}
if (example == null) {
example = "NULL";
} else if (Boolean.TRUE.equals(p.isListContainer)) {
example = "[" + example + "]";
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
example = "{'key' => " + example + "}";
}
p.example = example;
}
/**
* Return the example value of the parameter. Overrides the
* setParameterExampleValue(CodegenParameter, Parameter) method in
* DefaultCodegen to always call setParameterExampleValue(CodegenParameter)
* in this class, which adds single quotes around strings from the
* x-example property.
*
* @param codegenParameter Codegen parameter
* @param parameter Parameter
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) {
if (parameter.getExample() != null) {
codegenParameter.example = parameter.getExample().toString();
} else if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
Example example = parameter.getExamples().values().iterator().next();
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
}
} else {
Schema schema = parameter.getSchema();
if (schema != null && schema.getExample() != null) {
codegenParameter.example = schema.getExample().toString();
}
}
setParameterExampleValue(codegenParameter);
}
/**
* Return the default value of the property
* @param p OpenAPI property object
* @return string presentation of the default value of the property
*/
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
if (Boolean.valueOf(p.getDefault().toString()) == false)
return "FALSE";
else
return "TRUE";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Boolean.valueOf(p.getExample().toString()) == false)
return "FALSE";
else
return "TRUE";
}
} else if (ModelUtils.isDateSchema(p)) {
// TODO
} else if (ModelUtils.isDateTimeSchema(p)) {
// TODO
} else if (ModelUtils.isNumberSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default numbers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default integers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
return "'''" + p.getDefault() + "'''";
else
return "'" + p.getDefault() + "'";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getExample()).find())
return "'''" + p.getExample() + "'''";
else
return "'" + p.getExample() + "'";
}
} else if (ModelUtils.isArraySchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
}
return null;
}
@Override
public String apiTestFileFolder() {
return outputFolder + File.separator + testFolder;
}
@Override
public String modelTestFileFolder() {
return outputFolder + File.separator + testFolder;
}
@Override
public String toApiTestFilename(String name) {
return "test_" + toApiFilename(name);
}
@Override
public String toModelTestFilename(String name) {
return "test_" + toModelFilename(name);
}
} }

View File

@ -1,3 +1,15 @@
# ref: https://docs.travis-ci.com/user/languages/r/ # ref: https://docs.travis-ci.com/user/languages/r/
language: r language: r
cache: packages cache:
directories:
- /home/travis/R/Library
r_packages:
- jsonlite
- httr
# uncomment below to install deps with devtools
#install:
#- R -e 'devtools::install_deps(dep = T)'
script:
- R CMD build .
- R CMD check *tar.gz
- R CMD INSTALL *tar.gz

View File

@ -1,9 +1,9 @@
#' Response Class #' ApiResponse Class
#' #'
#' Response Class #' ApiResponse Class
#' @export #' @export
Response <- R6::R6Class( ApiResponse <- R6::R6Class(
'Response', 'ApiResponse',
public = list( public = list(
content = NULL, content = NULL,
response = NULL, response = NULL,

View File

@ -1,8 +1,26 @@
# Generated by openapi-generator: https://openapi-generator.tech # Generated by openapi-generator: https://openapi-generator.tech
# Do not edit by hand # Do not edit by hand
# Core
export(ApiClient)
export(ApiResponse)
# Models
{{#models}} {{#models}}
{{#model}} {{#model}}
export({{{classname}}}) export({{{classname}}})
{{/model}} {{/model}}
{{/models}} {{/models}}
# APIs
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}
{{#-first}}
export({{{classname}}})
{{/-first}}
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}

View File

@ -18,23 +18,83 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}} {{/infoUrl}}
## Installation ## Installation
You'll need the `devtools` package in order to build the API.
Make sure you have a proper CRAN repository from which you can download packages.
### Prerequisites ### Prerequisites
Install the `devtools` package with the following command.
Install the dependencies
```R ```R
if(!require(devtools)) { install.packages("devtools") } install.packages("jsonlite")
install.packages("httr")
install.packages("caTools")
``` ```
### Installation of the API package ### Build the package
Make sure you set the working directory to where the API code is located.
Then execute ```sh
```R git clone https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}
library(devtools) cd {{{gitRepoId}}}
install(".") R CMD build .
R CMD check {{{packageName}}}_{{{packageVersion}}}.tar.gz
R CMD INSTALL {{{packageName}}}_{{{packageVersion}}}.tar.gz
``` ```
### Install the package
```R
install.packages("{{{packageName}}}")
```
To install directly from Github, use `devtools`:
```R
install.packages("devtools")
library(devtools)
install_github("{{{gitUserId}}}/{{{gitRepoId}}}")
```
### Usage
```R
library({{{packageName}}})
```
## Documentation for API Endpoints
All URIs are relative to *{{basePath}}*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
## Documentation for Models
{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md)
{{/model}}{{/models}}
## Documentation for Authorization
{{^authMethods}} All endpoints do not require authorization.
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}### {{name}}
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - {{scope}}: {{description}}
{{/scopes}}
{{/isOAuth}}
{{/authMethods}}
## Author ## Author
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} {{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}

View File

@ -1,2 +1,5 @@
^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^\.openapi-generator-ignore$
^\.travis\.yml$
^\.openapi-generator$

View File

@ -5,7 +5,6 @@
#' #'
#' @field path Stores url path of the request. #' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication. #' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#' #'
#' @importFrom R6 R6Class #' @importFrom R6 R6Class
#' #'
@ -18,11 +17,11 @@
{{/operation}} {{/operation}}
#' } #' }
#' #'
#' @importFrom caTools base64encode
#' @export #' @export
{{classname}} <- R6::R6Class( {{classname}} <- R6::R6Class(
'{{classname}}', '{{classname}}',
public = list( public = list(
userAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}",
apiClient = NULL, apiClient = NULL,
initialize = function(apiClient){ initialize = function(apiClient){
if (!missing(apiClient)) { if (!missing(apiClient)) {
@ -33,27 +32,25 @@
} }
}, },
{{#operation}} {{#operation}}
{{operationId}} = function({{#allParams}}{{paramName}}, {{/allParams}}...){ {{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{#defaultValue}}{{{.}}}{{/defaultValue}}, {{/optionalParams}}...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
{{#hasHeaderParams}} {{#requiredParams}}
{{#headerParams}} if (missing(`{{paramName}}`)) {
if (!missing(`{{paramName}}`)) { stop("Missing required parameter `{{{paramName}}}`.")
headerParams['{{baseName}}'] <- `{{paramName}}`
} }
{{/requiredParams}}
{{#headerParams}}
headerParams['{{baseName}}'] <- `{{paramName}}`
{{/headerParams}} {{/headerParams}}
{{/hasHeaderParams}}
{{#hasQueryParams}}
{{#queryParams}} {{#queryParams}}
if (!missing(`{{paramName}}`)) {
queryParams['{{baseName}}'] <- {{paramName}} queryParams['{{baseName}}'] <- {{paramName}}
}
{{/queryParams}} {{/queryParams}}
{{/hasQueryParams}}
{{#hasFormParams}} {{#hasFormParams}}
body <- list( body <- list(
{{#formParams}} {{#formParams}}
@ -86,7 +83,33 @@
{{/pathParams}} {{/pathParams}}
{{/hasPathParams}} {{/hasPathParams}}
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), {{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
# HTTP basic auth
headerParams['Authorization'] <- paste("Basic", caTools::base64encode(paste(self$apiClient$username, self$apiClient$password, sep=":")), 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='')
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if ("{{{keyParamName}}}" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["{{{keyParamName}}}"]) > 0) {
queryParams['{{keyParamName}}'] <- paste(unlist(self$apiClient$apiKeys["{{keyParamName}}"]), collapse='')
}
{{/isKeyInQuery}}
{{/isApiKey}}
{{#isOAuth}}
# OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
{{/isOAuth}}
{{/authMethods}}
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "{{httpMethod}}", method = "{{httpMethod}}",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -96,21 +119,19 @@
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
{{#returnType}} {{#returnType}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
returnObject <- {{returnType}}$new() httr::content(resp, "text", encoding = "UTF-8"
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) {{returnType}}$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/returnType}} {{/returnType}}
{{^returnType}} {{^returnType}}
# void response, no need to return anything # void response, no need to return anything
{{/returnType}} {{/returnType}}
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}{{#hasMore}},{{/hasMore}} }{{#hasMore}},{{/hasMore}}

View File

@ -12,51 +12,80 @@
#' Ref: https://openapi-generator.tech #' Ref: https://openapi-generator.tech
#' Do not edit the class manually. #' Do not edit the class manually.
#' #'
#' @field basePath
#' @field userAgent
#' @field defaultHeaders
#' @field username
#' @field password
#' @field apiKeys
#' @field accessToken
#' @importFrom httr
#' @export #' @export
ApiClient <- R6::R6Class( ApiClient <- R6::R6Class(
'ApiClient', 'ApiClient',
public = list( public = list(
# base path of all requests
basePath = "{{{basePath}}}", basePath = "{{{basePath}}}",
configuration = NULL, # user agent in the HTTP request
userAgent = NULL, userAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}",
# default headers in the HTTP request
defaultHeaders = NULL, defaultHeaders = NULL,
initialize = function(basePath, configuration, defaultHeaders){ # username (HTTP basic authentication)
if (!missing(basePath)) { username = NULL,
# password (HTTP basic authentication)
password = NULL,
# API keys
apiKeys = NULL,
# Access token
accessToken = NULL,
# constructor
initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL){
if (!is.null(basePath)) {
self$basePath <- basePath self$basePath <- basePath
} }
if (!missing(configuration)) { if (!is.null(defaultHeaders)) {
self$configuration <- configuration
}
if (!missing(defaultHeaders)) {
self$defaultHeaders <- defaultHeaders self$defaultHeaders <- defaultHeaders
} }
self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}' if (!is.null(username)) {
self$username <- username
}
if (!is.null(password)) {
self$password <- password
}
if (!is.null(accessToken)) {
self$accessToken <- accessToken
}
if (!is.null(apiKeys)) {
self$apiKeys <- apiKeys
} else {
self$apiKeys <- list()
}
if (!is.null(userAgent)) {
self$`userAgent` <- userAgent
}
}, },
callApi = function(url, method, queryParams, headerParams, body, ...){ CallApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(c(headerParams, self$defaultHeaders)) headers <- httr::add_headers(c(headerParams, self$defaultHeaders))
if (method == "GET") { if (method == "GET") {
httr::GET(url, queryParams, headers, ...) httr::GET(url, queryParams, headers, ...)
} } else if (method == "POST") {
else if (method == "POST") { httr::POST(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...) } else if (method == "PUT") {
} httr::PUT(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
else if (method == "PUT") { } else if (method == "PATCH") {
httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...) httr::PATCH(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
} } else if (method == "HEAD") {
else if (method == "PATCH") { httr::HEAD(url, query = queryParams, headers, ...)
httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...) } else if (method == "DELETE") {
} httr::DELETE(url, query = queryParams, headers, ...)
else if (method == "HEAD") { } else {
httr::HEAD(url, queryParams, headers, ...)
}
else if (method == "DELETE") {
httr::DELETE(url, queryParams, headers, ...)
}
else {
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.") stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
} }
} }

View File

@ -1,4 +1,4 @@
# {{invokerPackage}}\{{classname}}{{#description}} # {{classname}}{{#description}}
{{description}}{{/description}} {{description}}{{/description}}
All URIs are relative to *{{basePath}}* All URIs are relative to *{{basePath}}*
@ -10,41 +10,71 @@ Method | HTTP request | Description
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
# **{{{operationId}}}** # **{{operationId}}**
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#authMethods}}ctx, {{/authMethods}}{{#allParams}}{{#required}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}optional{{/hasOptionalParams}}) > {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}{{#defaultValue}}={{{.}}}{{/defaultValue}}{{^defaultValue}}=var.{{{paramName}}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalParams}})
{{{summary}}}{{#notes}} {{{summary}}}{{#notes}}
{{{notes}}}{{/notes}} {{{notes}}}{{/notes}}
### Required Parameters ### Example
```R
library({{{packageName}}})
{{#allParams}}
var.{{{paramName}}} <- {{{example}}} # {{{dataType}}} | {{{description}}}
{{/allParams}}
{{#summary}}
#{{{.}}}
{{/summary}}
api.instance <- {{{classname}}}$new()
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
api.instance$apiClient$username <- 'TODO_YOUR_USERNAME';
api.instance$apiClient$password <- 'TODO_YOUR_PASSWORD';
{{/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}}
{{#returnType}}result <- {{/returnType}}api.instance${{{operationId}}}({{#requiredParams}}var.{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-first}}{{#requiredParams.0}}, {{/requiredParams.0}}{{/-first}}{{{paramName}}}=var.{{{paramName}}}{{^-last}}, {{/-last}}{{/optionalParams}})
{{#returnType}}
dput(result)
{{/returnType}}
```
### Parameters
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} {{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{#authMethods}} ------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
**ctx** | **context.Context** | context containing the authentication | nil if no authentication{{/authMethods}}{{/-last}}{{/allParams}}{{#allParams}}{{#required}} {{#requiredParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}} {{/requiredParams}}
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters {{#optionalParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/optionalParams}}
### Optional Parameters
Optional parameters are passed through a map[string]interface{}.
{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/allParams}}{{/hasOptionalParams}}
### Return type ### Return type
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}} (empty response body){{/returnType}} {{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
### Authorization ### Authorization
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](../README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}} {{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
### HTTP request headers ### HTTP request headers
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

@ -0,0 +1,29 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test {{{classname}}}")
api.instance <- {{{classname}}}$new()
{{#operations}}
{{#operation}}
test_that("{{{operationId}}}", {
# tests for {{operationId}}
# base path: {{{basePath}}}
{{#summary}}
# {{summary}}
{{/summary}}
{{#notes}}
# {{notes}}
{{/notes}}
{{#allParams}}
# @param {{{dataType}}} {{{paramName}}} {{{description}}} {{^required}} (optional){{/required}}
{{/allParams}}
# @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
{{/operation}}
{{/operations}}

View File

@ -8,5 +8,5 @@ Encoding: UTF-8
License: Unlicense License: Unlicense
LazyData: true LazyData: true
Suggests: testthat Suggests: testthat
Imports: jsonlite, httr, R6 Imports: jsonlite, httr, R6, caTools
RoxygenNote: 6.0.1.9000 RoxygenNote: 6.0.1.9000

View File

@ -17,8 +17,9 @@
{{#vars}} {{#vars}}
`{{{baseName}}}` = NULL, `{{{baseName}}}` = NULL,
{{/vars}} {{/vars}}
initialize = function({{#vars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/vars}}){ initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){
{{#vars}} local.optional.var <- list(...)
{{#requiredVars}}
if (!missing(`{{baseName}}`)) { if (!missing(`{{baseName}}`)) {
{{^isListContainer}} {{^isListContainer}}
{{#isInteger}} {{#isInteger}}
@ -58,7 +59,48 @@
{{/isListContainer}} {{/isListContainer}}
self$`{{baseName}}` <- `{{baseName}}` self$`{{baseName}}` <- `{{baseName}}`
} }
{{/vars}} {{/requiredVars}}
{{#optionalVars}}
if (!is.null(`{{baseName}}`)) {
{{^isListContainer}}
{{#isInteger}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isInteger}}
{{#isLong}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isLong}}
{{#isFloat}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isFloat}}
{{#isDouble}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDouble}}
{{#isString}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isString}}
{{#isDate}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDate}}
{{#isDateTime}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDateTime}}
{{^isPrimitiveType}}
stopifnot(R6::is.R6(`{{baseName}}`))
{{/isPrimitiveType}}
{{/isListContainer}}
{{#isListContainer}}
{{#isPrimitiveType}}
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
sapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
{{/isPrimitiveType}}
{{/isListContainer}}
self$`{{baseName}}` <- `{{baseName}}`
}
{{/optionalVars}}
}, },
toJSON = function() { toJSON = function() {
{{classname}}Object <- list() {{classname}}Object <- list()
@ -116,34 +158,35 @@
{{/vars}} {{/vars}}
}, },
toJSONString = function() { toJSONString = function() {
outstring <- sprintf( sprintf(
'{ '{
{{#vars}} {{#vars}}
"{{baseName}}": "{{baseName}}":
{{#isListContainer}} {{#isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
{{#isNumeric}}[%d]{{/isNumeric}} {{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}}{{#hasMore}},{{/hasMore}}
{{^isNumeric}}["%s"]{{/isNumeric}} {{/isPrimitiveType}}
{{^isPrimitiveType}}
[%s]{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}}["%s"]{{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
{{#isNumeric}}%d{{/isNumeric}} {{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}}{{#hasMore}},{{/hasMore}}
{{^isNumeric}}"%s"{{/isNumeric}} {{/isPrimitiveType}}
{{^isPrimitiveType}}
%s{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}}"%s"{{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{#hasMore}},{{/hasMore}}
{{/vars}} {{/vars}}
}', }',
{{#vars}} {{#vars}}
{{#isListContainer}} {{#isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
paste0(self$`{{baseName}}`, collapse='","'){{#hasMore}},{{/hasMore}} paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=","){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
paste0(sapply(self$`{{baseName}}`, function(x) x$toJSON()), collapse='","'){{#hasMore}},{{/hasMore}} paste(unlist(lapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
@ -151,22 +194,27 @@
self$`{{baseName}}`{{#hasMore}},{{/hasMore}} self$`{{baseName}}`{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
self$`{{baseName}}`$toJSON(){{#hasMore}},{{/hasMore}} jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{/vars}} {{/vars}}
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function({{classname}}Json) { fromJSONString = function({{classname}}Json) {
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}} {{#vars}}
{{#isListContainer}} {{#isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}` self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function (x) x)
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {{dataType}}$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) data.frame <- {{classname}}Object$`{{baseName}}`
self$`{{baseName}}` <- vector("list", length = nrow(data.frame))
for (row in 1:nrow(data.frame)) {
{{baseName}}.node <- {{dataType}}$new()
{{baseName}}.node$fromJSON(jsonlite::toJSON(data.frame[row,,drop = TRUE], auto_unbox = TRUE))
self$`{{baseName}}`[[row]] <- {{baseName}}.node
}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
@ -174,11 +222,11 @@
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}` self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
{{dataType}}Object <- {{dataType}}$new() self$`{{baseName}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
self$`{{baseName}}` <- {{dataType}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{/vars}} {{/vars}}
self
} }
) )
) )

View File

@ -1,11 +1,9 @@
{{#models}}{{#model}}# {{classname}} {{#models}}{{#model}}# {{packageName}}::{{classname}}
## Properties ## Properties
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{{dataType}}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} {{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/vars}} {{/vars}}
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
{{/model}}{{/models}} {{/model}}{{/models}}

View File

@ -0,0 +1,23 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test {{{classname}}}")
model.instance <- {{{classname}}}$new()
{{#models}}
{{#model}}
{{#vars}}
test_that("{{{name}}}", {
# tests for the property `{{{name}}}` ({{dataType}})
{{#description}}
# {{description}}
{{/description}}
# uncomment below to test the property
#expect_equal(model.instance$`{{{name}}}`, "EXPECTED_RESULT")
})
{{/vars}}
{{/model}}
{{/models}}

View File

@ -0,0 +1,4 @@
library(testthat)
library({{{packageName}}})
test_check("{{{packageName}}}")

View File

@ -1,2 +1,5 @@
^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^\.openapi-generator-ignore$
^\.travis\.yml$
^\.openapi-generator$

View File

@ -1,3 +1,15 @@
# ref: https://docs.travis-ci.com/user/languages/r/ # ref: https://docs.travis-ci.com/user/languages/r/
language: r language: r
cache: packages cache:
directories:
- /home/travis/R/Library
r_packages:
- jsonlite
- httr
# uncomment below to install deps with devtools
#install:
#- R -e 'devtools::install_deps(dep = T)'
script:
- R CMD build .
- R CMD check *tar.gz
- R CMD INSTALL *tar.gz

View File

@ -8,5 +8,5 @@ Encoding: UTF-8
License: Unlicense License: Unlicense
LazyData: true LazyData: true
Suggests: testthat Suggests: testthat
Imports: jsonlite, httr, R6 Imports: jsonlite, httr, R6, caTools
RoxygenNote: 6.0.1.9000 RoxygenNote: 6.0.1.9000

View File

@ -1,9 +1,19 @@
# Generated by openapi-generator: https://openapi-generator.tech # Generated by openapi-generator: https://openapi-generator.tech
# Do not edit by hand # Do not edit by hand
# Core
export(ApiClient)
export(ApiResponse) export(ApiResponse)
# Models
export(Category) export(Category)
export(ModelApiResponse)
export(Order) export(Order)
export(Pet) export(Pet)
export(Tag) export(Tag)
export(User) export(User)
# APIs
export(PetApi)
export(StoreApi)
export(UserApi)

View File

@ -1,71 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' ApiClient Class
#'
#' Generic API client for OpenAPI client library builds.
#' OpenAPI generic API client. This client handles the client-
#' server communication, and is invariant across implementations. Specifics of
#' the methods and models for each application are generated from the OpenAPI Generator
#' templates.
#'
#' NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
#' Ref: https://openapi-generator.tech
#' Do not edit the class manually.
#'
#' @export
ApiClient <- R6::R6Class(
'ApiClient',
public = list(
basePath = "http://petstore.swagger.io/v2",
configuration = NULL,
userAgent = NULL,
defaultHeaders = NULL,
initialize = function(basePath, configuration, defaultHeaders){
if (!missing(basePath)) {
self$basePath <- basePath
}
if (!missing(configuration)) {
self$configuration <- configuration
}
if (!missing(defaultHeaders)) {
self$defaultHeaders <- defaultHeaders
}
self$`userAgent` <- 'OpenAPI-Generator/1.0.0/r'
},
callApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(c(headerParams, self$defaultHeaders))
if (method == "GET") {
httr::GET(url, queryParams, headers, ...)
}
else if (method == "POST") {
httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PUT") {
httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "PATCH") {
httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...)
}
else if (method == "HEAD") {
httr::HEAD(url, queryParams, headers, ...)
}
else if (method == "DELETE") {
httr::DELETE(url, queryParams, headers, ...)
}
else {
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
}
}
)
)

View File

@ -1,100 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' ApiResponse Class
#'
#' @field code
#' @field type
#' @field message
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
ApiResponse <- R6::R6Class(
'ApiResponse',
public = list(
`code` = NULL,
`type` = NULL,
`message` = NULL,
initialize = function(`code`, `type`, `message`){
if (!missing(`code`)) {
stopifnot(is.numeric(`code`), length(`code`) == 1)
self$`code` <- `code`
}
if (!missing(`type`)) {
stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type`
}
if (!missing(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message`
}
},
toJSON = function() {
ApiResponseObject <- list()
if (!is.null(self$`code`)) {
ApiResponseObject[['code']] <-
self$`code`
}
if (!is.null(self$`type`)) {
ApiResponseObject[['type']] <-
self$`type`
}
if (!is.null(self$`message`)) {
ApiResponseObject[['message']] <-
self$`message`
}
ApiResponseObject
},
fromJSON = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
if (!is.null(ApiResponseObject$`code`)) {
self$`code` <- ApiResponseObject$`code`
}
if (!is.null(ApiResponseObject$`type`)) {
self$`type` <- ApiResponseObject$`type`
}
if (!is.null(ApiResponseObject$`message`)) {
self$`message` <- ApiResponseObject$`message`
}
},
toJSONString = function() {
outstring <- sprintf(
'{
"code":
%d
,
"type":
"%s"
,
"message":
"%s"
}',
self$`code`,
self$`type`,
self$`message`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
self$`code` <- ApiResponseObject$`code`
self$`type` <- ApiResponseObject$`type`
self$`message` <- ApiResponseObject$`message`
}
)
)

View File

@ -1,24 +0,0 @@
#' Element Class
#'
#' Element Class
#' @export
Element <- R6::R6Class(
'Element',
public = list(
id = NULL,
name = NULL,
initialize = function(id,name){
if (!missing(id)) {
stopifnot(is.numeric(id), length(id) == 1)
self$id <- id
}
if (!missing(name)) {
stopifnot(is.character(name), length(name) == 1)
self$name <- name
}
},
toJSON = function() {
sprintf('{"id":%d,"name":"%s"}', self$id, self$name)
}
)
)

View File

@ -1,159 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Order Class
#'
#' @field id
#' @field petId
#' @field quantity
#' @field shipDate
#' @field status
#' @field complete
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Order <- R6::R6Class(
'Order',
public = list(
`id` = NULL,
`petId` = NULL,
`quantity` = NULL,
`shipDate` = NULL,
`status` = NULL,
`complete` = NULL,
initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){
if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!missing(`petId`)) {
stopifnot(is.numeric(`petId`), length(`petId`) == 1)
self$`petId` <- `petId`
}
if (!missing(`quantity`)) {
stopifnot(is.numeric(`quantity`), length(`quantity`) == 1)
self$`quantity` <- `quantity`
}
if (!missing(`shipDate`)) {
stopifnot(is.character(`shipDate`), length(`shipDate`) == 1)
self$`shipDate` <- `shipDate`
}
if (!missing(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status`
}
if (!missing(`complete`)) {
self$`complete` <- `complete`
}
},
toJSON = function() {
OrderObject <- list()
if (!is.null(self$`id`)) {
OrderObject[['id']] <-
self$`id`
}
if (!is.null(self$`petId`)) {
OrderObject[['petId']] <-
self$`petId`
}
if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <-
self$`quantity`
}
if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <-
self$`shipDate`
}
if (!is.null(self$`status`)) {
OrderObject[['status']] <-
self$`status`
}
if (!is.null(self$`complete`)) {
OrderObject[['complete']] <-
self$`complete`
}
OrderObject
},
fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id`
}
if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId`
}
if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity`
}
if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate`
}
if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status`
}
if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete`
}
},
toJSONString = function() {
outstring <- sprintf(
'{
"id":
%d
,
"petId":
%d
,
"quantity":
%d
,
"shipDate":
"%s"
,
"status":
"%s"
,
"complete":
"%s"
}',
self$`id`,
self$`petId`,
self$`quantity`,
self$`shipDate`,
self$`status`,
self$`complete`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
self$`id` <- OrderObject$`id`
self$`petId` <- OrderObject$`petId`
self$`quantity` <- OrderObject$`quantity`
self$`shipDate` <- OrderObject$`shipDate`
self$`status` <- OrderObject$`status`
self$`complete` <- OrderObject$`complete`
}
)
)

View File

@ -1,200 +0,0 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' User Class
#'
#' @field id
#' @field username
#' @field firstName
#' @field lastName
#' @field email
#' @field password
#' @field phone
#' @field userStatus
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
User <- R6::R6Class(
'User',
public = list(
`id` = NULL,
`username` = NULL,
`firstName` = NULL,
`lastName` = NULL,
`email` = NULL,
`password` = NULL,
`phone` = NULL,
`userStatus` = NULL,
initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){
if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!missing(`username`)) {
stopifnot(is.character(`username`), length(`username`) == 1)
self$`username` <- `username`
}
if (!missing(`firstName`)) {
stopifnot(is.character(`firstName`), length(`firstName`) == 1)
self$`firstName` <- `firstName`
}
if (!missing(`lastName`)) {
stopifnot(is.character(`lastName`), length(`lastName`) == 1)
self$`lastName` <- `lastName`
}
if (!missing(`email`)) {
stopifnot(is.character(`email`), length(`email`) == 1)
self$`email` <- `email`
}
if (!missing(`password`)) {
stopifnot(is.character(`password`), length(`password`) == 1)
self$`password` <- `password`
}
if (!missing(`phone`)) {
stopifnot(is.character(`phone`), length(`phone`) == 1)
self$`phone` <- `phone`
}
if (!missing(`userStatus`)) {
stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1)
self$`userStatus` <- `userStatus`
}
},
toJSON = function() {
UserObject <- list()
if (!is.null(self$`id`)) {
UserObject[['id']] <-
self$`id`
}
if (!is.null(self$`username`)) {
UserObject[['username']] <-
self$`username`
}
if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <-
self$`firstName`
}
if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <-
self$`lastName`
}
if (!is.null(self$`email`)) {
UserObject[['email']] <-
self$`email`
}
if (!is.null(self$`password`)) {
UserObject[['password']] <-
self$`password`
}
if (!is.null(self$`phone`)) {
UserObject[['phone']] <-
self$`phone`
}
if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <-
self$`userStatus`
}
UserObject
},
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id`
}
if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username`
}
if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName`
}
if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName`
}
if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email`
}
if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password`
}
if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone`
}
if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus`
}
},
toJSONString = function() {
outstring <- sprintf(
'{
"id":
%d
,
"username":
"%s"
,
"firstName":
"%s"
,
"lastName":
"%s"
,
"email":
"%s"
,
"password":
"%s"
,
"phone":
"%s"
,
"userStatus":
%d
}',
self$`id`,
self$`username`,
self$`firstName`,
self$`lastName`,
self$`email`,
self$`password`,
self$`phone`,
self$`userStatus`
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
self$`id` <- UserObject$`id`
self$`username` <- UserObject$`username`
self$`firstName` <- UserObject$`firstName`
self$`lastName` <- UserObject$`lastName`
self$`email` <- UserObject$`email`
self$`password` <- UserObject$`password`
self$`phone` <- UserObject$`phone`
self$`userStatus` <- UserObject$`userStatus`
}
)
)

View File

@ -0,0 +1,100 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' ApiClient Class
#'
#' Generic API client for OpenAPI client library builds.
#' OpenAPI generic API client. This client handles the client-
#' server communication, and is invariant across implementations. Specifics of
#' the methods and models for each application are generated from the OpenAPI Generator
#' templates.
#'
#' NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
#' Ref: https://openapi-generator.tech
#' Do not edit the class manually.
#'
#' @field basePath
#' @field userAgent
#' @field defaultHeaders
#' @field username
#' @field password
#' @field apiKeys
#' @field accessToken
#' @importFrom httr
#' @export
ApiClient <- R6::R6Class(
'ApiClient',
public = list(
# base path of all requests
basePath = "http://petstore.swagger.io/v2",
# user agent in the HTTP request
userAgent = "OpenAPI-Generator/1.0.0/r",
# default headers in the HTTP request
defaultHeaders = NULL,
# username (HTTP basic authentication)
username = NULL,
# password (HTTP basic authentication)
password = NULL,
# API keys
apiKeys = NULL,
# Access token
accessToken = NULL,
# constructor
initialize = function(basePath=NULL, userAgent=NULL, defaultHeaders=NULL, username=NULL, password=NULL, apiKeys=NULL, accessToken=NULL){
if (!is.null(basePath)) {
self$basePath <- basePath
}
if (!is.null(defaultHeaders)) {
self$defaultHeaders <- defaultHeaders
}
if (!is.null(username)) {
self$username <- username
}
if (!is.null(password)) {
self$password <- password
}
if (!is.null(accessToken)) {
self$accessToken <- accessToken
}
if (!is.null(apiKeys)) {
self$apiKeys <- apiKeys
} else {
self$apiKeys <- list()
}
if (!is.null(userAgent)) {
self$`userAgent` <- userAgent
}
},
CallApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(c(headerParams, self$defaultHeaders))
if (method == "GET") {
httr::GET(url, queryParams, headers, ...)
} else if (method == "POST") {
httr::POST(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
} else if (method == "PUT") {
httr::PUT(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
} else if (method == "PATCH") {
httr::PATCH(url, query = queryParams, headers, body = body, httr::content_type("application/json"), ...)
} else if (method == "HEAD") {
httr::HEAD(url, query = queryParams, headers, ...)
} else if (method == "DELETE") {
httr::DELETE(url, query = queryParams, headers, ...)
} else {
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
}
}
)
)

View File

@ -1,9 +1,9 @@
#' Response Class #' ApiResponse Class
#' #'
#' Response Class #' ApiResponse Class
#' @export #' @export
Response <- R6::R6Class( ApiResponse <- R6::R6Class(
'Response', 'ApiResponse',
public = list( public = list(
content = NULL, content = NULL,
response = NULL, response = NULL,

View File

@ -20,12 +20,13 @@ Category <- R6::R6Class(
public = list( public = list(
`id` = NULL, `id` = NULL,
`name` = NULL, `name` = NULL,
initialize = function(`id`, `name`){ initialize = function(`id`=NULL, `name`=NULL, ...){
if (!missing(`id`)) { local.optional.var <- list(...)
if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1) stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id` self$`id` <- `id`
} }
if (!missing(`name`)) { if (!is.null(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1) stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name` self$`name` <- `name`
} }
@ -53,28 +54,22 @@ Category <- R6::R6Class(
} }
}, },
toJSONString = function() { toJSONString = function() {
outstring <- sprintf( sprintf(
'{ '{
"id": "id":
%d %d,
,
"name": "name":
"%s" "%s"
}', }',
self$`id`, self$`id`,
self$`name` self$`name`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(CategoryJson) { fromJSONString = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson) CategoryObject <- jsonlite::fromJSON(CategoryJson)
self$`id` <- CategoryObject$`id` self$`id` <- CategoryObject$`id`
self$`name` <- CategoryObject$`name` self$`name` <- CategoryObject$`name`
self
} }
) )
) )

View File

@ -0,0 +1,92 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' ModelApiResponse Class
#'
#' @field code
#' @field type
#' @field message
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
ModelApiResponse <- R6::R6Class(
'ModelApiResponse',
public = list(
`code` = NULL,
`type` = NULL,
`message` = NULL,
initialize = function(`code`=NULL, `type`=NULL, `message`=NULL, ...){
local.optional.var <- list(...)
if (!is.null(`code`)) {
stopifnot(is.numeric(`code`), length(`code`) == 1)
self$`code` <- `code`
}
if (!is.null(`type`)) {
stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type`
}
if (!is.null(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message`
}
},
toJSON = function() {
ModelApiResponseObject <- list()
if (!is.null(self$`code`)) {
ModelApiResponseObject[['code']] <-
self$`code`
}
if (!is.null(self$`type`)) {
ModelApiResponseObject[['type']] <-
self$`type`
}
if (!is.null(self$`message`)) {
ModelApiResponseObject[['message']] <-
self$`message`
}
ModelApiResponseObject
},
fromJSON = function(ModelApiResponseJson) {
ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson)
if (!is.null(ModelApiResponseObject$`code`)) {
self$`code` <- ModelApiResponseObject$`code`
}
if (!is.null(ModelApiResponseObject$`type`)) {
self$`type` <- ModelApiResponseObject$`type`
}
if (!is.null(ModelApiResponseObject$`message`)) {
self$`message` <- ModelApiResponseObject$`message`
}
},
toJSONString = function() {
sprintf(
'{
"code":
%d,
"type":
"%s",
"message":
"%s"
}',
self$`code`,
self$`type`,
self$`message`
)
},
fromJSONString = function(ModelApiResponseJson) {
ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson)
self$`code` <- ModelApiResponseObject$`code`
self$`type` <- ModelApiResponseObject$`type`
self$`message` <- ModelApiResponseObject$`message`
self
}
)
)

View File

@ -0,0 +1,142 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' Order Class
#'
#' @field id
#' @field petId
#' @field quantity
#' @field shipDate
#' @field status
#' @field complete
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Order <- R6::R6Class(
'Order',
public = list(
`id` = NULL,
`petId` = NULL,
`quantity` = NULL,
`shipDate` = NULL,
`status` = NULL,
`complete` = NULL,
initialize = function(`id`=NULL, `petId`=NULL, `quantity`=NULL, `shipDate`=NULL, `status`=NULL, `complete`=FALSE, ...){
local.optional.var <- list(...)
if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!is.null(`petId`)) {
stopifnot(is.numeric(`petId`), length(`petId`) == 1)
self$`petId` <- `petId`
}
if (!is.null(`quantity`)) {
stopifnot(is.numeric(`quantity`), length(`quantity`) == 1)
self$`quantity` <- `quantity`
}
if (!is.null(`shipDate`)) {
stopifnot(is.character(`shipDate`), length(`shipDate`) == 1)
self$`shipDate` <- `shipDate`
}
if (!is.null(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status`
}
if (!is.null(`complete`)) {
self$`complete` <- `complete`
}
},
toJSON = function() {
OrderObject <- list()
if (!is.null(self$`id`)) {
OrderObject[['id']] <-
self$`id`
}
if (!is.null(self$`petId`)) {
OrderObject[['petId']] <-
self$`petId`
}
if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <-
self$`quantity`
}
if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <-
self$`shipDate`
}
if (!is.null(self$`status`)) {
OrderObject[['status']] <-
self$`status`
}
if (!is.null(self$`complete`)) {
OrderObject[['complete']] <-
self$`complete`
}
OrderObject
},
fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id`
}
if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId`
}
if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity`
}
if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate`
}
if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status`
}
if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete`
}
},
toJSONString = function() {
sprintf(
'{
"id":
%d,
"petId":
%d,
"quantity":
%d,
"shipDate":
"%s",
"status":
"%s",
"complete":
"%s"
}',
self$`id`,
self$`petId`,
self$`quantity`,
self$`shipDate`,
self$`status`,
self$`complete`
)
},
fromJSONString = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
self$`id` <- OrderObject$`id`
self$`petId` <- OrderObject$`petId`
self$`quantity` <- OrderObject$`quantity`
self$`shipDate` <- OrderObject$`shipDate`
self$`status` <- OrderObject$`status`
self$`complete` <- OrderObject$`complete`
self
}
)
)

View File

@ -28,15 +28,8 @@ Pet <- R6::R6Class(
`photoUrls` = NULL, `photoUrls` = NULL,
`tags` = NULL, `tags` = NULL,
`status` = NULL, `status` = NULL,
initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){ initialize = function(`name`, `photoUrls`, `id`=NULL, `category`=NULL, `tags`=NULL, `status`=NULL, ...){
if (!missing(`id`)) { local.optional.var <- list(...)
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!missing(`category`)) {
stopifnot(R6::is.R6(`category`))
self$`category` <- `category`
}
if (!missing(`name`)) { if (!missing(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1) stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name` self$`name` <- `name`
@ -46,12 +39,20 @@ Pet <- R6::R6Class(
sapply(`photoUrls`, function(x) stopifnot(is.character(x))) sapply(`photoUrls`, function(x) stopifnot(is.character(x)))
self$`photoUrls` <- `photoUrls` self$`photoUrls` <- `photoUrls`
} }
if (!missing(`tags`)) { if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!is.null(`category`)) {
stopifnot(R6::is.R6(`category`))
self$`category` <- `category`
}
if (!is.null(`tags`)) {
stopifnot(is.vector(`tags`), length(`tags`) != 0) stopifnot(is.vector(`tags`), length(`tags`) != 0)
sapply(`tags`, function(x) stopifnot(R6::is.R6(x))) sapply(`tags`, function(x) stopifnot(R6::is.R6(x)))
self$`tags` <- `tags` self$`tags` <- `tags`
} }
if (!missing(`status`)) { if (!is.null(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1) stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status` self$`status` <- `status`
} }
@ -113,53 +114,44 @@ Pet <- R6::R6Class(
} }
}, },
toJSONString = function() { toJSONString = function() {
outstring <- sprintf( sprintf(
'{ '{
"id": "id":
%d %d,
,
"category": "category":
"%s" %s,
,
"name": "name":
"%s",
"%s"
,
"photoUrls": "photoUrls":
[%s],
["%s"]
,
"tags": "tags":
["%s"] [%s],
,
"status": "status":
"%s" "%s"
}', }',
self$`id`, self$`id`,
self$`category`$toJSON(), jsonlite::toJSON(self$`category`$toJSON(), auto_unbox=TRUE),
self$`name`, self$`name`,
paste0(self$`photoUrls`, collapse='","'), paste(unlist(lapply(self$`photoUrls`, function(x) paste0('"', x, '"'))), collapse=","),
paste0(sapply(self$`tags`, function(x) x$toJSON()), collapse='","'), paste(unlist(lapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","),
self$`status` self$`status`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(PetJson) { fromJSONString = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson) PetObject <- jsonlite::fromJSON(PetJson)
self$`id` <- PetObject$`id` self$`id` <- PetObject$`id`
CategoryObject <- Category$new() self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`category` <- CategoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`name` <- PetObject$`name` self$`name` <- PetObject$`name`
self$`photoUrls` <- PetObject$`photoUrls` self$`photoUrls` <- lapply(PetObject$`photoUrls`, function (x) x)
self$`tags` <- sapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) data.frame <- PetObject$`tags`
self$`tags` <- vector("list", length = nrow(data.frame))
for (row in 1:nrow(data.frame)) {
tags.node <- Tag$new()
tags.node$fromJSON(jsonlite::toJSON(data.frame[row,,drop = TRUE], auto_unbox = TRUE))
self$`tags`[[row]] <- tags.node
}
self$`status` <- PetObject$`status` self$`status` <- PetObject$`status`
self
} }
) )
) )

View File

@ -11,43 +11,42 @@
#' #'
#' @field path Stores url path of the request. #' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication. #' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#' #'
#' @importFrom R6 R6Class #' @importFrom R6 R6Class
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
#' #'
#' add_pet Add a new pet to the store #' AddPet Add a new pet to the store
#' #'
#' #'
#' delete_pet Deletes a pet #' DeletePet Deletes a pet
#' #'
#' #'
#' find_pets_by_status Finds Pets by status #' FindPetsByStatus Finds Pets by status
#' #'
#' #'
#' find_pets_by_tags Finds Pets by tags #' FindPetsByTags Finds Pets by tags
#' #'
#' #'
#' get_pet_by_id Find pet by ID #' GetPetById Find pet by ID
#' #'
#' #'
#' update_pet Update an existing pet #' UpdatePet Update an existing pet
#' #'
#' #'
#' update_pet_with_form Updates a pet in the store with form data #' UpdatePetWithForm Updates a pet in the store with form data
#' #'
#' #'
#' upload_file uploads an image #' UploadFile uploads an image
#' #'
#' } #' }
#' #'
#' @importFrom caTools base64encode
#' @export #' @export
PetApi <- R6::R6Class( PetApi <- R6::R6Class(
'PetApi', 'PetApi',
public = list( public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL, apiClient = NULL,
initialize = function(apiClient){ initialize = function(apiClient){
if (!missing(apiClient)) { if (!missing(apiClient)) {
@ -57,10 +56,14 @@ PetApi <- R6::R6Class(
self$apiClient <- ApiClient$new() self$apiClient <- ApiClient$new()
} }
}, },
add_pet = function(body, ...){ AddPet = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -69,7 +72,10 @@ PetApi <- R6::R6Class(
} }
urlPath <- "/pet" urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -79,27 +85,32 @@ PetApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
delete_pet = function(pet_id, api_key, ...){ DeletePet = function(pet.id, api.key=NULL, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (!missing(`api_key`)) { if (missing(`pet.id`)) {
headerParams['api_key'] <- `api_key` stop("Missing required parameter `pet.id`.")
} }
headerParams['api_key'] <- `api.key`
urlPath <- "/pet/{petId}" urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet.id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath) urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE", method = "DELETE",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -109,23 +120,28 @@ PetApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
find_pets_by_status = function(status, ...){ FindPetsByStatus = function(status, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (!missing(`status`)) { if (missing(`status`)) {
queryParams['status'] <- status stop("Missing required parameter `status`.")
} }
queryParams['status'] <- status
urlPath <- "/pet/findByStatus" urlPath <- "/pet/findByStatus"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -133,25 +149,30 @@ PetApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) Pet$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
find_pets_by_tags = function(tags, ...){ FindPetsByTags = function(tags, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (!missing(`tags`)) { if (missing(`tags`)) {
queryParams['tags'] <- tags stop("Missing required parameter `tags`.")
} }
queryParams['tags'] <- tags
urlPath <- "/pet/findByTags" urlPath <- "/pet/findByTags"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -159,25 +180,34 @@ PetApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) Pet$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
get_pet_by_id = function(pet_id, ...){ GetPetById = function(pet.id, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`pet.id`)) {
stop("Missing required parameter `pet.id`.")
}
urlPath <- "/pet/{petId}" urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet.id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath) urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # 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='')
}
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -185,18 +215,22 @@ PetApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) Pet$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
update_pet = function(body, ...){ UpdatePet = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -205,7 +239,10 @@ PetApi <- R6::R6Class(
} }
urlPath <- "/pet" urlPath <- "/pet"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT", method = "PUT",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -215,16 +252,20 @@ PetApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
update_pet_with_form = function(pet_id, name, status, ...){ UpdatePetWithForm = function(pet.id, name=NULL, status=NULL, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`pet.id`)) {
stop("Missing required parameter `pet.id`.")
}
body <- list( body <- list(
"name" = name, "name" = name,
@ -232,11 +273,14 @@ PetApi <- R6::R6Class(
) )
urlPath <- "/pet/{petId}" urlPath <- "/pet/{petId}"
if (!missing(`pet_id`)) { if (!missing(`pet.id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath) urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -246,28 +290,35 @@ PetApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
upload_file = function(pet_id, additional_metadata, file, ...){ UploadFile = function(pet.id, additional.metadata=NULL, file=NULL, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`pet.id`)) {
stop("Missing required parameter `pet.id`.")
}
body <- list( body <- list(
"additionalMetadata" = additional_metadata, "additionalMetadata" = additional.metadata,
"file" = httr::upload_file(file) "file" = httr::upload_file(file)
) )
urlPath <- "/pet/{petId}/uploadImage" urlPath <- "/pet/{petId}/uploadImage"
if (!missing(`pet_id`)) { if (!missing(`pet.id`)) {
urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet_id`, urlPath) urlPath <- gsub(paste0("\\{", "petId", "\\}"), `pet.id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # OAuth token
headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -275,11 +326,11 @@ PetApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) ModelApiResponse$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
} }

View File

@ -11,31 +11,30 @@
#' #'
#' @field path Stores url path of the request. #' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication. #' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#' #'
#' @importFrom R6 R6Class #' @importFrom R6 R6Class
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
#' #'
#' delete_order Delete purchase order by ID #' DeleteOrder Delete purchase order by ID
#' #'
#' #'
#' get_inventory Returns pet inventories by status #' GetInventory Returns pet inventories by status
#' #'
#' #'
#' get_order_by_id Find purchase order by ID #' GetOrderById Find purchase order by ID
#' #'
#' #'
#' place_order Place an order for a pet #' PlaceOrder Place an order for a pet
#' #'
#' } #' }
#' #'
#' @importFrom caTools base64encode
#' @export #' @export
StoreApi <- R6::R6Class( StoreApi <- R6::R6Class(
'StoreApi', 'StoreApi',
public = list( public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL, apiClient = NULL,
initialize = function(apiClient){ initialize = function(apiClient){
if (!missing(apiClient)) { if (!missing(apiClient)) {
@ -45,17 +44,22 @@ StoreApi <- R6::R6Class(
self$apiClient <- ApiClient$new() self$apiClient <- ApiClient$new()
} }
}, },
delete_order = function(order_id, ...){ DeleteOrder = function(order.id, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
urlPath <- "/store/order/{orderId}" if (missing(`order.id`)) {
if (!missing(`order_id`)) { stop("Missing required parameter `order.id`.")
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), urlPath <- "/store/order/{orderId}"
if (!missing(`order.id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath)
}
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE", method = "DELETE",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -65,19 +69,24 @@ StoreApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
get_inventory = function(...){ GetInventory = function(...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
urlPath <- "/store/inventory" urlPath <- "/store/inventory"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath), # 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='')
}
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -85,25 +94,30 @@ StoreApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) integer$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
get_order_by_id = function(order_id, ...){ GetOrderById = function(order.id, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`order.id`)) {
stop("Missing required parameter `order.id`.")
}
urlPath <- "/store/order/{orderId}" urlPath <- "/store/order/{orderId}"
if (!missing(`order_id`)) { if (!missing(`order.id`)) {
urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order_id`, urlPath) urlPath <- gsub(paste0("\\{", "orderId", "\\}"), `order.id`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -111,18 +125,22 @@ StoreApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) Order$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
place_order = function(body, ...){ PlaceOrder = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -131,7 +149,8 @@ StoreApi <- R6::R6Class(
} }
urlPath <- "/store/order" urlPath <- "/store/order"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -139,11 +158,11 @@ StoreApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) Order$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
} }

View File

@ -20,12 +20,13 @@ Tag <- R6::R6Class(
public = list( public = list(
`id` = NULL, `id` = NULL,
`name` = NULL, `name` = NULL,
initialize = function(`id`, `name`){ initialize = function(`id`=NULL, `name`=NULL, ...){
if (!missing(`id`)) { local.optional.var <- list(...)
if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1) stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id` self$`id` <- `id`
} }
if (!missing(`name`)) { if (!is.null(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1) stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name` self$`name` <- `name`
} }
@ -53,28 +54,22 @@ Tag <- R6::R6Class(
} }
}, },
toJSONString = function() { toJSONString = function() {
outstring <- sprintf( sprintf(
'{ '{
"id": "id":
%d %d,
,
"name": "name":
"%s" "%s"
}', }',
self$`id`, self$`id`,
self$`name` self$`name`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(TagJson) { fromJSONString = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson) TagObject <- jsonlite::fromJSON(TagJson)
self$`id` <- TagObject$`id` self$`id` <- TagObject$`id`
self$`name` <- TagObject$`name` self$`name` <- TagObject$`name`
self
} }
) )
) )

View File

@ -0,0 +1,177 @@
# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://openapi-generator.tech
#' User Class
#'
#' @field id
#' @field username
#' @field firstName
#' @field lastName
#' @field email
#' @field password
#' @field phone
#' @field userStatus
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
User <- R6::R6Class(
'User',
public = list(
`id` = NULL,
`username` = NULL,
`firstName` = NULL,
`lastName` = NULL,
`email` = NULL,
`password` = NULL,
`phone` = NULL,
`userStatus` = NULL,
initialize = function(`id`=NULL, `username`=NULL, `firstName`=NULL, `lastName`=NULL, `email`=NULL, `password`=NULL, `phone`=NULL, `userStatus`=NULL, ...){
local.optional.var <- list(...)
if (!is.null(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id`
}
if (!is.null(`username`)) {
stopifnot(is.character(`username`), length(`username`) == 1)
self$`username` <- `username`
}
if (!is.null(`firstName`)) {
stopifnot(is.character(`firstName`), length(`firstName`) == 1)
self$`firstName` <- `firstName`
}
if (!is.null(`lastName`)) {
stopifnot(is.character(`lastName`), length(`lastName`) == 1)
self$`lastName` <- `lastName`
}
if (!is.null(`email`)) {
stopifnot(is.character(`email`), length(`email`) == 1)
self$`email` <- `email`
}
if (!is.null(`password`)) {
stopifnot(is.character(`password`), length(`password`) == 1)
self$`password` <- `password`
}
if (!is.null(`phone`)) {
stopifnot(is.character(`phone`), length(`phone`) == 1)
self$`phone` <- `phone`
}
if (!is.null(`userStatus`)) {
stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1)
self$`userStatus` <- `userStatus`
}
},
toJSON = function() {
UserObject <- list()
if (!is.null(self$`id`)) {
UserObject[['id']] <-
self$`id`
}
if (!is.null(self$`username`)) {
UserObject[['username']] <-
self$`username`
}
if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <-
self$`firstName`
}
if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <-
self$`lastName`
}
if (!is.null(self$`email`)) {
UserObject[['email']] <-
self$`email`
}
if (!is.null(self$`password`)) {
UserObject[['password']] <-
self$`password`
}
if (!is.null(self$`phone`)) {
UserObject[['phone']] <-
self$`phone`
}
if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <-
self$`userStatus`
}
UserObject
},
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id`
}
if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username`
}
if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName`
}
if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName`
}
if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email`
}
if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password`
}
if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone`
}
if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus`
}
},
toJSONString = function() {
sprintf(
'{
"id":
%d,
"username":
"%s",
"firstName":
"%s",
"lastName":
"%s",
"email":
"%s",
"password":
"%s",
"phone":
"%s",
"userStatus":
%d
}',
self$`id`,
self$`username`,
self$`firstName`,
self$`lastName`,
self$`email`,
self$`password`,
self$`phone`,
self$`userStatus`
)
},
fromJSONString = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
self$`id` <- UserObject$`id`
self$`username` <- UserObject$`username`
self$`firstName` <- UserObject$`firstName`
self$`lastName` <- UserObject$`lastName`
self$`email` <- UserObject$`email`
self$`password` <- UserObject$`password`
self$`phone` <- UserObject$`phone`
self$`userStatus` <- UserObject$`userStatus`
self
}
)
)

View File

@ -11,43 +11,42 @@
#' #'
#' @field path Stores url path of the request. #' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication. #' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#' #'
#' @importFrom R6 R6Class #' @importFrom R6 R6Class
#' #'
#' @section Methods: #' @section Methods:
#' \describe{ #' \describe{
#' #'
#' create_user Create user #' CreateUser Create user
#' #'
#' #'
#' create_users_with_array_input Creates list of users with given input array #' CreateUsersWithArrayInput Creates list of users with given input array
#' #'
#' #'
#' create_users_with_list_input Creates list of users with given input array #' CreateUsersWithListInput Creates list of users with given input array
#' #'
#' #'
#' delete_user Delete user #' DeleteUser Delete user
#' #'
#' #'
#' get_user_by_name Get user by user name #' GetUserByName Get user by user name
#' #'
#' #'
#' login_user Logs user into the system #' LoginUser Logs user into the system
#' #'
#' #'
#' logout_user Logs out current logged in user session #' LogoutUser Logs out current logged in user session
#' #'
#' #'
#' update_user Updated user #' UpdateUser Updated user
#' #'
#' } #' }
#' #'
#' @importFrom caTools base64encode
#' @export #' @export
UserApi <- R6::R6Class( UserApi <- R6::R6Class(
'UserApi', 'UserApi',
public = list( public = list(
userAgent = "OpenAPI-Generator/1.0.0/r",
apiClient = NULL, apiClient = NULL,
initialize = function(apiClient){ initialize = function(apiClient){
if (!missing(apiClient)) { if (!missing(apiClient)) {
@ -57,10 +56,14 @@ UserApi <- R6::R6Class(
self$apiClient <- ApiClient$new() self$apiClient <- ApiClient$new()
} }
}, },
create_user = function(body, ...){ CreateUser = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -69,7 +72,8 @@ UserApi <- R6::R6Class(
} }
urlPath <- "/user" urlPath <- "/user"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -79,16 +83,20 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
create_users_with_array_input = function(body, ...){ CreateUsersWithArrayInput = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -97,7 +105,8 @@ UserApi <- R6::R6Class(
} }
urlPath <- "/user/createWithArray" urlPath <- "/user/createWithArray"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -107,16 +116,20 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
create_users_with_list_input = function(body, ...){ CreateUsersWithListInput = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -125,7 +138,8 @@ UserApi <- R6::R6Class(
} }
urlPath <- "/user/createWithList" urlPath <- "/user/createWithList"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST", method = "POST",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -135,23 +149,28 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
delete_user = function(username, ...){ DeleteUser = function(username, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`username`)) {
stop("Missing required parameter `username`.")
}
urlPath <- "/user/{username}" urlPath <- "/user/{username}"
if (!missing(`username`)) { if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "DELETE", method = "DELETE",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -161,23 +180,28 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
get_user_by_name = function(username, ...){ GetUserByName = function(username, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`username`)) {
stop("Missing required parameter `username`.")
}
urlPath <- "/user/{username}" urlPath <- "/user/{username}"
if (!missing(`username`)) { if (!missing(`username`)) {
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -185,29 +209,34 @@ UserApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) User$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
login_user = function(username, password, ...){ LoginUser = function(username, password, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`username`)) {
stop("Missing required parameter `username`.")
}
if (missing(`password`)) {
stop("Missing required parameter `password`.")
}
if (!missing(`username`)) {
queryParams['username'] <- username queryParams['username'] <- username
}
if (!missing(`password`)) {
queryParams['password'] <- password queryParams['password'] <- password
}
urlPath <- "/user/login" urlPath <- "/user/login"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -215,21 +244,22 @@ UserApi <- R6::R6Class(
...) ...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) character$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
logout_user = function(...){ LogoutUser = function(...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
urlPath <- "/user/logout" urlPath <- "/user/logout"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET", method = "GET",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -239,16 +269,24 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
}, },
update_user = function(username, body, ...){ UpdateUser = function(username, body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- c()
if (missing(`username`)) {
stop("Missing required parameter `username`.")
}
if (missing(`body`)) {
stop("Missing required parameter `body`.")
}
if (!missing(`body`)) { if (!missing(`body`)) {
body <- `body`$toJSONString() body <- `body`$toJSONString()
@ -261,7 +299,8 @@ UserApi <- R6::R6Class(
urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath) urlPath <- gsub(paste0("\\{", "username", "\\}"), `username`, urlPath)
} }
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "PUT", method = "PUT",
queryParams = queryParams, queryParams = queryParams,
headerParams = headerParams, headerParams = headerParams,
@ -271,9 +310,9 @@ UserApi <- R6::R6Class(
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
# void response, no need to return anything # void response, no need to return anything
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) ApiResponse$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
Response$new("API server error", resp) ApiResponse$new("API server error", resp)
} }
} }

View File

@ -10,23 +10,104 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
- Build package: org.openapitools.codegen.languages.RClientCodegen - Build package: org.openapitools.codegen.languages.RClientCodegen
## Installation ## Installation
You'll need the `devtools` package in order to build the API.
Make sure you have a proper CRAN repository from which you can download packages.
### Prerequisites ### Prerequisites
Install the `devtools` package with the following command.
Install the dependencies
```R ```R
if(!require(devtools)) { install.packages("devtools") } install.packages("jsonlite")
install.packages("httr")
install.packages("caTools")
``` ```
### Installation of the API package ### Build the package
Make sure you set the working directory to where the API code is located.
Then execute ```sh
```R git clone https://github.com/GIT_USER_ID/GIT_REPO_ID
library(devtools) cd GIT_REPO_ID
install(".") R CMD build .
R CMD check petstore_1.0.0.tar.gz
R CMD INSTALL petstore_1.0.0.tar.gz
``` ```
### Install the package
```R
install.packages("petstore")
```
To install directly from Github, use `devtools`:
```R
install.packages("devtools")
library(devtools)
install_github("GIT_USER_ID/GIT_REPO_ID")
```
### Usage
```R
library(petstore)
```
## Documentation for API Endpoints
All URIs are relative to *http://petstore.swagger.io/v2*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PetApi* | [**AddPet**](docs/PetApi.md#AddPet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**DeletePet**](docs/PetApi.md#DeletePet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#FindPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
*PetApi* | [**FindPetsByTags**](docs/PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**GetPetById**](docs/PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**UpdatePet**](docs/PetApi.md#UpdatePet) | **PUT** /pet | Update an existing pet
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#UpdatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**UploadFile**](docs/PetApi.md#UploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#DeleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**GetInventory**](docs/StoreApi.md#GetInventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**GetOrderById**](docs/StoreApi.md#GetOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**PlaceOrder**](docs/StoreApi.md#PlaceOrder) | **POST** /store/order | Place an order for a pet
*UserApi* | [**CreateUser**](docs/UserApi.md#CreateUser) | **POST** /user | Create user
*UserApi* | [**CreateUsersWithArrayInput**](docs/UserApi.md#CreateUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**CreateUsersWithListInput**](docs/UserApi.md#CreateUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
*UserApi* | [**DeleteUser**](docs/UserApi.md#DeleteUser) | **DELETE** /user/{username} | Delete user
*UserApi* | [**GetUserByName**](docs/UserApi.md#GetUserByName) | **GET** /user/{username} | Get user by user name
*UserApi* | [**LoginUser**](docs/UserApi.md#LoginUser) | **GET** /user/login | Logs user into the system
*UserApi* | [**LogoutUser**](docs/UserApi.md#LogoutUser) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**UpdateUser**](docs/UserApi.md#UpdateUser) | **PUT** /user/{username} | Updated user
## Documentation for Models
- [Category](docs/Category.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)
## Documentation for Authorization
### api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
### petstore_auth
- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- write:pets: modify pets in your account
- read:pets: read your pets
## Author ## Author

View File

@ -0,0 +1,10 @@
# petstore::ApiResponse
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**code** | **integer** | | [optional]
**type** | **character** | | [optional]
**message** | **character** | | [optional]

View File

@ -0,0 +1,9 @@
# petstore::Category
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**name** | **character** | | [optional]

View File

@ -0,0 +1,10 @@
# petstore::ModelApiResponse
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**code** | **integer** | | [optional]
**type** | **character** | | [optional]
**message** | **character** | | [optional]

View File

@ -0,0 +1,13 @@
# petstore::Order
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**petId** | **integer** | | [optional]
**quantity** | **integer** | | [optional]
**shipDate** | **character** | | [optional]
**status** | **character** | Order Status | [optional]
**complete** | **character** | | [optional] [default to FALSE]

View File

@ -0,0 +1,13 @@
# petstore::Pet
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**category** | [**Category**](Category.md) | | [optional]
**name** | **character** | | [default to &#39;doggie&#39;]
**photoUrls** | **character** | |
**tags** | [**Tag**](Tag.md) | | [optional]
**status** | **character** | pet status in the store | [optional]

View File

@ -0,0 +1,348 @@
# PetApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**AddPet**](PetApi.md#AddPet) | **POST** /pet | Add a new pet to the store
[**DeletePet**](PetApi.md#DeletePet) | **DELETE** /pet/{petId} | Deletes a pet
[**FindPetsByStatus**](PetApi.md#FindPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
[**FindPetsByTags**](PetApi.md#FindPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
[**GetPetById**](PetApi.md#GetPetById) | **GET** /pet/{petId} | Find pet by ID
[**UpdatePet**](PetApi.md#UpdatePet) | **PUT** /pet | Update an existing pet
[**UpdatePetWithForm**](PetApi.md#UpdatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
[**UploadFile**](PetApi.md#UploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
# **AddPet**
> AddPet(body)
Add a new pet to the store
### Example
```R
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';
api.instance$AddPet(var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
### Return type
void (empty response body)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Accept**: Not defined
# **DeletePet**
> DeletePet(pet.id, api.key=var.api.key)
Deletes a pet
### Example
```R
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';
api.instance$DeletePet(var.pet.id, api.key=var.api.key)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet.id** | **integer**| Pet id to delete |
**api.key** | **character**| | [optional]
### Return type
void (empty response body)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **FindPetsByStatus**
> Pet FindPetsByStatus(status)
Finds Pets by status
Multiple status values can be provided with comma separated strings
### Example
```R
library(petstore)
var.status <- ['status_example'] # 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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**status** | [**character**](character.md)| Status values that need to be considered for filter |
### Return type
[**Pet**](Pet.md)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **FindPetsByTags**
> Pet FindPetsByTags(tags)
Finds Pets by tags
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
### Example
```R
library(petstore)
var.tags <- ['tags_example'] # 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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**tags** | [**character**](character.md)| Tags to filter by |
### Return type
[**Pet**](Pet.md)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **GetPetById**
> Pet GetPetById(pet.id)
Find pet by ID
Returns a single pet
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet.id** | **integer**| ID of pet to return |
### Return type
[**Pet**](Pet.md)
### Authorization
[api_key](../README.md#api_key)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **UpdatePet**
> UpdatePet(body)
Update an existing pet
### Example
```R
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';
api.instance$UpdatePet(var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
### Return type
void (empty response body)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: application/json, application/xml
- **Accept**: Not defined
# **UpdatePetWithForm**
> UpdatePetWithForm(pet.id, name=var.name, status=var.status)
Updates a pet in the store with form data
### Example
```R
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';
api.instance$UpdatePetWithForm(var.pet.id, name=var.name, status=var.status)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet.id** | **integer**| ID of pet that needs to be updated |
**name** | **character**| Updated name of the pet | [optional]
**status** | **character**| Updated status of the pet | [optional]
### Return type
void (empty response body)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: application/x-www-form-urlencoded
- **Accept**: Not defined
# **UploadFile**
> ModelApiResponse UploadFile(pet.id, additional.metadata=var.additional.metadata, file=var.file)
uploads an image
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet.id** | **integer**| ID of pet to update |
**additional.metadata** | **character**| Additional data to pass to server | [optional]
**file** | **data.frame**| file to upload | [optional]
### Return type
[**ModelApiResponse**](ApiResponse.md)
### Authorization
[petstore_auth](../README.md#petstore_auth)
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: application/json

View File

@ -0,0 +1,167 @@
# StoreApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**DeleteOrder**](StoreApi.md#DeleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
[**GetInventory**](StoreApi.md#GetInventory) | **GET** /store/inventory | Returns pet inventories by status
[**GetOrderById**](StoreApi.md#GetOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
[**PlaceOrder**](StoreApi.md#PlaceOrder) | **POST** /store/order | Place an order for a pet
# **DeleteOrder**
> DeleteOrder(order.id)
Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example
```R
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()
api.instance$DeleteOrder(var.order.id)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**order.id** | **character**| ID of the order that needs to be deleted |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **GetInventory**
> integer GetInventory()
Returns pet inventories by status
Returns a map of status codes to quantities
### Example
```R
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()
dput(result)
```
### Parameters
This endpoint does not need any parameter.
### Return type
**integer**
### Authorization
[api_key](../README.md#api_key)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json
# **GetOrderById**
> Order GetOrderById(order.id)
Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**order.id** | **integer**| ID of pet that needs to be fetched |
### Return type
[**Order**](Order.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **PlaceOrder**
> Order PlaceOrder(body)
Place an order for a pet
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**Order**](Order.md)| order placed for purchasing the pet |
### Return type
[**Order**](Order.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json

View File

@ -0,0 +1,9 @@
# petstore::Tag
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**name** | **character** | | [optional]

View File

@ -0,0 +1,15 @@
# petstore::User
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **integer** | | [optional]
**username** | **character** | | [optional]
**firstName** | **character** | | [optional]
**lastName** | **character** | | [optional]
**email** | **character** | | [optional]
**password** | **character** | | [optional]
**phone** | **character** | | [optional]
**userStatus** | **integer** | User Status | [optional]

View File

@ -0,0 +1,320 @@
# UserApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**CreateUser**](UserApi.md#CreateUser) | **POST** /user | Create user
[**CreateUsersWithArrayInput**](UserApi.md#CreateUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
[**CreateUsersWithListInput**](UserApi.md#CreateUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
[**DeleteUser**](UserApi.md#DeleteUser) | **DELETE** /user/{username} | Delete user
[**GetUserByName**](UserApi.md#GetUserByName) | **GET** /user/{username} | Get user by user name
[**LoginUser**](UserApi.md#LoginUser) | **GET** /user/login | Logs user into the system
[**LogoutUser**](UserApi.md#LogoutUser) | **GET** /user/logout | Logs out current logged in user session
[**UpdateUser**](UserApi.md#UpdateUser) | **PUT** /user/{username} | Updated user
# **CreateUser**
> CreateUser(body)
Create user
This can only be done by the logged in user.
### Example
```R
library(petstore)
var.body <- User$new() # User | Created user object
#Create user
api.instance <- UserApi$new()
api.instance$CreateUser(var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](User.md)| Created user object |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **CreateUsersWithArrayInput**
> CreateUsersWithArrayInput(body)
Creates list of users with given input array
### Example
```R
library(petstore)
var.body <- [array$new()] # User | List of user object
#Creates list of users with given input array
api.instance <- UserApi$new()
api.instance$CreateUsersWithArrayInput(var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](array.md)| List of user object |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **CreateUsersWithListInput**
> CreateUsersWithListInput(body)
Creates list of users with given input array
### Example
```R
library(petstore)
var.body <- [array$new()] # User | List of user object
#Creates list of users with given input array
api.instance <- UserApi$new()
api.instance$CreateUsersWithListInput(var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**User**](array.md)| List of user object |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **DeleteUser**
> DeleteUser(username)
Delete user
This can only be done by the logged in user.
### Example
```R
library(petstore)
var.username <- 'username_example' # character | The name that needs to be deleted
#Delete user
api.instance <- UserApi$new()
api.instance$DeleteUser(var.username)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **character**| The name that needs to be deleted |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **GetUserByName**
> User GetUserByName(username)
Get user by user name
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **character**| The name that needs to be fetched. Use user1 for testing. |
### Return type
[**User**](User.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **LoginUser**
> character LoginUser(username, password)
Logs user into the system
### Example
```R
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)
dput(result)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **character**| The user name for login |
**password** | **character**| The password for login in clear text |
### Return type
**character**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
# **LogoutUser**
> LogoutUser()
Logs out current logged in user session
### Example
```R
library(petstore)
#Logs out current logged in user session
api.instance <- UserApi$new()
api.instance$LogoutUser()
```
### Parameters
This endpoint does not need any parameter.
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
# **UpdateUser**
> UpdateUser(username, body)
Updated user
This can only be done by the logged in user.
### Example
```R
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()
api.instance$UpdateUser(var.username, var.body)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **character**| name that need to be deleted |
**body** | [**User**](User.md)| Updated user object |
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined

View File

@ -0,0 +1,4 @@
library(testthat)
library(petstore)
test_check("petstore")

View File

@ -0,0 +1,21 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Category")
model.instance <- Category$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("name", {
# tests for the property `name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`name`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,28 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test ModelApiResponse")
model.instance <- ModelApiResponse$new()
test_that("code", {
# tests for the property `code` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`code`, "EXPECTED_RESULT")
})
test_that("type", {
# tests for the property `type` (character)
# uncomment below to test the property
#expect_equal(model.instance$`type`, "EXPECTED_RESULT")
})
test_that("message", {
# tests for the property `message` (character)
# uncomment below to test the property
#expect_equal(model.instance$`message`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,50 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Order")
model.instance <- Order$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("pet_id", {
# tests for the property `pet_id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`pet_id`, "EXPECTED_RESULT")
})
test_that("quantity", {
# tests for the property `quantity` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`quantity`, "EXPECTED_RESULT")
})
test_that("ship_date", {
# tests for the property `ship_date` (character)
# uncomment below to test the property
#expect_equal(model.instance$`ship_date`, "EXPECTED_RESULT")
})
test_that("status", {
# tests for the property `status` (character)
# Order Status
# uncomment below to test the property
#expect_equal(model.instance$`status`, "EXPECTED_RESULT")
})
test_that("complete", {
# tests for the property `complete` (character)
# uncomment below to test the property
#expect_equal(model.instance$`complete`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,50 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Pet")
model.instance <- Pet$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("category", {
# tests for the property `category` (Category)
# uncomment below to test the property
#expect_equal(model.instance$`category`, "EXPECTED_RESULT")
})
test_that("name", {
# tests for the property `name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`name`, "EXPECTED_RESULT")
})
test_that("photo_urls", {
# tests for the property `photo_urls` (character)
# uncomment below to test the property
#expect_equal(model.instance$`photo_urls`, "EXPECTED_RESULT")
})
test_that("tags", {
# tests for the property `tags` (Tag)
# uncomment below to test the property
#expect_equal(model.instance$`tags`, "EXPECTED_RESULT")
})
test_that("status", {
# tests for the property `status` (character)
# pet status in the store
# uncomment below to test the property
#expect_equal(model.instance$`status`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,103 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test PetApi")
api.instance <- PetApi$new()
test_that("AddPet", {
# tests for AddPet
# Add a new pet to the store
# @param body Pet object that needs to be added to the store
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("DeletePet", {
# tests for DeletePet
# Deletes a pet
# @param pet.id Pet id to delete
# @param [Hash] opts the optional parameters
# @option opts [character] :api.key
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("FindPetsByStatus", {
# tests for FindPetsByStatus
# Finds Pets by status
# Multiple status values can be provided with comma separated strings
# @param status Status values that need to be considered for filter
# @param [Hash] opts the optional parameters
# @return [Pet]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("FindPetsByTags", {
# tests for FindPetsByTags
# Finds Pets by tags
# Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
# @param tags Tags to filter by
# @param [Hash] opts the optional parameters
# @return [Pet]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("GetPetById", {
# tests for GetPetById
# Find pet by ID
# Returns a single pet
# @param pet.id ID of pet to return
# @param [Hash] opts the optional parameters
# @return [Pet]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("UpdatePet", {
# tests for UpdatePet
# Update an existing pet
# @param body Pet object that needs to be added to the store
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("UpdatePetWithForm", {
# tests for UpdatePetWithForm
# Updates a pet in the store with form data
# @param pet.id ID of pet that needs to be updated
# @param [Hash] opts the optional parameters
# @option opts [character] :name Updated name of the pet
# @option opts [character] :status Updated status of the pet
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("UploadFile", {
# tests for UploadFile
# uploads an image
# @param pet.id ID of pet to update
# @param [Hash] opts the optional parameters
# @option opts [character] :additional.metadata Additional data to pass to server
# @option opts [data.frame] :file file to upload
# @return [ModelApiResponse]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,53 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test StoreApi")
api.instance <- StoreApi$new()
test_that("DeleteOrder", {
# tests for DeleteOrder
# Delete purchase order by ID
# For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
# @param order.id ID of the order that needs to be deleted
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("GetInventory", {
# tests for GetInventory
# Returns pet inventories by status
# Returns a map of status codes to quantities
# @param [Hash] opts the optional parameters
# @return [integer]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("GetOrderById", {
# tests for GetOrderById
# Find purchase order by ID
# For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
# @param order.id ID of pet that needs to be fetched
# @param [Hash] opts the optional parameters
# @return [Order]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("PlaceOrder", {
# tests for PlaceOrder
# Place an order for a pet
# @param body order placed for purchasing the pet
# @param [Hash] opts the optional parameters
# @return [Order]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,21 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test Tag")
model.instance <- Tag$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("name", {
# tests for the property `name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`name`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,64 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test User")
model.instance <- User$new()
test_that("id", {
# tests for the property `id` (integer)
# uncomment below to test the property
#expect_equal(model.instance$`id`, "EXPECTED_RESULT")
})
test_that("username", {
# tests for the property `username` (character)
# uncomment below to test the property
#expect_equal(model.instance$`username`, "EXPECTED_RESULT")
})
test_that("first_name", {
# tests for the property `first_name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`first_name`, "EXPECTED_RESULT")
})
test_that("last_name", {
# tests for the property `last_name` (character)
# uncomment below to test the property
#expect_equal(model.instance$`last_name`, "EXPECTED_RESULT")
})
test_that("email", {
# tests for the property `email` (character)
# uncomment below to test the property
#expect_equal(model.instance$`email`, "EXPECTED_RESULT")
})
test_that("password", {
# tests for the property `password` (character)
# uncomment below to test the property
#expect_equal(model.instance$`password`, "EXPECTED_RESULT")
})
test_that("phone", {
# tests for the property `phone` (character)
# uncomment below to test the property
#expect_equal(model.instance$`phone`, "EXPECTED_RESULT")
})
test_that("user_status", {
# tests for the property `user_status` (integer)
# User Status
# uncomment below to test the property
#expect_equal(model.instance$`user_status`, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,99 @@
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
context("Test UserApi")
api.instance <- UserApi$new()
test_that("CreateUser", {
# tests for CreateUser
# Create user
# This can only be done by the logged in user.
# @param body Created user object
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("CreateUsersWithArrayInput", {
# tests for CreateUsersWithArrayInput
# Creates list of users with given input array
# @param body List of user object
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("CreateUsersWithListInput", {
# tests for CreateUsersWithListInput
# Creates list of users with given input array
# @param body List of user object
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("DeleteUser", {
# tests for DeleteUser
# Delete user
# This can only be done by the logged in user.
# @param username The name that needs to be deleted
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("GetUserByName", {
# tests for GetUserByName
# Get user by user name
# @param username The name that needs to be fetched. Use user1 for testing.
# @param [Hash] opts the optional parameters
# @return [User]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("LoginUser", {
# tests for LoginUser
# Logs user into the system
# @param username The user name for login
# @param password The password for login in clear text
# @param [Hash] opts the optional parameters
# @return [character]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("LogoutUser", {
# tests for LogoutUser
# Logs out current logged in user session
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})
test_that("UpdateUser", {
# tests for UpdateUser
# Updated user
# This can only be done by the logged in user.
# @param username name that need to be deleted
# @param body Updated user object
# @param [Hash] opts the optional parameters
# @return [Void]
# uncomment below to test the operation
#expect_equal(result, "EXPECTED_RESULT")
})

View File

@ -0,0 +1,4 @@
library(testthat)
library(petstore)
test_check("petstore")