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 90a6302a65.

* 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
58 changed files with 3129 additions and 1104 deletions

View File

@@ -17,8 +17,10 @@
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.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
@@ -27,6 +29,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.regex.Pattern;
import static org.openapitools.codegen.utils.StringUtils.camelize;
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 apiDocPath = "docs/";
protected String modelDocPath = "docs/";
protected String testFolder = "tests/testthat";
public CodegenType getTag() {
return CodegenType.CLIENT;
@@ -54,8 +58,8 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
public RClientCodegen() {
super();
outputFolder = "generated-code/r";
modelTemplateFiles.put("model.mustache", ".r");
apiTemplateFiles.put("api.mustache", ".r");
modelTemplateFiles.put("model.mustache", ".R");
apiTemplateFiles.put("api.mustache", ".R");
modelDocTemplateFiles.put("model_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
"if", "else", "repeat", "while", "function", "for", "in",
"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("modelDocPath", modelDocPath);
apiTestTemplateFiles.clear(); // TODO: add api test template
modelTestTemplateFiles.clear(); // TODO: add model test template
modelTestTemplateFiles.put("model_test.mustache", ".R");
apiTestTemplateFiles.put("api_test.mustache", ".R");
apiDocTemplateFiles.clear(); // TODO: add api doc template
modelDocTemplateFiles.clear(); // TODO: add model doc template
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
modelPackage = 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("Rbuildignore.mustache", "", ".Rbuildignore"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("response.mustache", "/R", "Response.r"));
supportingFiles.add(new SupportingFile("element.mustache", "/R", "Element.r"));
supportingFiles.add(new SupportingFile("api_client.mustache", "/R", "ApiClient.r"));
supportingFiles.add(new SupportingFile("ApiResponse.mustache", File.separator + "R", "api_response.R"));
//supportingFiles.add(new SupportingFile("element.mustache", File.separator + "R", "Element.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("testthat.mustache", File.separator + "tests", "testthat.R"));
}
@Override
@@ -180,7 +187,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
}
@Override
public String toVarName(String name) {
public String toParamName(String name) {
// replace - with _ e.g. created-at => created_at
name = sanitizeName(name.replaceAll("-", "_"));
@@ -200,21 +207,22 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
if (name.matches("^\\d.*"))
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;
}
@Override
public String toParamName(String name) {
return toVarName(name);
public String toModelFilename(String name) {
return underscore(toModelName(name));
}
@Override
public String toModelName(String name) {
return toModelFilename(name);
}
@Override
public String toModelFilename(String name) {
if (!StringUtils.isEmpty(modelNamePrefix)) {
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'.
// e.g. PetApi.r => pet_api.r
return camelize(name + "_api");
return underscore(name + "_api");
}
@Override
@@ -327,7 +335,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
sanitizedOperationId = "call_" + sanitizedOperationId;
}
return underscore(sanitizedOperationId);
return camelize(sanitizedOperationId);
}
@Override
@@ -450,4 +458,179 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
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/
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
Response <- R6::R6Class(
'Response',
ApiResponse <- R6::R6Class(
'ApiResponse',
public = list(
content = NULL,
response = NULL,
@@ -12,4 +12,4 @@ Response <- R6::R6Class(
self$response <- response
}
)
)
)

View File

@@ -1,8 +1,26 @@
# Generated by openapi-generator: https://openapi-generator.tech
# Do not edit by hand
# Core
export(ApiClient)
export(ApiResponse)
# Models
{{#models}}
{{#model}}
export({{{classname}}})
{{/model}}
{{/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}}
## 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
Install the `devtools` package with the following command.
Install the dependencies
```R
if(!require(devtools)) { install.packages("devtools") }
install.packages("jsonlite")
install.packages("httr")
install.packages("caTools")
```
### Installation of the API package
Make sure you set the working directory to where the API code is located.
Then execute
```R
library(devtools)
install(".")
### Build the package
```sh
git clone https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}
cd {{{gitRepoId}}}
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
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}

View File

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

View File

@@ -5,7 +5,6 @@
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
@@ -18,11 +17,11 @@
{{/operation}}
#' }
#'
#' @importFrom caTools base64encode
#' @export
{{classname}} <- R6::R6Class(
'{{classname}}',
public = list(
userAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
@@ -33,36 +32,34 @@
}
},
{{#operation}}
{{operationId}} = function({{#allParams}}{{paramName}}, {{/allParams}}...){
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{#defaultValue}}{{{.}}}{{/defaultValue}}, {{/optionalParams}}...){
args <- list(...)
queryParams <- list()
headerParams <- character()
headerParams <- c()
{{#hasHeaderParams}}
{{#headerParams}}
if (!missing(`{{paramName}}`)) {
headerParams['{{baseName}}'] <- `{{paramName}}`
{{#requiredParams}}
if (missing(`{{paramName}}`)) {
stop("Missing required parameter `{{{paramName}}}`.")
}
{{/requiredParams}}
{{#headerParams}}
headerParams['{{baseName}}'] <- `{{paramName}}`
{{/headerParams}}
{{/hasHeaderParams}}
{{#hasQueryParams}}
{{#queryParams}}
if (!missing(`{{paramName}}`)) {
queryParams['{{baseName}}'] <- {{paramName}}
}
queryParams['{{baseName}}'] <- {{paramName}}
{{/queryParams}}
{{/hasQueryParams}}
{{#hasFormParams}}
body <- list(
{{#formParams}}
{{^isFile}}
"{{baseName}}" = {{paramName}}{{#hasMore}},{{/hasMore}}
{{/isFile}}
{{#isFile}}
"{{baseName}}" = httr::upload_file({{paramName}}){{#hasMore}},{{/hasMore}}
{{/isFile}}
{{^isFile}}
"{{baseName}}" = {{paramName}}{{#hasMore}},{{/hasMore}}
{{/isFile}}
{{#isFile}}
"{{baseName}}" = httr::upload_file({{paramName}}){{#hasMore}},{{/hasMore}}
{{/isFile}}
{{/formParams}}
)
@@ -86,7 +83,33 @@
{{/pathParams}}
{{/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}}",
queryParams = queryParams,
headerParams = headerParams,
@@ -95,22 +118,20 @@
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
{{#returnType}}
{{#isPrimitiveType}}
returnObject <- {{returnType}}$new()
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
{{/isPrimitiveType}}
{{/returnType}}
{{#isPrimitiveType}}
httr::content(resp, "text", encoding = "UTF-8"
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{returnType}}$new()$fromJSONString(httr::content(resp, "text", encoding = "UTF-8"))
{{/isPrimitiveType}}
{{/returnType}}
{{^returnType}}
# void response, no need to return anything
# void response, no need to return anything
{{/returnType}}
} 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) {
Response$new("API server error", resp)
ApiResponse$new("API server error", resp)
}
}{{#hasMore}},{{/hasMore}}

View File

@@ -12,53 +12,82 @@
#' 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 = "{{{basePath}}}",
configuration = NULL,
userAgent = NULL,
# user agent in the HTTP request
userAgent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}",
# default headers in the HTTP request
defaultHeaders = NULL,
initialize = function(basePath, configuration, defaultHeaders){
if (!missing(basePath)) {
self$basePath <- basePath
}
# 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 (!missing(configuration)) {
self$configuration <- configuration
}
if (!is.null(defaultHeaders)) {
self$defaultHeaders <- defaultHeaders
}
if (!missing(defaultHeaders)) {
self$defaultHeaders <- defaultHeaders
}
if (!is.null(username)) {
self$username <- username
}
self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}'
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))
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`.")
}
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,4 +1,4 @@
# {{invokerPackage}}\{{classname}}{{#description}}
# {{classname}}{{#description}}
{{description}}{{/description}}
All URIs are relative to *{{basePath}}*
@@ -10,41 +10,71 @@ Method | HTTP request | Description
{{#operations}}
{{#operation}}
# **{{{operationId}}}**
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#authMethods}}ctx, {{/authMethods}}{{#allParams}}{{#required}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}optional{{/hasOptionalParams}})
# **{{operationId}}**
> {{#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}}
{{{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}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{#authMethods}}
**ctx** | **context.Context** | context containing the authentication | nil if no authentication{{/authMethods}}{{/-last}}{{/allParams}}{{#allParams}}{{#required}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
### 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}}
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#requiredParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/requiredParams}}
{{#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}}
### 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
{{^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
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **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}}
{{/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
LazyData: true
Suggests: testthat
Imports: jsonlite, httr, R6
Imports: jsonlite, httr, R6, caTools
RoxygenNote: 6.0.1.9000

View File

@@ -17,48 +17,90 @@
{{#vars}}
`{{{baseName}}}` = NULL,
{{/vars}}
initialize = function({{#vars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/vars}}){
{{#vars}}
initialize = function({{#requiredVars}}`{{baseName}}`{{#hasMore}}, {{/hasMore}}{{/requiredVars}}{{#optionalVars}}{{#-first}}{{#requiredVars.0}}, {{/requiredVars.0}}{{/-first}}`{{baseName}}`={{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}NULL{{/defaultValue}}{{^-last}}, {{/-last}}{{/optionalVars}}, ...){
local.optional.var <- list(...)
{{#requiredVars}}
if (!missing(`{{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}}
{{#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}}
{{#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}}`
}
{{/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() {
{{classname}}Object <- list()
@@ -66,20 +108,20 @@
if (!is.null(self$`{{baseName}}`)) {
{{classname}}Object[['{{baseName}}']] <-
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
sapply(self$`{{baseName}}`, function(x) x$toJSON())
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
sapply(self$`{{baseName}}`, function(x) x$toJSON())
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON()
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON()
{{/isPrimitiveType}}
{{/isListContainer}}
}
{{/vars}}
@@ -91,94 +133,100 @@
{{#vars}}
if (!is.null({{classname}}Object$`{{baseName}}`)) {
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
{{baseName}}Object
})
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
{{baseName}}Object
})
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
self$`{{baseName}}` <- {{baseName}}Object
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
self$`{{baseName}}` <- {{baseName}}Object
{{/isPrimitiveType}}
{{/isListContainer}}
}
{{/vars}}
},
toJSONString = function() {
outstring <- sprintf(
sprintf(
'{
{{#vars}}
"{{baseName}}":
{{#isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}[%d]{{/isNumeric}}
{{^isNumeric}}["%s"]{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}["%s"]{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}%d{{/isNumeric}}
{{^isNumeric}}"%s"{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}"%s"{{/isPrimitiveType}}
{{/isListContainer}}
{{#hasMore}},{{/hasMore}}
{{#isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}}{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
[%s]{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}}{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
%s{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{/vars}}
}',
{{#vars}}
{{#isListContainer}}
{{#isPrimitiveType}}
paste0(self$`{{baseName}}`, collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
paste0(sapply(self$`{{baseName}}`, function(x) x$toJSON()), collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=","){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
paste(unlist(lapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON(){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}`{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{/isListContainer}}
{{/vars}}
)
gsub("[\r\n]| ", "", outstring)
},
fromJSONString = function({{classname}}Json) {
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}}
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}` <- sapply({{classname}}Object$`{{baseName}}`, function(x) {{dataType}}$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function (x) x)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
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}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{dataType}}Object <- {{dataType}}$new()
self$`{{baseName}}` <- {{dataType}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
{{/isPrimitiveType}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
{{/isPrimitiveType}}
{{/isListContainer}}
{{/vars}}
self
}
)
)

View File

@@ -1,11 +1,9 @@
{{#models}}{{#model}}# {{classname}}
{{#models}}{{#model}}# {{packageName}}::{{classname}}
## Properties
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}}
[[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}}

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}}}")