[R] minify json in toJSON (#12699)

* minify json in toJSON

* update fromjson with better variable naming
This commit is contained in:
William Cheng 2022-06-25 18:11:25 +08:00 committed by GitHub
parent 29ea48ee96
commit e4b78dbbd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 333 additions and 315 deletions

View File

@ -176,24 +176,24 @@
#' @description
#' Deserialize JSON string into an instance of {{{classname}}}
#'
#' @param {{classname}}Json the JSON input
#' @param input_json the JSON input
#' @return the instance of {{{classname}}}
#' @export
fromJSON = function({{classname}}Json) {
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
{{#vars}}
if (!is.null({{classname}}Object$`{{baseName}}`)) {
if (!is.null(this_object$`{{baseName}}`)) {
{{#isContainer}}
self$`{{name}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
self$`{{name}}` <- ApiClient$new()$deserializeObj(this_object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
self$`{{name}}` <- {{classname}}Object$`{{baseName}}`
self$`{{name}}` <- this_object$`{{baseName}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{name}}Object <- {{dataType}}$new()
{{name}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE, digits = NA))
self$`{{name}}` <- {{name}}Object
{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object <- {{dataType}}$new()
{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object$fromJSON(jsonlite::toJSON(this_object${{baseName}}, auto_unbox = TRUE, digits = NA))
self$`{{name}}` <- {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object
{{/isPrimitiveType}}
{{/isContainer}}
}
@ -266,29 +266,29 @@
{{/vars}}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of {{{classname}}}
#'
#' @description
#' Deserialize JSON string into an instance of {{{classname}}}
#'
#' @param {{classname}}Json the JSON input
#' @param input_json the JSON input
#' @return the instance of {{{classname}}}
#' @export
fromJSONString = function({{classname}}Json) {
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
{{#vars}}
{{! AAPI - added condition for handling container type of parameters, map and array}}
{{#isContainer}}
self$`{{name}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{name}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
self$`{{name}}` <- ApiClient$new()$deserializeObj(this_object$`{{name}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
self$`{{name}}` <- {{classname}}Object$`{{name}}`
self$`{{name}}` <- this_object$`{{name}}`
{{/isPrimitiveType}}
{{^isPrimitiveType}}
self$`{{name}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{name}}, auto_unbox = TRUE, digits = NA))
self$`{{name}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON(this_object${{name}}, auto_unbox = TRUE, digits = NA))
{{/isPrimitiveType}}
{{/isContainer}}
{{/vars}}

View File

@ -99,25 +99,25 @@ AllofTagApiResponse <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of AllofTagApiResponse
#'
#' @param AllofTagApiResponseJson the JSON input
#' @param input_json the JSON input
#' @return the instance of AllofTagApiResponse
#' @export
fromJSON = function(AllofTagApiResponseJson) {
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
if (!is.null(AllofTagApiResponseObject$`id`)) {
self$`id` <- AllofTagApiResponseObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(AllofTagApiResponseObject$`name`)) {
self$`name` <- AllofTagApiResponseObject$`name`
if (!is.null(this_object$`name`)) {
self$`name` <- this_object$`name`
}
if (!is.null(AllofTagApiResponseObject$`code`)) {
self$`code` <- AllofTagApiResponseObject$`code`
if (!is.null(this_object$`code`)) {
self$`code` <- this_object$`code`
}
if (!is.null(AllofTagApiResponseObject$`type`)) {
self$`type` <- AllofTagApiResponseObject$`type`
if (!is.null(this_object$`type`)) {
self$`type` <- this_object$`type`
}
if (!is.null(AllofTagApiResponseObject$`message`)) {
self$`message` <- AllofTagApiResponseObject$`message`
if (!is.null(this_object$`message`)) {
self$`message` <- this_object$`message`
}
self
},
@ -167,23 +167,23 @@ AllofTagApiResponse <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of AllofTagApiResponse
#'
#' @description
#' Deserialize JSON string into an instance of AllofTagApiResponse
#'
#' @param AllofTagApiResponseJson the JSON input
#' @param input_json the JSON input
#' @return the instance of AllofTagApiResponse
#' @export
fromJSONString = function(AllofTagApiResponseJson) {
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
self$`id` <- AllofTagApiResponseObject$`id`
self$`name` <- AllofTagApiResponseObject$`name`
self$`code` <- AllofTagApiResponseObject$`code`
self$`type` <- AllofTagApiResponseObject$`type`
self$`message` <- AllofTagApiResponseObject$`message`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`name` <- this_object$`name`
self$`code` <- this_object$`code`
self$`type` <- this_object$`type`
self$`message` <- this_object$`message`
self
},
#' Validate JSON input with respect to AllofTagApiResponse

View File

@ -66,16 +66,16 @@ Animal <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Animal
#'
#' @param AnimalJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Animal
#' @export
fromJSON = function(AnimalJson) {
AnimalObject <- jsonlite::fromJSON(AnimalJson)
if (!is.null(AnimalObject$`className`)) {
self$`className` <- AnimalObject$`className`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(AnimalObject$`color`)) {
self$`color` <- AnimalObject$`color`
if (!is.null(this_object$`color`)) {
self$`color` <- this_object$`color`
}
self
},
@ -104,20 +104,20 @@ Animal <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Animal
#'
#' @description
#' Deserialize JSON string into an instance of Animal
#'
#' @param AnimalJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Animal
#' @export
fromJSONString = function(AnimalJson) {
AnimalObject <- jsonlite::fromJSON(AnimalJson)
self$`className` <- AnimalObject$`className`
self$`color` <- AnimalObject$`color`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`color` <- this_object$`color`
self
},
#' Validate JSON input with respect to Animal

View File

@ -66,16 +66,16 @@ BasquePig <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of BasquePig
#'
#' @param BasquePigJson the JSON input
#' @param input_json the JSON input
#' @return the instance of BasquePig
#' @export
fromJSON = function(BasquePigJson) {
BasquePigObject <- jsonlite::fromJSON(BasquePigJson)
if (!is.null(BasquePigObject$`className`)) {
self$`className` <- BasquePigObject$`className`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(BasquePigObject$`color`)) {
self$`color` <- BasquePigObject$`color`
if (!is.null(this_object$`color`)) {
self$`color` <- this_object$`color`
}
self
},
@ -104,20 +104,20 @@ BasquePig <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of BasquePig
#'
#' @description
#' Deserialize JSON string into an instance of BasquePig
#'
#' @param BasquePigJson the JSON input
#' @param input_json the JSON input
#' @return the instance of BasquePig
#' @export
fromJSONString = function(BasquePigJson) {
BasquePigObject <- jsonlite::fromJSON(BasquePigJson)
self$`className` <- BasquePigObject$`className`
self$`color` <- BasquePigObject$`color`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`color` <- this_object$`color`
self
},
#' Validate JSON input with respect to BasquePig

View File

@ -78,19 +78,19 @@ Cat <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Cat
#'
#' @param CatJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Cat
#' @export
fromJSON = function(CatJson) {
CatObject <- jsonlite::fromJSON(CatJson)
if (!is.null(CatObject$`className`)) {
self$`className` <- CatObject$`className`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(CatObject$`color`)) {
self$`color` <- CatObject$`color`
if (!is.null(this_object$`color`)) {
self$`color` <- this_object$`color`
}
if (!is.null(CatObject$`declawed`)) {
self$`declawed` <- CatObject$`declawed`
if (!is.null(this_object$`declawed`)) {
self$`declawed` <- this_object$`declawed`
}
self
},
@ -126,21 +126,21 @@ Cat <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Cat
#'
#' @description
#' Deserialize JSON string into an instance of Cat
#'
#' @param CatJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Cat
#' @export
fromJSONString = function(CatJson) {
CatObject <- jsonlite::fromJSON(CatJson)
self$`className` <- CatObject$`className`
self$`color` <- CatObject$`color`
self$`declawed` <- CatObject$`declawed`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`color` <- this_object$`color`
self$`declawed` <- this_object$`declawed`
self
},
#' Validate JSON input with respect to Cat

View File

@ -55,13 +55,13 @@ CatAllOf <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of CatAllOf
#'
#' @param CatAllOfJson the JSON input
#' @param input_json the JSON input
#' @return the instance of CatAllOf
#' @export
fromJSON = function(CatAllOfJson) {
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
if (!is.null(CatAllOfObject$`declawed`)) {
self$`declawed` <- CatAllOfObject$`declawed`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`declawed`)) {
self$`declawed` <- this_object$`declawed`
}
self
},
@ -83,19 +83,19 @@ CatAllOf <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of CatAllOf
#'
#' @description
#' Deserialize JSON string into an instance of CatAllOf
#'
#' @param CatAllOfJson the JSON input
#' @param input_json the JSON input
#' @return the instance of CatAllOf
#' @export
fromJSONString = function(CatAllOfJson) {
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
self$`declawed` <- CatAllOfObject$`declawed`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`declawed` <- this_object$`declawed`
self
},
#' Validate JSON input with respect to CatAllOf

View File

@ -66,16 +66,16 @@ Category <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Category
#'
#' @param CategoryJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Category
#' @export
fromJSON = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
if (!is.null(CategoryObject$`id`)) {
self$`id` <- CategoryObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(CategoryObject$`name`)) {
self$`name` <- CategoryObject$`name`
if (!is.null(this_object$`name`)) {
self$`name` <- this_object$`name`
}
self
},
@ -104,20 +104,20 @@ Category <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Category
#'
#' @description
#' Deserialize JSON string into an instance of Category
#'
#' @param CategoryJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Category
#' @export
fromJSONString = function(CategoryJson) {
CategoryObject <- jsonlite::fromJSON(CategoryJson)
self$`id` <- CategoryObject$`id`
self$`name` <- CategoryObject$`name`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`name` <- this_object$`name`
self
},
#' Validate JSON input with respect to Category

View File

@ -66,16 +66,16 @@ DanishPig <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of DanishPig
#'
#' @param DanishPigJson the JSON input
#' @param input_json the JSON input
#' @return the instance of DanishPig
#' @export
fromJSON = function(DanishPigJson) {
DanishPigObject <- jsonlite::fromJSON(DanishPigJson)
if (!is.null(DanishPigObject$`className`)) {
self$`className` <- DanishPigObject$`className`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(DanishPigObject$`size`)) {
self$`size` <- DanishPigObject$`size`
if (!is.null(this_object$`size`)) {
self$`size` <- this_object$`size`
}
self
},
@ -104,20 +104,20 @@ DanishPig <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of DanishPig
#'
#' @description
#' Deserialize JSON string into an instance of DanishPig
#'
#' @param DanishPigJson the JSON input
#' @param input_json the JSON input
#' @return the instance of DanishPig
#' @export
fromJSONString = function(DanishPigJson) {
DanishPigObject <- jsonlite::fromJSON(DanishPigJson)
self$`className` <- DanishPigObject$`className`
self$`size` <- DanishPigObject$`size`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`size` <- this_object$`size`
self
},
#' Validate JSON input with respect to DanishPig

View File

@ -78,19 +78,19 @@ Dog <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Dog
#'
#' @param DogJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Dog
#' @export
fromJSON = function(DogJson) {
DogObject <- jsonlite::fromJSON(DogJson)
if (!is.null(DogObject$`className`)) {
self$`className` <- DogObject$`className`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(DogObject$`color`)) {
self$`color` <- DogObject$`color`
if (!is.null(this_object$`color`)) {
self$`color` <- this_object$`color`
}
if (!is.null(DogObject$`breed`)) {
self$`breed` <- DogObject$`breed`
if (!is.null(this_object$`breed`)) {
self$`breed` <- this_object$`breed`
}
self
},
@ -126,21 +126,21 @@ Dog <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Dog
#'
#' @description
#' Deserialize JSON string into an instance of Dog
#'
#' @param DogJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Dog
#' @export
fromJSONString = function(DogJson) {
DogObject <- jsonlite::fromJSON(DogJson)
self$`className` <- DogObject$`className`
self$`color` <- DogObject$`color`
self$`breed` <- DogObject$`breed`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`color` <- this_object$`color`
self$`breed` <- this_object$`breed`
self
},
#' Validate JSON input with respect to Dog

View File

@ -55,13 +55,13 @@ DogAllOf <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of DogAllOf
#'
#' @param DogAllOfJson the JSON input
#' @param input_json the JSON input
#' @return the instance of DogAllOf
#' @export
fromJSON = function(DogAllOfJson) {
DogAllOfObject <- jsonlite::fromJSON(DogAllOfJson)
if (!is.null(DogAllOfObject$`breed`)) {
self$`breed` <- DogAllOfObject$`breed`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`breed`)) {
self$`breed` <- this_object$`breed`
}
self
},
@ -83,19 +83,19 @@ DogAllOf <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of DogAllOf
#'
#' @description
#' Deserialize JSON string into an instance of DogAllOf
#'
#' @param DogAllOfJson the JSON input
#' @param input_json the JSON input
#' @return the instance of DogAllOf
#' @export
fromJSONString = function(DogAllOfJson) {
DogAllOfObject <- jsonlite::fromJSON(DogAllOfJson)
self$`breed` <- DogAllOfObject$`breed`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`breed` <- this_object$`breed`
self
},
#' Validate JSON input with respect to DogAllOf

View File

@ -77,19 +77,19 @@ ModelApiResponse <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of ModelApiResponse
#'
#' @param ModelApiResponseJson the JSON input
#' @param input_json the JSON input
#' @return the instance of ModelApiResponse
#' @export
fromJSON = function(ModelApiResponseJson) {
ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson)
if (!is.null(ModelApiResponseObject$`code`)) {
self$`code` <- ModelApiResponseObject$`code`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`code`)) {
self$`code` <- this_object$`code`
}
if (!is.null(ModelApiResponseObject$`type`)) {
self$`type` <- ModelApiResponseObject$`type`
if (!is.null(this_object$`type`)) {
self$`type` <- this_object$`type`
}
if (!is.null(ModelApiResponseObject$`message`)) {
self$`message` <- ModelApiResponseObject$`message`
if (!is.null(this_object$`message`)) {
self$`message` <- this_object$`message`
}
self
},
@ -125,21 +125,21 @@ ModelApiResponse <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of ModelApiResponse
#'
#' @description
#' Deserialize JSON string into an instance of ModelApiResponse
#'
#' @param ModelApiResponseJson the JSON input
#' @param input_json the JSON input
#' @return the instance of ModelApiResponse
#' @export
fromJSONString = function(ModelApiResponseJson) {
ModelApiResponseObject <- jsonlite::fromJSON(ModelApiResponseJson)
self$`code` <- ModelApiResponseObject$`code`
self$`type` <- ModelApiResponseObject$`type`
self$`message` <- ModelApiResponseObject$`message`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`code` <- this_object$`code`
self$`type` <- this_object$`type`
self$`message` <- this_object$`message`
self
},
#' Validate JSON input with respect to ModelApiResponse

View File

@ -110,28 +110,28 @@ Order <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Order
#'
#' @param OrderJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Order
#' @export
fromJSON = function(OrderJson) {
OrderObject <- jsonlite::fromJSON(OrderJson)
if (!is.null(OrderObject$`id`)) {
self$`id` <- OrderObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(OrderObject$`petId`)) {
self$`petId` <- OrderObject$`petId`
if (!is.null(this_object$`petId`)) {
self$`petId` <- this_object$`petId`
}
if (!is.null(OrderObject$`quantity`)) {
self$`quantity` <- OrderObject$`quantity`
if (!is.null(this_object$`quantity`)) {
self$`quantity` <- this_object$`quantity`
}
if (!is.null(OrderObject$`shipDate`)) {
self$`shipDate` <- OrderObject$`shipDate`
if (!is.null(this_object$`shipDate`)) {
self$`shipDate` <- this_object$`shipDate`
}
if (!is.null(OrderObject$`status`)) {
self$`status` <- OrderObject$`status`
if (!is.null(this_object$`status`)) {
self$`status` <- this_object$`status`
}
if (!is.null(OrderObject$`complete`)) {
self$`complete` <- OrderObject$`complete`
if (!is.null(this_object$`complete`)) {
self$`complete` <- this_object$`complete`
}
self
},
@ -188,24 +188,24 @@ Order <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Order
#'
#' @description
#' Deserialize JSON string into an instance of Order
#'
#' @param OrderJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Order
#' @export
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`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`petId` <- this_object$`petId`
self$`quantity` <- this_object$`quantity`
self$`shipDate` <- this_object$`shipDate`
self$`status` <- this_object$`status`
self$`complete` <- this_object$`complete`
self
},
#' Validate JSON input with respect to Order

View File

@ -112,30 +112,30 @@ Pet <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Pet
#'
#' @param PetJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Pet
#' @export
fromJSON = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
if (!is.null(PetObject$`id`)) {
self$`id` <- PetObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(PetObject$`category`)) {
categoryObject <- Category$new()
categoryObject$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE, digits = NA))
self$`category` <- categoryObject
if (!is.null(this_object$`category`)) {
category_object <- Category$new()
category_object$fromJSON(jsonlite::toJSON(this_object$category, auto_unbox = TRUE, digits = NA))
self$`category` <- category_object
}
if (!is.null(PetObject$`name`)) {
self$`name` <- PetObject$`name`
if (!is.null(this_object$`name`)) {
self$`name` <- this_object$`name`
}
if (!is.null(PetObject$`photoUrls`)) {
self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]", loadNamespace("petstore"))
if (!is.null(this_object$`photoUrls`)) {
self$`photoUrls` <- ApiClient$new()$deserializeObj(this_object$`photoUrls`, "array[character]", loadNamespace("petstore"))
}
if (!is.null(PetObject$`tags`)) {
self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]", loadNamespace("petstore"))
if (!is.null(this_object$`tags`)) {
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
}
if (!is.null(PetObject$`status`)) {
self$`status` <- PetObject$`status`
if (!is.null(this_object$`status`)) {
self$`status` <- this_object$`status`
}
self
},
@ -192,24 +192,24 @@ Pet <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Pet
#'
#' @description
#' Deserialize JSON string into an instance of Pet
#'
#' @param PetJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Pet
#' @export
fromJSONString = function(PetJson) {
PetObject <- jsonlite::fromJSON(PetJson)
self$`id` <- PetObject$`id`
self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(PetObject$category, auto_unbox = TRUE, digits = NA))
self$`name` <- PetObject$`name`
self$`photoUrls` <- ApiClient$new()$deserializeObj(PetObject$`photoUrls`, "array[character]", loadNamespace("petstore"))
self$`tags` <- ApiClient$new()$deserializeObj(PetObject$`tags`, "array[Tag]", loadNamespace("petstore"))
self$`status` <- PetObject$`status`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`category` <- Category$new()$fromJSON(jsonlite::toJSON(this_object$category, auto_unbox = TRUE, digits = NA))
self$`name` <- this_object$`name`
self$`photoUrls` <- ApiClient$new()$deserializeObj(this_object$`photoUrls`, "array[character]", loadNamespace("petstore"))
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
self$`status` <- this_object$`status`
self
},
#' Validate JSON input with respect to Pet

View File

@ -77,19 +77,19 @@ Special <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Special
#'
#' @param SpecialJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Special
#' @export
fromJSON = function(SpecialJson) {
SpecialObject <- jsonlite::fromJSON(SpecialJson)
if (!is.null(SpecialObject$`self`)) {
self$`item_self` <- SpecialObject$`self`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`self`)) {
self$`item_self` <- this_object$`self`
}
if (!is.null(SpecialObject$`private`)) {
self$`item_private` <- SpecialObject$`private`
if (!is.null(this_object$`private`)) {
self$`item_private` <- this_object$`private`
}
if (!is.null(SpecialObject$`super`)) {
self$`item_super` <- SpecialObject$`super`
if (!is.null(this_object$`super`)) {
self$`item_super` <- this_object$`super`
}
self
},
@ -125,21 +125,21 @@ Special <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Special
#'
#' @description
#' Deserialize JSON string into an instance of Special
#'
#' @param SpecialJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Special
#' @export
fromJSONString = function(SpecialJson) {
SpecialObject <- jsonlite::fromJSON(SpecialJson)
self$`item_self` <- SpecialObject$`item_self`
self$`item_private` <- SpecialObject$`item_private`
self$`item_super` <- SpecialObject$`item_super`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`item_self` <- this_object$`item_self`
self$`item_private` <- this_object$`item_private`
self$`item_super` <- this_object$`item_super`
self
},
#' Validate JSON input with respect to Special

View File

@ -66,16 +66,16 @@ Tag <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of Tag
#'
#' @param TagJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Tag
#' @export
fromJSON = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)
if (!is.null(TagObject$`id`)) {
self$`id` <- TagObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(TagObject$`name`)) {
self$`name` <- TagObject$`name`
if (!is.null(this_object$`name`)) {
self$`name` <- this_object$`name`
}
self
},
@ -104,20 +104,20 @@ Tag <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of Tag
#'
#' @description
#' Deserialize JSON string into an instance of Tag
#'
#' @param TagJson the JSON input
#' @param input_json the JSON input
#' @return the instance of Tag
#' @export
fromJSONString = function(TagJson) {
TagObject <- jsonlite::fromJSON(TagJson)
self$`id` <- TagObject$`id`
self$`name` <- TagObject$`name`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`name` <- this_object$`name`
self
},
#' Validate JSON input with respect to Tag

View File

@ -65,18 +65,18 @@ UpdatePetRequest <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of UpdatePetRequest
#'
#' @param UpdatePetRequestJson the JSON input
#' @param input_json the JSON input
#' @return the instance of UpdatePetRequest
#' @export
fromJSON = function(UpdatePetRequestJson) {
UpdatePetRequestObject <- jsonlite::fromJSON(UpdatePetRequestJson)
if (!is.null(UpdatePetRequestObject$`jsonData`)) {
jsonDataObject <- Pet$new()
jsonDataObject$fromJSON(jsonlite::toJSON(UpdatePetRequestObject$jsonData, auto_unbox = TRUE, digits = NA))
self$`jsonData` <- jsonDataObject
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`jsonData`)) {
jsondata_object <- Pet$new()
jsondata_object$fromJSON(jsonlite::toJSON(this_object$jsonData, auto_unbox = TRUE, digits = NA))
self$`jsonData` <- jsondata_object
}
if (!is.null(UpdatePetRequestObject$`binaryDataN2Information`)) {
self$`binaryDataN2Information` <- UpdatePetRequestObject$`binaryDataN2Information`
if (!is.null(this_object$`binaryDataN2Information`)) {
self$`binaryDataN2Information` <- this_object$`binaryDataN2Information`
}
self
},
@ -105,20 +105,20 @@ UpdatePetRequest <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of UpdatePetRequest
#'
#' @description
#' Deserialize JSON string into an instance of UpdatePetRequest
#'
#' @param UpdatePetRequestJson the JSON input
#' @param input_json the JSON input
#' @return the instance of UpdatePetRequest
#' @export
fromJSONString = function(UpdatePetRequestJson) {
UpdatePetRequestObject <- jsonlite::fromJSON(UpdatePetRequestJson)
self$`jsonData` <- Pet$new()$fromJSON(jsonlite::toJSON(UpdatePetRequestObject$jsonData, auto_unbox = TRUE, digits = NA))
self$`binaryDataN2Information` <- UpdatePetRequestObject$`binaryDataN2Information`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`jsonData` <- Pet$new()$fromJSON(jsonlite::toJSON(this_object$jsonData, auto_unbox = TRUE, digits = NA))
self$`binaryDataN2Information` <- this_object$`binaryDataN2Information`
self
},
#' Validate JSON input with respect to UpdatePetRequest

View File

@ -132,34 +132,34 @@ User <- R6::R6Class(
#' @description
#' Deserialize JSON string into an instance of User
#'
#' @param UserJson the JSON input
#' @param input_json the JSON input
#' @return the instance of User
#' @export
fromJSON = function(UserJson) {
UserObject <- jsonlite::fromJSON(UserJson)
if (!is.null(UserObject$`id`)) {
self$`id` <- UserObject$`id`
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(UserObject$`username`)) {
self$`username` <- UserObject$`username`
if (!is.null(this_object$`username`)) {
self$`username` <- this_object$`username`
}
if (!is.null(UserObject$`firstName`)) {
self$`firstName` <- UserObject$`firstName`
if (!is.null(this_object$`firstName`)) {
self$`firstName` <- this_object$`firstName`
}
if (!is.null(UserObject$`lastName`)) {
self$`lastName` <- UserObject$`lastName`
if (!is.null(this_object$`lastName`)) {
self$`lastName` <- this_object$`lastName`
}
if (!is.null(UserObject$`email`)) {
self$`email` <- UserObject$`email`
if (!is.null(this_object$`email`)) {
self$`email` <- this_object$`email`
}
if (!is.null(UserObject$`password`)) {
self$`password` <- UserObject$`password`
if (!is.null(this_object$`password`)) {
self$`password` <- this_object$`password`
}
if (!is.null(UserObject$`phone`)) {
self$`phone` <- UserObject$`phone`
if (!is.null(this_object$`phone`)) {
self$`phone` <- this_object$`phone`
}
if (!is.null(UserObject$`userStatus`)) {
self$`userStatus` <- UserObject$`userStatus`
if (!is.null(this_object$`userStatus`)) {
self$`userStatus` <- this_object$`userStatus`
}
self
},
@ -230,26 +230,26 @@ User <- R6::R6Class(
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
},
#' Deserialize JSON string into an instance of User
#'
#' @description
#' Deserialize JSON string into an instance of User
#'
#' @param UserJson the JSON input
#' @param input_json the JSON input
#' @return the instance of User
#' @export
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`
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`username` <- this_object$`username`
self$`firstName` <- this_object$`firstName`
self$`lastName` <- this_object$`lastName`
self$`email` <- this_object$`email`
self$`password` <- this_object$`password`
self$`phone` <- this_object$`phone`
self$`userStatus` <- this_object$`userStatus`
self
},
#' Validate JSON input with respect to User

View File

@ -2,36 +2,53 @@
install.packages("petstore_1.0.0.tar.gz",repos=NULL, type="source")
library(petstore)
errorMsg <- "{\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}"
#errorMsg <- '{"code": 404, "message": "Not found"}'
a <- ModelApiResponse$new()$fromJSONString(errorMsg)
dput(a)
var_pet_id <- 1231256 # integer | ID of pet to return
#Find pet by ID
api_instance <- PetApi$new()
# Configure API key authorization: api_key
api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
result <- tryCatch(
api_instance$GetPetById(var_pet_id),
ApiException = function(ex) ex
)
# In case of error, print the error object
if(!is.null(result$ApiException)) {
cat(result$ApiException$toString())
} else {
# deserialized response object
response.object <- result$content
# response headers
response.headers <- result$response$headers
# response status code
response.status.code <- result$response$status_code
}
#json2 <-
#'{"name": "pet", "photoUrls" : ["http://a.com", "http://b.com"]}'
#errorMsg <- "{\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}"
##errorMsg <- '{"code": 404, "message": "Not found"}'
#a <- ModelApiResponse$new()$fromJSONString(errorMsg)
#dput(a)
#
#var_pet_id <- 1231256 # integer | ID of pet to return
#
##Find pet by ID
#api_instance <- PetApi$new()
## Configure API key authorization: api_key
#api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#result <- tryCatch(
# api_instance$GetPetById(var_pet_id),
# ApiException = function(ex) ex
# )
## In case of error, print the error object
#if(!is.null(result$ApiException)) {
# cat(result$ApiException$toString())
#} else {
# # deserialized response object
# response.object <- result$content
# # response headers
# response.headers <- result$response$headers
# # response status code
# response.status.code <- result$response$status_code
#}
json2 <-
'{"name": "pet", "photoUrls" : ["http://a.com", "http://b.com"]}'
jsonlite::minify(json2)
pet_api <- PetApi$new()
pet_id <- 123321
pet <- Pet$new("name_test",
photoUrls = list("photo_test", "second test"),
category = Category$new(id = 450, name = "test_cat"),
id = pet_id,
tags = list(
Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown")
),
status = "available"
)
#jsonlite::minify(pet$toJSONString())
pet$toJSONString()
#json <-
#'[
# {"Name" : "Mario", "Age" : 32, "Occupation" : "Plumber"},

View File

@ -16,9 +16,10 @@ result <- pet_api$AddPet(pet)
test_that("AddPet", {
expect_equal(pet_id, 123321)
#expect_equal(result, NULL)
#expect_equal(pet$toJSONString(), '{"id":123321,"category":{"id":450,"name":"test_cat"},"name":"name_test","photoUrls":["photo_test","second test"],"tags":[{"id":123,"name":"tag_test"},{"id":456,"name":"unknown"}],"status":"available"}')
})
test_that("Test toJSON toJSON fromJSON fromJSONString", {
test_that("Test toJSON toJSONString fromJSON fromJSONString", {
pet0 <- Pet$new()
jsonpet <- pet0$toJSON()
pet2 <- pet0$fromJSON(