Skip to content

Commit

Permalink
[R] minify json in toJSON (#12699)
Browse files Browse the repository at this point in the history
* minify json in toJSON

* update fromjson with better variable naming
  • Loading branch information
wing328 authored Jun 25, 2022
1 parent 29ea48e commit e4b78db
Show file tree
Hide file tree
Showing 19 changed files with 331 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down Expand Up @@ -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}}
Expand Down
44 changes: 22 additions & 22 deletions samples/client/petstore/R/R/allof_tag_api_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/R/R/animal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/R/R/basque_pig.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions samples/client/petstore/R/R/cat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions samples/client/petstore/R/R/cat_all_of.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/R/R/category.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit e4b78db

Please sign in to comment.