From 1a07bd65732ffb8dda40adf4d78f4873ab9f9c3b Mon Sep 17 00:00:00 2001 From: Joke Durnez Date: Sat, 26 Jan 2019 01:27:24 -0800 Subject: [PATCH] Bugfix/rheaders (#1965) * debug headers in R client * fixes to R client * petstore samples * missing space * other space :) --- .../codegen/languages/RClientCodegen.java | 49 ++--- .../src/main/resources/r/api.mustache | 17 +- .../src/main/resources/r/api_client.mustache | 10 +- .../src/main/resources/r/model.mustache | 173 +++++++++++------- .../petstore/R/.openapi-generator/VERSION | 2 +- samples/client/petstore/R/R/ApiClient.r | 10 +- samples/client/petstore/R/R/ApiResponse.r | 54 ++++-- samples/client/petstore/R/R/Category.r | 37 ++-- samples/client/petstore/R/R/Order.r | 103 +++++++---- samples/client/petstore/R/R/PetApi.r | 28 +-- samples/client/petstore/R/R/StoreApi.r | 18 +- samples/client/petstore/R/R/Tag.r | 37 ++-- samples/client/petstore/R/R/User.r | 139 +++++++++----- samples/client/petstore/R/R/UserApi.r | 32 ++-- samples/client/petstore/R/R/pet.R | 119 +++++++----- 15 files changed, 495 insertions(+), 333 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 4c4dd0ae78b..e262415f018 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -74,37 +74,29 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { ) ); - defaultIncludes = new HashSet( - Arrays.asList( - "map", - "array") - ); - - languageSpecificPrimitives = new HashSet( - Arrays.asList( - "Integer", - "Numeric", - "Character") - ); - - instantiationTypes.clear(); + languageSpecificPrimitives.clear(); + languageSpecificPrimitives.add("integer"); + languageSpecificPrimitives.add("numeric"); + languageSpecificPrimitives.add("character"); + languageSpecificPrimitives.add("data.frame"); + languageSpecificPrimitives.add("object"); typeMapping.clear(); - typeMapping.put("integer", "Integer"); - typeMapping.put("long", "Integer"); - typeMapping.put("number", "Numeric"); - typeMapping.put("float", "Numeric"); - typeMapping.put("double", "Numeric"); - typeMapping.put("boolean", "Character"); - typeMapping.put("string", "Character"); - typeMapping.put("UUID", "Character"); - typeMapping.put("date", "Character"); - typeMapping.put("DateTime", "Character"); - typeMapping.put("password", "Character"); + typeMapping.put("integer", "integer"); + typeMapping.put("long", "integer"); + typeMapping.put("number", "numeric"); + typeMapping.put("float", "numeric"); + typeMapping.put("double", "numeric"); + typeMapping.put("boolean", "character"); + typeMapping.put("string", "character"); + typeMapping.put("UUID", "character"); + typeMapping.put("date", "character"); + typeMapping.put("DateTime", "character"); + typeMapping.put("password", "character"); typeMapping.put("file", "data.frame"); typeMapping.put("binary", "data.frame"); - typeMapping.put("ByteArray", "Character"); - typeMapping.put("object", "object"); + typeMapping.put("ByteArray", "character"); + typeMapping.put("map", "object"); cliOptions.clear(); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "R package name (convention: lowercase).") @@ -370,8 +362,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override protected boolean needToImport(String type) { - return !defaultIncludes.contains(type) - && !languageSpecificPrimitives.contains(type); + return !languageSpecificPrimitives.contains(type); } public void setPackageName(String packageName) { diff --git a/modules/openapi-generator/src/main/resources/r/api.mustache b/modules/openapi-generator/src/main/resources/r/api.mustache index e8939377886..792c735af0b 100644 --- a/modules/openapi-generator/src/main/resources/r/api.mustache +++ b/modules/openapi-generator/src/main/resources/r/api.mustache @@ -92,15 +92,20 @@ headerParams = headerParams, body = body, ...) - + if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { {{#returnType}} - returnObject <- {{returnType}}$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) - {{/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}} {{^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) diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index 9fb8a7be662..9cbf157f277 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -36,19 +36,19 @@ ApiClient <- R6::R6Class( self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/r{{/httpUserAgent}}' }, callApi = function(url, method, queryParams, headerParams, body, ...){ - headers <- httr::add_headers(headerParams) + 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, ...) + httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...) } 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") { - httr::PATCH(url, queryParams, headers, body = body, ...) + httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...) } else if (method == "HEAD") { httr::HEAD(url, queryParams, headers, ...) @@ -61,4 +61,4 @@ ApiClient <- R6::R6Class( } } ) -) \ No newline at end of file +) diff --git a/modules/openapi-generator/src/main/resources/r/model.mustache b/modules/openapi-generator/src/main/resources/r/model.mustache index a1327b91f42..4f2248cfc7c 100644 --- a/modules/openapi-generator/src/main/resources/r/model.mustache +++ b/modules/openapi-generator/src/main/resources/r/model.mustache @@ -21,40 +21,40 @@ {{#vars}} 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.list(`{{baseName}}`), length(`{{baseName}}`) != 0) - lapply(`{{baseName}}`, function(x) stopifnot(is.character(x))) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - stopifnot(is.list(`{{baseName}}`), length(`{{baseName}}`) != 0) - lapply(`{{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}}` } @@ -64,7 +64,23 @@ {{classname}}Object <- list() {{#vars}} 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}} @@ -74,63 +90,94 @@ {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} if (!is.null({{classname}}Object$`{{baseName}}`)) { - {{#isPrimitiveType}} - self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}` - {{/isPrimitiveType}} - {{^isPrimitiveType}} {{#isListContainer}} - self$`{{baseName}}` <- lapply({{classname}}Object$`{{baseName}}`, function(x) { - {{baseName}}Object <- {{dataType}}$new() - {{baseName}}Object$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)) - {{baseName}}Object - }) + {{#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}} - {{baseName}}Object <- {{dataType}}$new() - {{baseName}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE)) - self$`{{baseName}}` <- {{baseName}}Object + {{#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}} - {{/isPrimitiveType}} } {{/vars}} }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ {{#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}} {{#isListContainer}} - {{#isPrimitiveType}} - lapply(self$`{{baseName}}`, function(x) paste(paste0('"', x, '"'), sep=",")){{#hasMore}},{{/hasMore}} - {{/isPrimitiveType}} - {{^isPrimitiveType}} - lapply(self$`{{baseName}}`, function(x) paste(x$toJSON(), sep=",")){{#hasMore}},{{/hasMore}} - {{/isPrimitiveType}} + {{#isPrimitiveType}} + paste0(self$`{{baseName}}`, collapse='","'){{#hasMore}},{{/hasMore}} + {{/isPrimitiveType}} + {{^isPrimitiveType}} + paste0(sapply(self$`{{baseName}}`, function(x) x$toJSON()), collapse='","'){{#hasMore}},{{/hasMore}} + {{/isPrimitiveType}} {{/isListContainer}} {{^isListContainer}} - self$`{{baseName}}`{{^isPrimitiveType}}$toJSON(){{/isPrimitiveType}}{{#hasMore}},{{/hasMore}} + {{#isPrimitiveType}} + self$`{{baseName}}`{{#hasMore}},{{/hasMore}} + {{/isPrimitiveType}} + {{^isPrimitiveType}} + self$`{{baseName}}`$toJSON(){{#hasMore}},{{/hasMore}} + {{/isPrimitiveType}} {{/isListContainer}} {{/vars}} ) + gsub("[\r\n]| ", "", outstring) }, fromJSONString = function({{classname}}Json) { {{classname}}Object <- jsonlite::fromJSON({{classname}}Json) {{#vars}} - {{#isPrimitiveType}} - self$`{{baseName}}` <- {{classname}}Object$`{{baseName}}` - {{/isPrimitiveType}} - {{^isPrimitiveType}} {{#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}} - {{dataType}}Object <- {{dataType}}$new() - self$`{{baseName}}` <- {{dataType}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE)) + {{#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}} {{/isListContainer}} - {{/isPrimitiveType}} {{/vars}} } ) diff --git a/samples/client/petstore/R/.openapi-generator/VERSION b/samples/client/petstore/R/.openapi-generator/VERSION index 096bf47efe3..afa63656064 100644 --- a/samples/client/petstore/R/.openapi-generator/VERSION +++ b/samples/client/petstore/R/.openapi-generator/VERSION @@ -1 +1 @@ -3.0.0-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/R/R/ApiClient.r b/samples/client/petstore/R/R/ApiClient.r index 0ddd91ee062..10d9af5f692 100644 --- a/samples/client/petstore/R/R/ApiClient.r +++ b/samples/client/petstore/R/R/ApiClient.r @@ -43,19 +43,19 @@ ApiClient <- R6::R6Class( self$`userAgent` <- 'OpenAPI-Generator/1.0.0/r' }, callApi = function(url, method, queryParams, headerParams, body, ...){ - headers <- httr::add_headers(headerParams) + 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, ...) + httr::POST(url, queryParams, headers, body = body, content_type("application/json"), ...) } 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") { - httr::PATCH(url, queryParams, headers, body = body, ...) + httr::PATCH(url, queryParams, headers, body = body, content_type("application/json"), ...) } else if (method == "HEAD") { httr::HEAD(url, queryParams, headers, ...) @@ -68,4 +68,4 @@ ApiClient <- R6::R6Class( } } ) -) \ No newline at end of file +) diff --git a/samples/client/petstore/R/R/ApiResponse.r b/samples/client/petstore/R/R/ApiResponse.r index db3be3b1b2d..15375351bf6 100644 --- a/samples/client/petstore/R/R/ApiResponse.r +++ b/samples/client/petstore/R/R/ApiResponse.r @@ -24,28 +24,31 @@ ApiResponse <- R6::R6Class( `message` = NULL, initialize = function(`code`, `type`, `message`){ if (!missing(`code`)) { - stopifnot(is.numeric(`code`), length(`code`) == 1) + stopifnot(is.numeric(`code`), length(`code`) == 1) self$`code` <- `code` } if (!missing(`type`)) { - stopifnot(is.character(`type`), length(`type`) == 1) + stopifnot(is.character(`type`), length(`type`) == 1) self$`type` <- `type` } if (!missing(`message`)) { - stopifnot(is.character(`message`), length(`message`) == 1) + stopifnot(is.character(`message`), length(`message`) == 1) self$`message` <- `message` } }, toJSON = function() { ApiResponseObject <- list() if (!is.null(self$`code`)) { - ApiResponseObject[['code']] <- self$`code` + ApiResponseObject[['code']] <- + self$`code` } if (!is.null(self$`type`)) { - ApiResponseObject[['type']] <- self$`type` + ApiResponseObject[['type']] <- + self$`type` } if (!is.null(self$`message`)) { - ApiResponseObject[['message']] <- self$`message` + ApiResponseObject[['message']] <- + self$`message` } ApiResponseObject @@ -53,32 +56,45 @@ ApiResponse <- R6::R6Class( fromJSON = function(ApiResponseJson) { ApiResponseObject <- jsonlite::fromJSON(ApiResponseJson) if (!is.null(ApiResponseObject$`code`)) { - self$`code` <- ApiResponseObject$`code` + self$`code` <- ApiResponseObject$`code` } if (!is.null(ApiResponseObject$`type`)) { - self$`type` <- ApiResponseObject$`type` + self$`type` <- ApiResponseObject$`type` } if (!is.null(ApiResponseObject$`message`)) { - self$`message` <- ApiResponseObject$`message` + self$`message` <- ApiResponseObject$`message` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "code": %d, - "type": %s, - "message": %s + "code": + %d + + + , + "type": + + "%s" + + , + "message": + + "%s" + + }', - self$`code`, - self$`type`, - self$`message` + 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` + self$`code` <- ApiResponseObject$`code` + self$`type` <- ApiResponseObject$`type` + self$`message` <- ApiResponseObject$`message` } ) ) diff --git a/samples/client/petstore/R/R/Category.r b/samples/client/petstore/R/R/Category.r index c1ea3523d7b..88b9c0734e2 100644 --- a/samples/client/petstore/R/R/Category.r +++ b/samples/client/petstore/R/R/Category.r @@ -22,21 +22,23 @@ Category <- R6::R6Class( `name` = NULL, initialize = function(`id`, `name`){ if (!missing(`id`)) { - stopifnot(is.numeric(`id`), length(`id`) == 1) + stopifnot(is.numeric(`id`), length(`id`) == 1) self$`id` <- `id` } if (!missing(`name`)) { - stopifnot(is.character(`name`), length(`name`) == 1) + stopifnot(is.character(`name`), length(`name`) == 1) self$`name` <- `name` } }, toJSON = function() { CategoryObject <- list() if (!is.null(self$`id`)) { - CategoryObject[['id']] <- self$`id` + CategoryObject[['id']] <- + self$`id` } if (!is.null(self$`name`)) { - CategoryObject[['name']] <- self$`name` + CategoryObject[['name']] <- + self$`name` } CategoryObject @@ -44,26 +46,35 @@ Category <- R6::R6Class( fromJSON = function(CategoryJson) { CategoryObject <- jsonlite::fromJSON(CategoryJson) if (!is.null(CategoryObject$`id`)) { - self$`id` <- CategoryObject$`id` + self$`id` <- CategoryObject$`id` } if (!is.null(CategoryObject$`name`)) { - self$`name` <- CategoryObject$`name` + self$`name` <- CategoryObject$`name` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "id": %d, - "name": %s + "id": + %d + + + , + "name": + + "%s" + + }', - self$`id`, - self$`name` + self$`id`, + self$`name` ) + gsub("[\r\n]| ", "", outstring) }, fromJSONString = function(CategoryJson) { CategoryObject <- jsonlite::fromJSON(CategoryJson) - self$`id` <- CategoryObject$`id` - self$`name` <- CategoryObject$`name` + self$`id` <- CategoryObject$`id` + self$`name` <- CategoryObject$`name` } ) ) diff --git a/samples/client/petstore/R/R/Order.r b/samples/client/petstore/R/R/Order.r index 5055880cfef..35512638078 100644 --- a/samples/client/petstore/R/R/Order.r +++ b/samples/client/petstore/R/R/Order.r @@ -30,23 +30,23 @@ Order <- R6::R6Class( `complete` = NULL, initialize = function(`id`, `petId`, `quantity`, `shipDate`, `status`, `complete`){ if (!missing(`id`)) { - stopifnot(is.numeric(`id`), length(`id`) == 1) + stopifnot(is.numeric(`id`), length(`id`) == 1) self$`id` <- `id` } if (!missing(`petId`)) { - stopifnot(is.numeric(`petId`), length(`petId`) == 1) + stopifnot(is.numeric(`petId`), length(`petId`) == 1) self$`petId` <- `petId` } if (!missing(`quantity`)) { - stopifnot(is.numeric(`quantity`), length(`quantity`) == 1) + stopifnot(is.numeric(`quantity`), length(`quantity`) == 1) self$`quantity` <- `quantity` } if (!missing(`shipDate`)) { - stopifnot(is.character(`shipDate`), length(`shipDate`) == 1) + stopifnot(is.character(`shipDate`), length(`shipDate`) == 1) self$`shipDate` <- `shipDate` } if (!missing(`status`)) { - stopifnot(is.character(`status`), length(`status`) == 1) + stopifnot(is.character(`status`), length(`status`) == 1) self$`status` <- `status` } if (!missing(`complete`)) { @@ -56,22 +56,28 @@ Order <- R6::R6Class( toJSON = function() { OrderObject <- list() if (!is.null(self$`id`)) { - OrderObject[['id']] <- self$`id` + OrderObject[['id']] <- + self$`id` } if (!is.null(self$`petId`)) { - OrderObject[['petId']] <- self$`petId` + OrderObject[['petId']] <- + self$`petId` } if (!is.null(self$`quantity`)) { - OrderObject[['quantity']] <- self$`quantity` + OrderObject[['quantity']] <- + self$`quantity` } if (!is.null(self$`shipDate`)) { - OrderObject[['shipDate']] <- self$`shipDate` + OrderObject[['shipDate']] <- + self$`shipDate` } if (!is.null(self$`status`)) { - OrderObject[['status']] <- self$`status` + OrderObject[['status']] <- + self$`status` } if (!is.null(self$`complete`)) { - OrderObject[['complete']] <- self$`complete` + OrderObject[['complete']] <- + self$`complete` } OrderObject @@ -79,50 +85,75 @@ Order <- R6::R6Class( fromJSON = function(OrderJson) { OrderObject <- jsonlite::fromJSON(OrderJson) if (!is.null(OrderObject$`id`)) { - self$`id` <- OrderObject$`id` + self$`id` <- OrderObject$`id` } if (!is.null(OrderObject$`petId`)) { - self$`petId` <- OrderObject$`petId` + self$`petId` <- OrderObject$`petId` } if (!is.null(OrderObject$`quantity`)) { - self$`quantity` <- OrderObject$`quantity` + self$`quantity` <- OrderObject$`quantity` } if (!is.null(OrderObject$`shipDate`)) { - self$`shipDate` <- OrderObject$`shipDate` + self$`shipDate` <- OrderObject$`shipDate` } if (!is.null(OrderObject$`status`)) { - self$`status` <- OrderObject$`status` + self$`status` <- OrderObject$`status` } if (!is.null(OrderObject$`complete`)) { - self$`complete` <- OrderObject$`complete` + self$`complete` <- OrderObject$`complete` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "id": %d, - "petId": %d, - "quantity": %d, - "shipDate": %s, - "status": %s, - "complete": %s + "id": + %d + + + , + "petId": + %d + + + , + "quantity": + %d + + + , + "shipDate": + + "%s" + + , + "status": + + "%s" + + , + "complete": + + "%s" + + }', - self$`id`, - self$`petId`, - self$`quantity`, - self$`shipDate`, - self$`status`, - self$`complete` + 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` + self$`id` <- OrderObject$`id` + self$`petId` <- OrderObject$`petId` + self$`quantity` <- OrderObject$`quantity` + self$`shipDate` <- OrderObject$`shipDate` + self$`status` <- OrderObject$`status` + self$`complete` <- OrderObject$`complete` } ) ) diff --git a/samples/client/petstore/R/R/PetApi.r b/samples/client/petstore/R/R/PetApi.r index e3697d9cd79..85844eded32 100644 --- a/samples/client/petstore/R/R/PetApi.r +++ b/samples/client/petstore/R/R/PetApi.r @@ -57,13 +57,13 @@ PetApi <- R6::R6Class( self$apiClient <- ApiClient$new() } }, - add_pet = function(pet, ...){ + add_pet = function(body, ...){ args <- list(...) queryParams <- list() headerParams <- character() - if (!missing(`pet`)) { - body <- `pet`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { body <- NULL } @@ -133,9 +133,7 @@ PetApi <- R6::R6Class( ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - returnObject <- Pet$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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) { - returnObject <- Pet$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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) { - returnObject <- Pet$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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(...) queryParams <- list() headerParams <- character() - if (!missing(`pet`)) { - body <- `pet`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { body <- NULL } @@ -281,9 +275,7 @@ PetApi <- R6::R6Class( ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - returnObject <- ApiResponse$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/StoreApi.r b/samples/client/petstore/R/R/StoreApi.r index 738365c4364..744e1ebebf9 100644 --- a/samples/client/petstore/R/R/StoreApi.r +++ b/samples/client/petstore/R/R/StoreApi.r @@ -85,9 +85,7 @@ StoreApi <- R6::R6Class( ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - returnObject <- Integer$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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) { - returnObject <- Order$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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(...) queryParams <- list() headerParams <- character() - if (!missing(`order`)) { - body <- `order`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { body <- NULL } @@ -143,9 +139,7 @@ StoreApi <- R6::R6Class( ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - returnObject <- Order$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) { diff --git a/samples/client/petstore/R/R/Tag.r b/samples/client/petstore/R/R/Tag.r index 9cd0373611c..714d5814324 100644 --- a/samples/client/petstore/R/R/Tag.r +++ b/samples/client/petstore/R/R/Tag.r @@ -22,21 +22,23 @@ Tag <- R6::R6Class( `name` = NULL, initialize = function(`id`, `name`){ if (!missing(`id`)) { - stopifnot(is.numeric(`id`), length(`id`) == 1) + stopifnot(is.numeric(`id`), length(`id`) == 1) self$`id` <- `id` } if (!missing(`name`)) { - stopifnot(is.character(`name`), length(`name`) == 1) + stopifnot(is.character(`name`), length(`name`) == 1) self$`name` <- `name` } }, toJSON = function() { TagObject <- list() if (!is.null(self$`id`)) { - TagObject[['id']] <- self$`id` + TagObject[['id']] <- + self$`id` } if (!is.null(self$`name`)) { - TagObject[['name']] <- self$`name` + TagObject[['name']] <- + self$`name` } TagObject @@ -44,26 +46,35 @@ Tag <- R6::R6Class( fromJSON = function(TagJson) { TagObject <- jsonlite::fromJSON(TagJson) if (!is.null(TagObject$`id`)) { - self$`id` <- TagObject$`id` + self$`id` <- TagObject$`id` } if (!is.null(TagObject$`name`)) { - self$`name` <- TagObject$`name` + self$`name` <- TagObject$`name` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "id": %d, - "name": %s + "id": + %d + + + , + "name": + + "%s" + + }', - self$`id`, - self$`name` + self$`id`, + self$`name` ) + gsub("[\r\n]| ", "", outstring) }, fromJSONString = function(TagJson) { TagObject <- jsonlite::fromJSON(TagJson) - self$`id` <- TagObject$`id` - self$`name` <- TagObject$`name` + self$`id` <- TagObject$`id` + self$`name` <- TagObject$`name` } ) ) diff --git a/samples/client/petstore/R/R/User.r b/samples/client/petstore/R/R/User.r index 0a811bab418..58455ff5b91 100644 --- a/samples/client/petstore/R/R/User.r +++ b/samples/client/petstore/R/R/User.r @@ -34,63 +34,71 @@ User <- R6::R6Class( `userStatus` = NULL, initialize = function(`id`, `username`, `firstName`, `lastName`, `email`, `password`, `phone`, `userStatus`){ if (!missing(`id`)) { - stopifnot(is.numeric(`id`), length(`id`) == 1) + stopifnot(is.numeric(`id`), length(`id`) == 1) self$`id` <- `id` } if (!missing(`username`)) { - stopifnot(is.character(`username`), length(`username`) == 1) + stopifnot(is.character(`username`), length(`username`) == 1) self$`username` <- `username` } if (!missing(`firstName`)) { - stopifnot(is.character(`firstName`), length(`firstName`) == 1) + stopifnot(is.character(`firstName`), length(`firstName`) == 1) self$`firstName` <- `firstName` } if (!missing(`lastName`)) { - stopifnot(is.character(`lastName`), length(`lastName`) == 1) + stopifnot(is.character(`lastName`), length(`lastName`) == 1) self$`lastName` <- `lastName` } if (!missing(`email`)) { - stopifnot(is.character(`email`), length(`email`) == 1) + stopifnot(is.character(`email`), length(`email`) == 1) self$`email` <- `email` } if (!missing(`password`)) { - stopifnot(is.character(`password`), length(`password`) == 1) + stopifnot(is.character(`password`), length(`password`) == 1) self$`password` <- `password` } if (!missing(`phone`)) { - stopifnot(is.character(`phone`), length(`phone`) == 1) + stopifnot(is.character(`phone`), length(`phone`) == 1) self$`phone` <- `phone` } if (!missing(`userStatus`)) { - stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1) + stopifnot(is.numeric(`userStatus`), length(`userStatus`) == 1) self$`userStatus` <- `userStatus` } }, toJSON = function() { UserObject <- list() if (!is.null(self$`id`)) { - UserObject[['id']] <- self$`id` + UserObject[['id']] <- + self$`id` } if (!is.null(self$`username`)) { - UserObject[['username']] <- self$`username` + UserObject[['username']] <- + self$`username` } if (!is.null(self$`firstName`)) { - UserObject[['firstName']] <- self$`firstName` + UserObject[['firstName']] <- + self$`firstName` } if (!is.null(self$`lastName`)) { - UserObject[['lastName']] <- self$`lastName` + UserObject[['lastName']] <- + self$`lastName` } if (!is.null(self$`email`)) { - UserObject[['email']] <- self$`email` + UserObject[['email']] <- + self$`email` } if (!is.null(self$`password`)) { - UserObject[['password']] <- self$`password` + UserObject[['password']] <- + self$`password` } if (!is.null(self$`phone`)) { - UserObject[['phone']] <- self$`phone` + UserObject[['phone']] <- + self$`phone` } if (!is.null(self$`userStatus`)) { - UserObject[['userStatus']] <- self$`userStatus` + UserObject[['userStatus']] <- + self$`userStatus` } UserObject @@ -98,62 +106,95 @@ User <- R6::R6Class( fromJSON = function(UserJson) { UserObject <- jsonlite::fromJSON(UserJson) if (!is.null(UserObject$`id`)) { - self$`id` <- UserObject$`id` + self$`id` <- UserObject$`id` } if (!is.null(UserObject$`username`)) { - self$`username` <- UserObject$`username` + self$`username` <- UserObject$`username` } if (!is.null(UserObject$`firstName`)) { - self$`firstName` <- UserObject$`firstName` + self$`firstName` <- UserObject$`firstName` } if (!is.null(UserObject$`lastName`)) { - self$`lastName` <- UserObject$`lastName` + self$`lastName` <- UserObject$`lastName` } if (!is.null(UserObject$`email`)) { - self$`email` <- UserObject$`email` + self$`email` <- UserObject$`email` } if (!is.null(UserObject$`password`)) { - self$`password` <- UserObject$`password` + self$`password` <- UserObject$`password` } if (!is.null(UserObject$`phone`)) { - self$`phone` <- UserObject$`phone` + self$`phone` <- UserObject$`phone` } if (!is.null(UserObject$`userStatus`)) { - self$`userStatus` <- UserObject$`userStatus` + self$`userStatus` <- UserObject$`userStatus` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "id": %d, - "username": %s, - "firstName": %s, - "lastName": %s, - "email": %s, - "password": %s, - "phone": %s, - "userStatus": %d + "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` + 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` + 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` } ) ) diff --git a/samples/client/petstore/R/R/UserApi.r b/samples/client/petstore/R/R/UserApi.r index b71836edb3e..b7c06e78a74 100644 --- a/samples/client/petstore/R/R/UserApi.r +++ b/samples/client/petstore/R/R/UserApi.r @@ -57,13 +57,13 @@ UserApi <- R6::R6Class( self$apiClient <- ApiClient$new() } }, - create_user = function(user, ...){ + create_user = function(body, ...){ args <- list(...) queryParams <- list() headerParams <- character() - if (!missing(`user`)) { - body <- `user`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { 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(...) queryParams <- list() headerParams <- character() - if (!missing(`user`)) { - body <- `user`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { 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(...) queryParams <- list() headerParams <- character() - if (!missing(`user`)) { - body <- `user`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { body <- NULL } @@ -185,9 +185,7 @@ UserApi <- R6::R6Class( ...) if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) { - returnObject <- User$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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) { - returnObject <- Character$new() - result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8")) - Response$new(returnObject, resp) + jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8")) } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) { Response$new("API client error", resp) } 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(...) queryParams <- list() headerParams <- character() - if (!missing(`user`)) { - body <- `user`$toJSONString() + if (!missing(`body`)) { + body <- `body`$toJSONString() } else { body <- NULL } diff --git a/samples/client/petstore/R/R/pet.R b/samples/client/petstore/R/R/pet.R index 6248b752a9c..ecd1753b2e1 100644 --- a/samples/client/petstore/R/R/pet.R +++ b/samples/client/petstore/R/R/pet.R @@ -30,51 +30,57 @@ Pet <- R6::R6Class( `status` = NULL, initialize = function(`id`, `category`, `name`, `photoUrls`, `tags`, `status`){ if (!missing(`id`)) { - stopifnot(is.numeric(`id`), length(`id`) == 1) + stopifnot(is.numeric(`id`), length(`id`) == 1) self$`id` <- `id` } if (!missing(`category`)) { - stopifnot(R6::is.R6(`category`)) + stopifnot(R6::is.R6(`category`)) self$`category` <- `category` } if (!missing(`name`)) { - stopifnot(is.character(`name`), length(`name`) == 1) + stopifnot(is.character(`name`), length(`name`) == 1) self$`name` <- `name` } if (!missing(`photoUrls`)) { - stopifnot(is.list(`photoUrls`), length(`photoUrls`) != 0) - lapply(`photoUrls`, function(x) stopifnot(is.character(x))) + stopifnot(is.vector(`photoUrls`), length(`photoUrls`) != 0) + sapply(`photoUrls`, function(x) stopifnot(is.character(x))) self$`photoUrls` <- `photoUrls` } if (!missing(`tags`)) { - stopifnot(is.list(`tags`), length(`tags`) != 0) - lapply(`tags`, function(x) stopifnot(R6::is.R6(x))) + stopifnot(is.vector(`tags`), length(`tags`) != 0) + sapply(`tags`, function(x) stopifnot(R6::is.R6(x))) self$`tags` <- `tags` } if (!missing(`status`)) { - stopifnot(is.character(`status`), length(`status`) == 1) + stopifnot(is.character(`status`), length(`status`) == 1) self$`status` <- `status` } }, toJSON = function() { PetObject <- list() if (!is.null(self$`id`)) { - PetObject[['id']] <- self$`id` + PetObject[['id']] <- + self$`id` } if (!is.null(self$`category`)) { - PetObject[['category']] <- self$`category`$toJSON() + PetObject[['category']] <- + self$`category`$toJSON() } if (!is.null(self$`name`)) { - PetObject[['name']] <- self$`name` + PetObject[['name']] <- + self$`name` } if (!is.null(self$`photoUrls`)) { - PetObject[['photoUrls']] <- self$`photoUrls` + PetObject[['photoUrls']] <- + self$`photoUrls` } 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`)) { - PetObject[['status']] <- self$`status` + PetObject[['status']] <- + self$`status` } PetObject @@ -82,57 +88,78 @@ Pet <- R6::R6Class( fromJSON = function(PetJson) { PetObject <- jsonlite::fromJSON(PetJson) if (!is.null(PetObject$`id`)) { - self$`id` <- PetObject$`id` + self$`id` <- PetObject$`id` } if (!is.null(PetObject$`category`)) { - categoryObject <- Category$new() - categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE)) - self$`category` <- categoryObject + categoryObject <- Category$new() + categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE)) + self$`category` <- categoryObject } if (!is.null(PetObject$`name`)) { - self$`name` <- PetObject$`name` + self$`name` <- PetObject$`name` } if (!is.null(PetObject$`photoUrls`)) { - self$`photoUrls` <- PetObject$`photoUrls` + self$`photoUrls` <- PetObject$`photoUrls` } if (!is.null(PetObject$`tags`)) { - self$`tags` <- lapply(PetObject$`tags`, function(x) { - tagsObject <- Tag$new() - tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)) - tagsObject - }) + self$`tags` <- sapply(PetObject$`tags`, function(x) { + tagsObject <- Tag$new() + tagsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)) + tagsObject + }) } if (!is.null(PetObject$`status`)) { - self$`status` <- PetObject$`status` + self$`status` <- PetObject$`status` } }, toJSONString = function() { - sprintf( + outstring <- sprintf( '{ - "id": %d, - "category": %s, - "name": %s, - "photoUrls": [%s], - "tags": [%s], - "status": %s + "id": + %d + + + , + "category": + "%s" + , + "name": + + "%s" + + , + "photoUrls": + + ["%s"] + + , + "tags": + ["%s"] + , + "status": + + "%s" + + }', - self$`id`, - self$`category`$toJSON(), - self$`name`, - lapply(self$`photoUrls`, function(x) paste(paste0('"', x, '"'), sep=",")), - lapply(self$`tags`, function(x) paste(x$toJSON(), sep=",")), - self$`status` + self$`id`, + self$`category`$toJSON(), + self$`name`, + paste0(self$`photoUrls`, collapse='","'), + paste0(sapply(self$`tags`, function(x) x$toJSON()), collapse='","'), + self$`status` ) + gsub("[\r\n]| ", "", outstring) }, fromJSONString = function(PetJson) { PetObject <- jsonlite::fromJSON(PetJson) - self$`id` <- PetObject$`id` - CategoryObject <- Category$new() - self$`category` <- CategoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE)) - self$`name` <- PetObject$`name` - self$`photoUrls` <- PetObject$`photoUrls` - self$`tags` <- lapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) - self$`status` <- PetObject$`status` + self$`id` <- PetObject$`id` + CategoryObject <- Category$new() + self$`category` <- CategoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE)) + self$`name` <- PetObject$`name` + self$`photoUrls` <- PetObject$`photoUrls` + self$`tags` <- sapply(PetObject$`tags`, function(x) Tag$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))) + self$`status` <- PetObject$`status` } ) )