Bugfix/rheaders (#1965)

* debug headers in R client

* fixes to R client

* petstore samples

* missing space

* other space :)
This commit is contained in:
Joke Durnez 2019-01-26 01:27:24 -08:00 committed by William Cheng
parent 9ec594eec5
commit 1a07bd6573
15 changed files with 495 additions and 333 deletions

View File

@ -74,37 +74,29 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
) )
); );
defaultIncludes = new HashSet<String>( languageSpecificPrimitives.clear();
Arrays.asList( languageSpecificPrimitives.add("integer");
"map", languageSpecificPrimitives.add("numeric");
"array") languageSpecificPrimitives.add("character");
); languageSpecificPrimitives.add("data.frame");
languageSpecificPrimitives.add("object");
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"Integer",
"Numeric",
"Character")
);
instantiationTypes.clear();
typeMapping.clear(); typeMapping.clear();
typeMapping.put("integer", "Integer"); typeMapping.put("integer", "integer");
typeMapping.put("long", "Integer"); typeMapping.put("long", "integer");
typeMapping.put("number", "Numeric"); typeMapping.put("number", "numeric");
typeMapping.put("float", "Numeric"); typeMapping.put("float", "numeric");
typeMapping.put("double", "Numeric"); typeMapping.put("double", "numeric");
typeMapping.put("boolean", "Character"); typeMapping.put("boolean", "character");
typeMapping.put("string", "Character"); typeMapping.put("string", "character");
typeMapping.put("UUID", "Character"); typeMapping.put("UUID", "character");
typeMapping.put("date", "Character"); typeMapping.put("date", "character");
typeMapping.put("DateTime", "Character"); typeMapping.put("DateTime", "character");
typeMapping.put("password", "Character"); typeMapping.put("password", "character");
typeMapping.put("file", "data.frame"); typeMapping.put("file", "data.frame");
typeMapping.put("binary", "data.frame"); typeMapping.put("binary", "data.frame");
typeMapping.put("ByteArray", "Character"); typeMapping.put("ByteArray", "character");
typeMapping.put("object", "object"); typeMapping.put("map", "object");
cliOptions.clear(); cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).") cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).")
@ -370,8 +362,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
protected boolean needToImport(String type) { protected boolean needToImport(String type) {
return !defaultIncludes.contains(type) return !languageSpecificPrimitives.contains(type);
&& !languageSpecificPrimitives.contains(type);
} }
public void setPackageName(String packageName) { public void setPackageName(String packageName) {

View File

@ -95,12 +95,17 @@
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
{{#returnType}} {{#returnType}}
returnObject <- {{returnType}}$new() {{#isPrimitiveType}}
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) returnObject <- {{returnType}}$new()
Response$new(returnObject, resp) result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
{{/returnType}} Response$new(returnObject, resp)
{{/isPrimitiveType}}
{{^isPrimitiveType}}
jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
{{/isPrimitiveType}}
{{/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) Response$new("API client error", resp)

View File

@ -36,19 +36,19 @@ ApiClient <- R6::R6Class(
self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}' self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}'
}, },
callApi = function(url, method, queryParams, headerParams, body, ...){ callApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(headerParams) 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, queryParams, headers, body = body, ...) httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "PUT") { else if (method == "PUT") {
httr::PUT(url, queryParams, headers, body = body, ...) httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "PATCH") { else if (method == "PATCH") {
httr::PATCH(url, queryParams, headers, body = body, ...) httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "HEAD") { else if (method == "HEAD") {
httr::HEAD(url, queryParams, headers, ...) httr::HEAD(url, queryParams, headers, ...)

View File

@ -21,40 +21,40 @@
{{#vars}} {{#vars}}
if (!missing(`{{baseName}}`)) { if (!missing(`{{baseName}}`)) {
{{^isListContainer}} {{^isListContainer}}
{{#isInteger}} {{#isInteger}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isInteger}} {{/isInteger}}
{{#isLong}} {{#isLong}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isLong}} {{/isLong}}
{{#isFloat}} {{#isFloat}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isFloat}} {{/isFloat}}
{{#isDouble}} {{#isDouble}}
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDouble}} {{/isDouble}}
{{#isString}} {{#isString}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isString}} {{/isString}}
{{#isDate}} {{#isDate}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDate}} {{/isDate}}
{{#isDateTime}} {{#isDateTime}}
stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1) stopifnot(is.character(`{{baseName}}`), length(`{{baseName}}`) == 1)
{{/isDateTime}} {{/isDateTime}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
stopifnot(R6::is.R6(`{{baseName}}`)) stopifnot(R6::is.R6(`{{baseName}}`))
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{#isListContainer}} {{#isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
stopifnot(is.list(`{{baseName}}`), length(`{{baseName}}`) != 0) stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
lapply(`{{baseName}}`, function(x) stopifnot(is.character(x))) sapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
stopifnot(is.list(`{{baseName}}`), length(`{{baseName}}`) != 0) stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
lapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x))) sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
self$`{{baseName}}` <- `{{baseName}}` self$`{{baseName}}` <- `{{baseName}}`
} }
@ -64,7 +64,23 @@
{{classname}}Object <- list() {{classname}}Object <- list()
{{#vars}} {{#vars}}
if (!is.null(self$`{{baseName}}`)) { if (!is.null(self$`{{baseName}}`)) {
{{classname}}Object[['{{baseName}}']] <- {{#isListContainer}}{{#isPrimitiveType}}self$`{{baseName}}`{{/isPrimitiveType}}{{^isPrimitiveType}}lapply(self$`{{baseName}}`, function(x) x$toJSON()){{/isPrimitiveType}}{{/isListContainer}}{{^isListContainer}}self$`{{baseName}}`{{^isPrimitiveType}}$toJSON(){{/isPrimitiveType}}{{/isListContainer}} {{classname}}Object[['{{baseName}}']] <-
{{#isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
sapply(self$`{{baseName}}`, function(x) x$toJSON())
{{/isPrimitiveType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isPrimitiveType}}
self$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON()
{{/isPrimitiveType}}
{{/isListContainer}}
} }
{{/vars}} {{/vars}}
@ -74,63 +90,94 @@
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
{{#vars}} {{#vars}}
if (!is.null({{classname}}Object$`{{baseName}}`)) { if (!is.null({{classname}}Object$`{{baseName}}`)) {
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}} {{#isListContainer}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) { {{#isPrimitiveType}}
{{baseName}}Object <- {{dataType}}$new() self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{baseName}}Object$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)) {{/isPrimitiveType}}
{{baseName}}Object {{^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}}
{{^isListContainer}} {{^isListContainer}}
{{baseName}}Object <- {{dataType}}$new() {{#isPrimitiveType}}
{{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE)) self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
self$`{{baseName}}` <- {{baseName}}Object {{/isPrimitiveType}}
{{^isPrimitiveType}}
{{baseName}}Object <- {{dataType}}$new()
{{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE))
self$`{{baseName}}` <- {{baseName}}Object
{{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{/isPrimitiveType}}
} }
{{/vars}} {{/vars}}
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
{{#vars}} {{#vars}}
"{{baseName}}": {{#isListContainer}}[{{/isListContainer}}{{#isPrimitiveType}}{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}%s{{/isNumeric}}{{/isPrimitiveType}}{{^isPrimitiveType}}%s{{/isPrimitiveType}}{{#isListContainer}}]{{/isListContainer}}{{#hasMore}},{{/hasMore}} "{{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}}
{{/vars}} {{/vars}}
}', }',
{{#vars}} {{#vars}}
{{#isListContainer}} {{#isListContainer}}
{{#isPrimitiveType}} {{#isPrimitiveType}}
lapply(self$`{{baseName}}`, function(x) paste(paste0('"', x, '"'), sep=",")){{#hasMore}},{{/hasMore}} paste0(self$`{{baseName}}`, collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
lapply(self$`{{baseName}}`, function(x) paste(x$toJSON(), sep=",")){{#hasMore}},{{/hasMore}} paste0(sapply(self$`{{baseName}}`, function(x) x$toJSON()), collapse='","'){{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
self$`{{baseName}}`{{^isPrimitiveType}}$toJSON(){{/isPrimitiveType}}{{#hasMore}},{{/hasMore}} {{#isPrimitiveType}}
self$`{{baseName}}`{{#hasMore}},{{/hasMore}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{baseName}}`$toJSON(){{#hasMore}},{{/hasMore}}
{{/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}}
{{#isPrimitiveType}}
self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}} {{#isListContainer}}
self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) {{dataType}}$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) {{#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}}
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
{{dataType}}Object <- {{dataType}}$new() {{#isPrimitiveType}}
self$`{{baseName}}` <- {{dataType}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE)) 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}}
{{/isListContainer}} {{/isListContainer}}
{{/isPrimitiveType}}
{{/vars}} {{/vars}}
} }
) )

View File

@ -1 +1 @@
3.0.0-SNAPSHOT 4.0.0-SNAPSHOT

View File

@ -43,19 +43,19 @@ ApiClient <- R6::R6Class(
self$`userAgent` <- 'OpenAPI-Generator/1.0.0/r' self$`userAgent` <- 'OpenAPI-Generator/1.0.0/r'
}, },
callApi = function(url, method, queryParams, headerParams, body, ...){ callApi = function(url, method, queryParams, headerParams, body, ...){
headers <- httr::add_headers(headerParams) 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, queryParams, headers, body = body, ...) httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "PUT") { else if (method == "PUT") {
httr::PUT(url, queryParams, headers, body = body, ...) httr::PUT(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "PATCH") { else if (method == "PATCH") {
httr::PATCH(url, queryParams, headers, body = body, ...) httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...)
} }
else if (method == "HEAD") { else if (method == "HEAD") {
httr::HEAD(url, queryParams, headers, ...) httr::HEAD(url, queryParams, headers, ...)

View File

@ -24,28 +24,31 @@ ApiResponse <- R6::R6Class(
`message` = NULL, `message` = NULL,
initialize = function(`code`, `type`, `message`){ initialize = function(`code`, `type`, `message`){
if (!missing(`code`)) { if (!missing(`code`)) {
stopifnot(is.numeric(`code`), length(`code`) == 1) stopifnot(is.numeric(`code`), length(`code`) == 1)
self$`code` <- `code` self$`code` <- `code`
} }
if (!missing(`type`)) { if (!missing(`type`)) {
stopifnot(is.character(`type`), length(`type`) == 1) stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type` self$`type` <- `type`
} }
if (!missing(`message`)) { if (!missing(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1) stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message` self$`message` <- `message`
} }
}, },
toJSON = function() { toJSON = function() {
ApiResponseObject <- list() ApiResponseObject <- list()
if (!is.null(self$`code`)) { if (!is.null(self$`code`)) {
ApiResponseObject[['code']] <- self$`code` ApiResponseObject[['code']] <-
self$`code`
} }
if (!is.null(self$`type`)) { if (!is.null(self$`type`)) {
ApiResponseObject[['type']] <- self$`type` ApiResponseObject[['type']] <-
self$`type`
} }
if (!is.null(self$`message`)) { if (!is.null(self$`message`)) {
ApiResponseObject[['message']] <- self$`message` ApiResponseObject[['message']] <-
self$`message`
} }
ApiResponseObject ApiResponseObject
@ -53,32 +56,45 @@ ApiResponse <- R6::R6Class(
fromJSON = function(ApiResponseJson) { fromJSON = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson) ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
if (!is.null(ApiResponseObject$`code`)) { if (!is.null(ApiResponseObject$`code`)) {
self$`code` <- ApiResponseObject$`code` self$`code` <- ApiResponseObject$`code`
} }
if (!is.null(ApiResponseObject$`type`)) { if (!is.null(ApiResponseObject$`type`)) {
self$`type` <- ApiResponseObject$`type` self$`type` <- ApiResponseObject$`type`
} }
if (!is.null(ApiResponseObject$`message`)) { if (!is.null(ApiResponseObject$`message`)) {
self$`message` <- ApiResponseObject$`message` self$`message` <- ApiResponseObject$`message`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"code": %d, "code":
"type": %s, %d
"message": %s
,
"type":
"%s"
,
"message":
"%s"
}', }',
self$`code`, self$`code`,
self$`type`, self$`type`,
self$`message` self$`message`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(ApiResponseJson) { fromJSONString = function(ApiResponseJson) {
ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson) ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson)
self$`code` <- ApiResponseObject$`code` self$`code` <- ApiResponseObject$`code`
self$`type` <- ApiResponseObject$`type` self$`type` <- ApiResponseObject$`type`
self$`message` <- ApiResponseObject$`message` self$`message` <- ApiResponseObject$`message`
} }
) )
) )

View File

@ -22,21 +22,23 @@ Category <- R6::R6Class(
`name` = NULL, `name` = NULL,
initialize = function(`id`, `name`){ initialize = function(`id`, `name`){
if (!missing(`id`)) { if (!missing(`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 (!missing(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1) stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name` self$`name` <- `name`
} }
}, },
toJSON = function() { toJSON = function() {
CategoryObject <- list() CategoryObject <- list()
if (!is.null(self$`id`)) { if (!is.null(self$`id`)) {
CategoryObject[['id']] <- self$`id` CategoryObject[['id']] <-
self$`id`
} }
if (!is.null(self$`name`)) { if (!is.null(self$`name`)) {
CategoryObject[['name']] <- self$`name` CategoryObject[['name']] <-
self$`name`
} }
CategoryObject CategoryObject
@ -44,26 +46,35 @@ Category <- R6::R6Class(
fromJSON = function(CategoryJson) { fromJSON = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson) CategoryObject <- jsonlite::fromJSON(CategoryJson)
if (!is.null(CategoryObject$`id`)) { if (!is.null(CategoryObject$`id`)) {
self$`id` <- CategoryObject$`id` self$`id` <- CategoryObject$`id`
} }
if (!is.null(CategoryObject$`name`)) { if (!is.null(CategoryObject$`name`)) {
self$`name` <- CategoryObject$`name` self$`name` <- CategoryObject$`name`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"id": %d, "id":
"name": %s %d
,
"name":
"%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`
} }
) )
) )

View File

@ -30,23 +30,23 @@ Order <- R6::R6Class(
`complete` = NULL, `complete` = NULL,
initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){ initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){
if (!missing(`id`)) { if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1) stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id` self$`id` <- `id`
} }
if (!missing(`petId`)) { if (!missing(`petId`)) {
stopifnot(is.numeric(`petId`), length(`petId`) == 1) stopifnot(is.numeric(`petId`), length(`petId`) == 1)
self$`petId` <- `petId` self$`petId` <- `petId`
} }
if (!missing(`quantity`)) { if (!missing(`quantity`)) {
stopifnot(is.numeric(`quantity`), length(`quantity`) == 1) stopifnot(is.numeric(`quantity`), length(`quantity`) == 1)
self$`quantity` <- `quantity` self$`quantity` <- `quantity`
} }
if (!missing(`shipDate`)) { if (!missing(`shipDate`)) {
stopifnot(is.character(`shipDate`), length(`shipDate`) == 1) stopifnot(is.character(`shipDate`), length(`shipDate`) == 1)
self$`shipDate` <- `shipDate` self$`shipDate` <- `shipDate`
} }
if (!missing(`status`)) { if (!missing(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1) stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status` self$`status` <- `status`
} }
if (!missing(`complete`)) { if (!missing(`complete`)) {
@ -56,22 +56,28 @@ Order <- R6::R6Class(
toJSON = function() { toJSON = function() {
OrderObject <- list() OrderObject <- list()
if (!is.null(self$`id`)) { if (!is.null(self$`id`)) {
OrderObject[['id']] <- self$`id` OrderObject[['id']] <-
self$`id`
} }
if (!is.null(self$`petId`)) { if (!is.null(self$`petId`)) {
OrderObject[['petId']] <- self$`petId` OrderObject[['petId']] <-
self$`petId`
} }
if (!is.null(self$`quantity`)) { if (!is.null(self$`quantity`)) {
OrderObject[['quantity']] <- self$`quantity` OrderObject[['quantity']] <-
self$`quantity`
} }
if (!is.null(self$`shipDate`)) { if (!is.null(self$`shipDate`)) {
OrderObject[['shipDate']] <- self$`shipDate` OrderObject[['shipDate']] <-
self$`shipDate`
} }
if (!is.null(self$`status`)) { if (!is.null(self$`status`)) {
OrderObject[['status']] <- self$`status` OrderObject[['status']] <-
self$`status`
} }
if (!is.null(self$`complete`)) { if (!is.null(self$`complete`)) {
OrderObject[['complete']] <- self$`complete` OrderObject[['complete']] <-
self$`complete`
} }
OrderObject OrderObject
@ -79,50 +85,75 @@ Order <- R6::R6Class(
fromJSON = function(OrderJson) { fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson) OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) { if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id` self$`id` <- OrderObject$`id`
} }
if (!is.null(OrderObject$`petId`)) { if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId` self$`petId` <- OrderObject$`petId`
} }
if (!is.null(OrderObject$`quantity`)) { if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity` self$`quantity` <- OrderObject$`quantity`
} }
if (!is.null(OrderObject$`shipDate`)) { if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate` self$`shipDate` <- OrderObject$`shipDate`
} }
if (!is.null(OrderObject$`status`)) { if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status` self$`status` <- OrderObject$`status`
} }
if (!is.null(OrderObject$`complete`)) { if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete` self$`complete` <- OrderObject$`complete`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"id": %d, "id":
"petId": %d, %d
"quantity": %d,
"shipDate": %s,
"status": %s, ,
"complete": %s "petId":
%d
,
"quantity":
%d
,
"shipDate":
"%s"
,
"status":
"%s"
,
"complete":
"%s"
}', }',
self$`id`, self$`id`,
self$`petId`, self$`petId`,
self$`quantity`, self$`quantity`,
self$`shipDate`, self$`shipDate`,
self$`status`, self$`status`,
self$`complete` self$`complete`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(OrderJson) { fromJSONString = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson) OrderObject <- jsonlite::fromJSON(OrderJson)
self$`id` <- OrderObject$`id` self$`id` <- OrderObject$`id`
self$`petId` <- OrderObject$`petId` self$`petId` <- OrderObject$`petId`
self$`quantity` <- OrderObject$`quantity` self$`quantity` <- OrderObject$`quantity`
self$`shipDate` <- OrderObject$`shipDate` self$`shipDate` <- OrderObject$`shipDate`
self$`status` <- OrderObject$`status` self$`status` <- OrderObject$`status`
self$`complete` <- OrderObject$`complete` self$`complete` <- OrderObject$`complete`
} }
) )
) )

View File

@ -57,13 +57,13 @@ PetApi <- R6::R6Class(
self$apiClient <- ApiClient$new() self$apiClient <- ApiClient$new()
} }
}, },
add_pet = function(pet, ...){ add_pet = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`pet`)) { if (!missing(`body`)) {
body <- `pet`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -133,9 +133,7 @@ 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) {
returnObject <- Pet$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -161,9 +159,7 @@ 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) {
returnObject <- Pet$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -189,9 +185,7 @@ 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) {
returnObject <- Pet$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -199,13 +193,13 @@ PetApi <- R6::R6Class(
} }
}, },
update_pet = function(pet, ...){ update_pet = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`pet`)) { if (!missing(`body`)) {
body <- `pet`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -281,9 +275,7 @@ 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) {
returnObject <- ApiResponse$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -85,9 +85,7 @@ 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) {
returnObject <- Integer$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -113,9 +111,7 @@ 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) {
returnObject <- Order$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -123,13 +119,13 @@ StoreApi <- R6::R6Class(
} }
}, },
place_order = function(order, ...){ place_order = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`order`)) { if (!missing(`body`)) {
body <- `order`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -143,9 +139,7 @@ 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) {
returnObject <- Order$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$new("API client error", resp)
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

View File

@ -22,21 +22,23 @@ Tag <- R6::R6Class(
`name` = NULL, `name` = NULL,
initialize = function(`id`, `name`){ initialize = function(`id`, `name`){
if (!missing(`id`)) { if (!missing(`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 (!missing(`name`)) {
stopifnot(is.character(`name`), length(`name`) == 1) stopifnot(is.character(`name`), length(`name`) == 1)
self$`name` <- `name` self$`name` <- `name`
} }
}, },
toJSON = function() { toJSON = function() {
TagObject <- list() TagObject <- list()
if (!is.null(self$`id`)) { if (!is.null(self$`id`)) {
TagObject[['id']] <- self$`id` TagObject[['id']] <-
self$`id`
} }
if (!is.null(self$`name`)) { if (!is.null(self$`name`)) {
TagObject[['name']] <- self$`name` TagObject[['name']] <-
self$`name`
} }
TagObject TagObject
@ -44,26 +46,35 @@ Tag <- R6::R6Class(
fromJSON = function(TagJson) { fromJSON = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson) TagObject <- jsonlite::fromJSON(TagJson)
if (!is.null(TagObject$`id`)) { if (!is.null(TagObject$`id`)) {
self$`id` <- TagObject$`id` self$`id` <- TagObject$`id`
} }
if (!is.null(TagObject$`name`)) { if (!is.null(TagObject$`name`)) {
self$`name` <- TagObject$`name` self$`name` <- TagObject$`name`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"id": %d, "id":
"name": %s %d
,
"name":
"%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`
} }
) )
) )

View File

@ -34,63 +34,71 @@ User <- R6::R6Class(
`userStatus` = NULL, `userStatus` = NULL,
initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){ initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){
if (!missing(`id`)) { if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1) stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id` self$`id` <- `id`
} }
if (!missing(`username`)) { if (!missing(`username`)) {
stopifnot(is.character(`username`), length(`username`) == 1) stopifnot(is.character(`username`), length(`username`) == 1)
self$`username` <- `username` self$`username` <- `username`
} }
if (!missing(`firstName`)) { if (!missing(`firstName`)) {
stopifnot(is.character(`firstName`), length(`firstName`) == 1) stopifnot(is.character(`firstName`), length(`firstName`) == 1)
self$`firstName` <- `firstName` self$`firstName` <- `firstName`
} }
if (!missing(`lastName`)) { if (!missing(`lastName`)) {
stopifnot(is.character(`lastName`), length(`lastName`) == 1) stopifnot(is.character(`lastName`), length(`lastName`) == 1)
self$`lastName` <- `lastName` self$`lastName` <- `lastName`
} }
if (!missing(`email`)) { if (!missing(`email`)) {
stopifnot(is.character(`email`), length(`email`) == 1) stopifnot(is.character(`email`), length(`email`) == 1)
self$`email` <- `email` self$`email` <- `email`
} }
if (!missing(`password`)) { if (!missing(`password`)) {
stopifnot(is.character(`password`), length(`password`) == 1) stopifnot(is.character(`password`), length(`password`) == 1)
self$`password` <- `password` self$`password` <- `password`
} }
if (!missing(`phone`)) { if (!missing(`phone`)) {
stopifnot(is.character(`phone`), length(`phone`) == 1) stopifnot(is.character(`phone`), length(`phone`) == 1)
self$`phone` <- `phone` self$`phone` <- `phone`
} }
if (!missing(`userStatus`)) { if (!missing(`userStatus`)) {
stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1) stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1)
self$`userStatus` <- `userStatus` self$`userStatus` <- `userStatus`
} }
}, },
toJSON = function() { toJSON = function() {
UserObject <- list() UserObject <- list()
if (!is.null(self$`id`)) { if (!is.null(self$`id`)) {
UserObject[['id']] <- self$`id` UserObject[['id']] <-
self$`id`
} }
if (!is.null(self$`username`)) { if (!is.null(self$`username`)) {
UserObject[['username']] <- self$`username` UserObject[['username']] <-
self$`username`
} }
if (!is.null(self$`firstName`)) { if (!is.null(self$`firstName`)) {
UserObject[['firstName']] <- self$`firstName` UserObject[['firstName']] <-
self$`firstName`
} }
if (!is.null(self$`lastName`)) { if (!is.null(self$`lastName`)) {
UserObject[['lastName']] <- self$`lastName` UserObject[['lastName']] <-
self$`lastName`
} }
if (!is.null(self$`email`)) { if (!is.null(self$`email`)) {
UserObject[['email']] <- self$`email` UserObject[['email']] <-
self$`email`
} }
if (!is.null(self$`password`)) { if (!is.null(self$`password`)) {
UserObject[['password']] <- self$`password` UserObject[['password']] <-
self$`password`
} }
if (!is.null(self$`phone`)) { if (!is.null(self$`phone`)) {
UserObject[['phone']] <- self$`phone` UserObject[['phone']] <-
self$`phone`
} }
if (!is.null(self$`userStatus`)) { if (!is.null(self$`userStatus`)) {
UserObject[['userStatus']] <- self$`userStatus` UserObject[['userStatus']] <-
self$`userStatus`
} }
UserObject UserObject
@ -98,62 +106,95 @@ User <- R6::R6Class(
fromJSON = function(UserJson) { fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson) UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) { if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id` self$`id` <- UserObject$`id`
} }
if (!is.null(UserObject$`username`)) { if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username` self$`username` <- UserObject$`username`
} }
if (!is.null(UserObject$`firstName`)) { if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName` self$`firstName` <- UserObject$`firstName`
} }
if (!is.null(UserObject$`lastName`)) { if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName` self$`lastName` <- UserObject$`lastName`
} }
if (!is.null(UserObject$`email`)) { if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email` self$`email` <- UserObject$`email`
} }
if (!is.null(UserObject$`password`)) { if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password` self$`password` <- UserObject$`password`
} }
if (!is.null(UserObject$`phone`)) { if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone` self$`phone` <- UserObject$`phone`
} }
if (!is.null(UserObject$`userStatus`)) { if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus` self$`userStatus` <- UserObject$`userStatus`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"id": %d, "id":
"username": %s, %d
"firstName": %s,
"lastName": %s,
"email": %s, ,
"password": %s, "username":
"phone": %s,
"userStatus": %d "%s"
,
"firstName":
"%s"
,
"lastName":
"%s"
,
"email":
"%s"
,
"password":
"%s"
,
"phone":
"%s"
,
"userStatus":
%d
}', }',
self$`id`, self$`id`,
self$`username`, self$`username`,
self$`firstName`, self$`firstName`,
self$`lastName`, self$`lastName`,
self$`email`, self$`email`,
self$`password`, self$`password`,
self$`phone`, self$`phone`,
self$`userStatus` self$`userStatus`
) )
gsub("[\r\n]| ", "", outstring)
}, },
fromJSONString = function(UserJson) { fromJSONString = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson) UserObject <- jsonlite::fromJSON(UserJson)
self$`id` <- UserObject$`id` self$`id` <- UserObject$`id`
self$`username` <- UserObject$`username` self$`username` <- UserObject$`username`
self$`firstName` <- UserObject$`firstName` self$`firstName` <- UserObject$`firstName`
self$`lastName` <- UserObject$`lastName` self$`lastName` <- UserObject$`lastName`
self$`email` <- UserObject$`email` self$`email` <- UserObject$`email`
self$`password` <- UserObject$`password` self$`password` <- UserObject$`password`
self$`phone` <- UserObject$`phone` self$`phone` <- UserObject$`phone`
self$`userStatus` <- UserObject$`userStatus` self$`userStatus` <- UserObject$`userStatus`
} }
) )
) )

View File

@ -57,13 +57,13 @@ UserApi <- R6::R6Class(
self$apiClient <- ApiClient$new() self$apiClient <- ApiClient$new()
} }
}, },
create_user = function(user, ...){ create_user = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`user`)) { if (!missing(`body`)) {
body <- `user`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -85,13 +85,13 @@ UserApi <- R6::R6Class(
} }
}, },
create_users_with_array_input = function(user, ...){ create_users_with_array_input = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`user`)) { if (!missing(`body`)) {
body <- `user`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -113,13 +113,13 @@ UserApi <- R6::R6Class(
} }
}, },
create_users_with_list_input = function(user, ...){ create_users_with_list_input = function(body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`user`)) { if (!missing(`body`)) {
body <- `user`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }
@ -185,9 +185,7 @@ 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) {
returnObject <- User$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -217,9 +215,7 @@ 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) {
returnObject <- Character$new() jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
Response$new(returnObject, resp)
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
Response$new("API client error", resp) Response$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) {
@ -249,13 +245,13 @@ UserApi <- R6::R6Class(
} }
}, },
update_user = function(username, user, ...){ update_user = function(username, body, ...){
args <- list(...) args <- list(...)
queryParams <- list() queryParams <- list()
headerParams <- character() headerParams <- character()
if (!missing(`user`)) { if (!missing(`body`)) {
body <- `user`$toJSONString() body <- `body`$toJSONString()
} else { } else {
body <- NULL body <- NULL
} }

View File

@ -30,51 +30,57 @@ Pet <- R6::R6Class(
`status` = NULL, `status` = NULL,
initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){ initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){
if (!missing(`id`)) { if (!missing(`id`)) {
stopifnot(is.numeric(`id`), length(`id`) == 1) stopifnot(is.numeric(`id`), length(`id`) == 1)
self$`id` <- `id` self$`id` <- `id`
} }
if (!missing(`category`)) { if (!missing(`category`)) {
stopifnot(R6::is.R6(`category`)) stopifnot(R6::is.R6(`category`))
self$`category` <- `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`
} }
if (!missing(`photoUrls`)) { if (!missing(`photoUrls`)) {
stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0) stopifnot(is.vector(`photoUrls`), length(`photoUrls`) != 0)
lapply(`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 (!missing(`tags`)) {
stopifnot(is.list(`tags`), length(`tags`) != 0) stopifnot(is.vector(`tags`), length(`tags`) != 0)
lapply(`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 (!missing(`status`)) {
stopifnot(is.character(`status`), length(`status`) == 1) stopifnot(is.character(`status`), length(`status`) == 1)
self$`status` <- `status` self$`status` <- `status`
} }
}, },
toJSON = function() { toJSON = function() {
PetObject <- list() PetObject <- list()
if (!is.null(self$`id`)) { if (!is.null(self$`id`)) {
PetObject[['id']] <- self$`id` PetObject[['id']] <-
self$`id`
} }
if (!is.null(self$`category`)) { if (!is.null(self$`category`)) {
PetObject[['category']] <- self$`category`$toJSON() PetObject[['category']] <-
self$`category`$toJSON()
} }
if (!is.null(self$`name`)) { if (!is.null(self$`name`)) {
PetObject[['name']] <- self$`name` PetObject[['name']] <-
self$`name`
} }
if (!is.null(self$`photoUrls`)) { if (!is.null(self$`photoUrls`)) {
PetObject[['photoUrls']] <- self$`photoUrls` PetObject[['photoUrls']] <-
self$`photoUrls`
} }
if (!is.null(self$`tags`)) { if (!is.null(self$`tags`)) {
PetObject[['tags']] <- lapply(self$`tags`, function(x) x$toJSON()) PetObject[['tags']] <-
sapply(self$`tags`, function(x) x$toJSON())
} }
if (!is.null(self$`status`)) { if (!is.null(self$`status`)) {
PetObject[['status']] <- self$`status` PetObject[['status']] <-
self$`status`
} }
PetObject PetObject
@ -82,57 +88,78 @@ Pet <- R6::R6Class(
fromJSON = function(PetJson) { fromJSON = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson) PetObject <- jsonlite::fromJSON(PetJson)
if (!is.null(PetObject$`id`)) { if (!is.null(PetObject$`id`)) {
self$`id` <- PetObject$`id` self$`id` <- PetObject$`id`
} }
if (!is.null(PetObject$`category`)) { if (!is.null(PetObject$`category`)) {
categoryObject <- Category$new() categoryObject <- Category$new()
categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE)) categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE))
self$`category` <- categoryObject self$`category` <- categoryObject
} }
if (!is.null(PetObject$`name`)) { if (!is.null(PetObject$`name`)) {
self$`name` <- PetObject$`name` self$`name` <- PetObject$`name`
} }
if (!is.null(PetObject$`photoUrls`)) { if (!is.null(PetObject$`photoUrls`)) {
self$`photoUrls` <- PetObject$`photoUrls` self$`photoUrls` <- PetObject$`photoUrls`
} }
if (!is.null(PetObject$`tags`)) { if (!is.null(PetObject$`tags`)) {
self$`tags` <- lapply(PetObject$`tags`, function(x) { self$`tags` <- sapply(PetObject$`tags`, function(x) {
tagsObject <- Tag$new() tagsObject <- Tag$new()
tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)) tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
tagsObject tagsObject
}) })
} }
if (!is.null(PetObject$`status`)) { if (!is.null(PetObject$`status`)) {
self$`status` <- PetObject$`status` self$`status` <- PetObject$`status`
} }
}, },
toJSONString = function() { toJSONString = function() {
sprintf( outstring <- sprintf(
'{ '{
"id": %d, "id":
"category": %s, %d
"name": %s,
"photoUrls": [%s],
"tags": [%s], ,
"status": %s "category":
"%s"
,
"name":
"%s"
,
"photoUrls":
["%s"]
,
"tags":
["%s"]
,
"status":
"%s"
}', }',
self$`id`, self$`id`,
self$`category`$toJSON(), self$`category`$toJSON(),
self$`name`, self$`name`,
lapply(self$`photoUrls`, function(x) paste(paste0('"', x, '"'), sep=",")), paste0(self$`photoUrls`, collapse='","'),
lapply(self$`tags`, function(x) paste(x$toJSON(), sep=",")), paste0(sapply(self$`tags`, function(x) x$toJSON()), 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() CategoryObject <- Category$new()
self$`category` <- CategoryObject$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` <- PetObject$`photoUrls`
self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) self$`tags` <- sapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
self$`status` <- PetObject$`status` self$`status` <- PetObject$`status`
} }
) )
) )