Skip to content

Commit e4b78db

Browse files
authored
[R] minify json in toJSON (#12699)
* minify json in toJSON * update fromjson with better variable naming
1 parent 29ea48e commit e4b78db

19 files changed

Lines changed: 331 additions & 313 deletions

File tree

modules/openapi-generator/src/main/resources/r/modelGeneric.mustache

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,24 @@
176176
#' @description
177177
#' Deserialize JSON string into an instance of {{{classname}}}
178178
#'
179-
#' @param {{classname}}Json the JSON input
179+
#' @param input_json the JSON input
180180
#' @return the instance of {{{classname}}}
181181
#' @export
182-
fromJSON = function({{classname}}Json) {
183-
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
182+
fromJSON = function(input_json) {
183+
this_object <- jsonlite::fromJSON(input_json)
184184
{{#vars}}
185-
if (!is.null({{classname}}Object$`{{baseName}}`)) {
185+
if (!is.null(this_object$`{{baseName}}`)) {
186186
{{#isContainer}}
187-
self$`{{name}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
187+
self$`{{name}}` <- ApiClient$new()$deserializeObj(this_object$`{{baseName}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
188188
{{/isContainer}}
189189
{{^isContainer}}
190190
{{#isPrimitiveType}}
191-
self$`{{name}}` <- {{classname}}Object$`{{baseName}}`
191+
self$`{{name}}` <- this_object$`{{baseName}}`
192192
{{/isPrimitiveType}}
193193
{{^isPrimitiveType}}
194-
{{name}}Object <- {{dataType}}$new()
195-
{{name}}Object$fromJSON(jsonlite::toJSON({{classname}}Object${{baseName}}, auto_unbox = TRUE, digits = NA))
196-
self$`{{name}}` <- {{name}}Object
194+
{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object <- {{dataType}}$new()
195+
{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object$fromJSON(jsonlite::toJSON(this_object${{baseName}}, auto_unbox = TRUE, digits = NA))
196+
self$`{{name}}` <- {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}_object
197197
{{/isPrimitiveType}}
198198
{{/isContainer}}
199199
}
@@ -266,29 +266,29 @@
266266
{{/vars}}
267267
)
268268
jsoncontent <- paste(jsoncontent, collapse = ",")
269-
paste('{', jsoncontent, '}', sep = "")
269+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
270270
},
271271
#' Deserialize JSON string into an instance of {{{classname}}}
272272
#'
273273
#' @description
274274
#' Deserialize JSON string into an instance of {{{classname}}}
275275
#'
276-
#' @param {{classname}}Json the JSON input
276+
#' @param input_json the JSON input
277277
#' @return the instance of {{{classname}}}
278278
#' @export
279-
fromJSONString = function({{classname}}Json) {
280-
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
279+
fromJSONString = function(input_json) {
280+
this_object <- jsonlite::fromJSON(input_json)
281281
{{#vars}}
282282
{{! AAPI - added condition for handling container type of parameters, map and array}}
283283
{{#isContainer}}
284-
self$`{{name}}` <- ApiClient$new()$deserializeObj({{classname}}Object$`{{name}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
284+
self$`{{name}}` <- ApiClient$new()$deserializeObj(this_object$`{{name}}`, "{{dataType}}", loadNamespace("{{packageName}}"))
285285
{{/isContainer}}
286286
{{^isContainer}}
287287
{{#isPrimitiveType}}
288-
self$`{{name}}` <- {{classname}}Object$`{{name}}`
288+
self$`{{name}}` <- this_object$`{{name}}`
289289
{{/isPrimitiveType}}
290290
{{^isPrimitiveType}}
291-
self$`{{name}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON({{classname}}Object${{name}}, auto_unbox = TRUE, digits = NA))
291+
self$`{{name}}` <- {{dataType}}$new()$fromJSON(jsonlite::toJSON(this_object${{name}}, auto_unbox = TRUE, digits = NA))
292292
{{/isPrimitiveType}}
293293
{{/isContainer}}
294294
{{/vars}}

samples/client/petstore/R/R/allof_tag_api_response.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,25 @@ AllofTagApiResponse <- R6::R6Class(
9999
#' @description
100100
#' Deserialize JSON string into an instance of AllofTagApiResponse
101101
#'
102-
#' @param AllofTagApiResponseJson the JSON input
102+
#' @param input_json the JSON input
103103
#' @return the instance of AllofTagApiResponse
104104
#' @export
105-
fromJSON = function(AllofTagApiResponseJson) {
106-
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
107-
if (!is.null(AllofTagApiResponseObject$`id`)) {
108-
self$`id` <- AllofTagApiResponseObject$`id`
105+
fromJSON = function(input_json) {
106+
this_object <- jsonlite::fromJSON(input_json)
107+
if (!is.null(this_object$`id`)) {
108+
self$`id` <- this_object$`id`
109109
}
110-
if (!is.null(AllofTagApiResponseObject$`name`)) {
111-
self$`name` <- AllofTagApiResponseObject$`name`
110+
if (!is.null(this_object$`name`)) {
111+
self$`name` <- this_object$`name`
112112
}
113-
if (!is.null(AllofTagApiResponseObject$`code`)) {
114-
self$`code` <- AllofTagApiResponseObject$`code`
113+
if (!is.null(this_object$`code`)) {
114+
self$`code` <- this_object$`code`
115115
}
116-
if (!is.null(AllofTagApiResponseObject$`type`)) {
117-
self$`type` <- AllofTagApiResponseObject$`type`
116+
if (!is.null(this_object$`type`)) {
117+
self$`type` <- this_object$`type`
118118
}
119-
if (!is.null(AllofTagApiResponseObject$`message`)) {
120-
self$`message` <- AllofTagApiResponseObject$`message`
119+
if (!is.null(this_object$`message`)) {
120+
self$`message` <- this_object$`message`
121121
}
122122
self
123123
},
@@ -167,23 +167,23 @@ AllofTagApiResponse <- R6::R6Class(
167167
)}
168168
)
169169
jsoncontent <- paste(jsoncontent, collapse = ",")
170-
paste('{', jsoncontent, '}', sep = "")
170+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
171171
},
172172
#' Deserialize JSON string into an instance of AllofTagApiResponse
173173
#'
174174
#' @description
175175
#' Deserialize JSON string into an instance of AllofTagApiResponse
176176
#'
177-
#' @param AllofTagApiResponseJson the JSON input
177+
#' @param input_json the JSON input
178178
#' @return the instance of AllofTagApiResponse
179179
#' @export
180-
fromJSONString = function(AllofTagApiResponseJson) {
181-
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
182-
self$`id` <- AllofTagApiResponseObject$`id`
183-
self$`name` <- AllofTagApiResponseObject$`name`
184-
self$`code` <- AllofTagApiResponseObject$`code`
185-
self$`type` <- AllofTagApiResponseObject$`type`
186-
self$`message` <- AllofTagApiResponseObject$`message`
180+
fromJSONString = function(input_json) {
181+
this_object <- jsonlite::fromJSON(input_json)
182+
self$`id` <- this_object$`id`
183+
self$`name` <- this_object$`name`
184+
self$`code` <- this_object$`code`
185+
self$`type` <- this_object$`type`
186+
self$`message` <- this_object$`message`
187187
self
188188
},
189189
#' Validate JSON input with respect to AllofTagApiResponse

samples/client/petstore/R/R/animal.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ Animal <- R6::R6Class(
6666
#' @description
6767
#' Deserialize JSON string into an instance of Animal
6868
#'
69-
#' @param AnimalJson the JSON input
69+
#' @param input_json the JSON input
7070
#' @return the instance of Animal
7171
#' @export
72-
fromJSON = function(AnimalJson) {
73-
AnimalObject <- jsonlite::fromJSON(AnimalJson)
74-
if (!is.null(AnimalObject$`className`)) {
75-
self$`className` <- AnimalObject$`className`
72+
fromJSON = function(input_json) {
73+
this_object <- jsonlite::fromJSON(input_json)
74+
if (!is.null(this_object$`className`)) {
75+
self$`className` <- this_object$`className`
7676
}
77-
if (!is.null(AnimalObject$`color`)) {
78-
self$`color` <- AnimalObject$`color`
77+
if (!is.null(this_object$`color`)) {
78+
self$`color` <- this_object$`color`
7979
}
8080
self
8181
},
@@ -104,20 +104,20 @@ Animal <- R6::R6Class(
104104
)}
105105
)
106106
jsoncontent <- paste(jsoncontent, collapse = ",")
107-
paste('{', jsoncontent, '}', sep = "")
107+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
108108
},
109109
#' Deserialize JSON string into an instance of Animal
110110
#'
111111
#' @description
112112
#' Deserialize JSON string into an instance of Animal
113113
#'
114-
#' @param AnimalJson the JSON input
114+
#' @param input_json the JSON input
115115
#' @return the instance of Animal
116116
#' @export
117-
fromJSONString = function(AnimalJson) {
118-
AnimalObject <- jsonlite::fromJSON(AnimalJson)
119-
self$`className` <- AnimalObject$`className`
120-
self$`color` <- AnimalObject$`color`
117+
fromJSONString = function(input_json) {
118+
this_object <- jsonlite::fromJSON(input_json)
119+
self$`className` <- this_object$`className`
120+
self$`color` <- this_object$`color`
121121
self
122122
},
123123
#' Validate JSON input with respect to Animal

samples/client/petstore/R/R/basque_pig.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ BasquePig <- R6::R6Class(
6666
#' @description
6767
#' Deserialize JSON string into an instance of BasquePig
6868
#'
69-
#' @param BasquePigJson the JSON input
69+
#' @param input_json the JSON input
7070
#' @return the instance of BasquePig
7171
#' @export
72-
fromJSON = function(BasquePigJson) {
73-
BasquePigObject <- jsonlite::fromJSON(BasquePigJson)
74-
if (!is.null(BasquePigObject$`className`)) {
75-
self$`className` <- BasquePigObject$`className`
72+
fromJSON = function(input_json) {
73+
this_object <- jsonlite::fromJSON(input_json)
74+
if (!is.null(this_object$`className`)) {
75+
self$`className` <- this_object$`className`
7676
}
77-
if (!is.null(BasquePigObject$`color`)) {
78-
self$`color` <- BasquePigObject$`color`
77+
if (!is.null(this_object$`color`)) {
78+
self$`color` <- this_object$`color`
7979
}
8080
self
8181
},
@@ -104,20 +104,20 @@ BasquePig <- R6::R6Class(
104104
)}
105105
)
106106
jsoncontent <- paste(jsoncontent, collapse = ",")
107-
paste('{', jsoncontent, '}', sep = "")
107+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
108108
},
109109
#' Deserialize JSON string into an instance of BasquePig
110110
#'
111111
#' @description
112112
#' Deserialize JSON string into an instance of BasquePig
113113
#'
114-
#' @param BasquePigJson the JSON input
114+
#' @param input_json the JSON input
115115
#' @return the instance of BasquePig
116116
#' @export
117-
fromJSONString = function(BasquePigJson) {
118-
BasquePigObject <- jsonlite::fromJSON(BasquePigJson)
119-
self$`className` <- BasquePigObject$`className`
120-
self$`color` <- BasquePigObject$`color`
117+
fromJSONString = function(input_json) {
118+
this_object <- jsonlite::fromJSON(input_json)
119+
self$`className` <- this_object$`className`
120+
self$`color` <- this_object$`color`
121121
self
122122
},
123123
#' Validate JSON input with respect to BasquePig

samples/client/petstore/R/R/cat.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ Cat <- R6::R6Class(
7878
#' @description
7979
#' Deserialize JSON string into an instance of Cat
8080
#'
81-
#' @param CatJson the JSON input
81+
#' @param input_json the JSON input
8282
#' @return the instance of Cat
8383
#' @export
84-
fromJSON = function(CatJson) {
85-
CatObject <- jsonlite::fromJSON(CatJson)
86-
if (!is.null(CatObject$`className`)) {
87-
self$`className` <- CatObject$`className`
84+
fromJSON = function(input_json) {
85+
this_object <- jsonlite::fromJSON(input_json)
86+
if (!is.null(this_object$`className`)) {
87+
self$`className` <- this_object$`className`
8888
}
89-
if (!is.null(CatObject$`color`)) {
90-
self$`color` <- CatObject$`color`
89+
if (!is.null(this_object$`color`)) {
90+
self$`color` <- this_object$`color`
9191
}
92-
if (!is.null(CatObject$`declawed`)) {
93-
self$`declawed` <- CatObject$`declawed`
92+
if (!is.null(this_object$`declawed`)) {
93+
self$`declawed` <- this_object$`declawed`
9494
}
9595
self
9696
},
@@ -126,21 +126,21 @@ Cat <- R6::R6Class(
126126
)}
127127
)
128128
jsoncontent <- paste(jsoncontent, collapse = ",")
129-
paste('{', jsoncontent, '}', sep = "")
129+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
130130
},
131131
#' Deserialize JSON string into an instance of Cat
132132
#'
133133
#' @description
134134
#' Deserialize JSON string into an instance of Cat
135135
#'
136-
#' @param CatJson the JSON input
136+
#' @param input_json the JSON input
137137
#' @return the instance of Cat
138138
#' @export
139-
fromJSONString = function(CatJson) {
140-
CatObject <- jsonlite::fromJSON(CatJson)
141-
self$`className` <- CatObject$`className`
142-
self$`color` <- CatObject$`color`
143-
self$`declawed` <- CatObject$`declawed`
139+
fromJSONString = function(input_json) {
140+
this_object <- jsonlite::fromJSON(input_json)
141+
self$`className` <- this_object$`className`
142+
self$`color` <- this_object$`color`
143+
self$`declawed` <- this_object$`declawed`
144144
self
145145
},
146146
#' Validate JSON input with respect to Cat

samples/client/petstore/R/R/cat_all_of.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ CatAllOf <- R6::R6Class(
5555
#' @description
5656
#' Deserialize JSON string into an instance of CatAllOf
5757
#'
58-
#' @param CatAllOfJson the JSON input
58+
#' @param input_json the JSON input
5959
#' @return the instance of CatAllOf
6060
#' @export
61-
fromJSON = function(CatAllOfJson) {
62-
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
63-
if (!is.null(CatAllOfObject$`declawed`)) {
64-
self$`declawed` <- CatAllOfObject$`declawed`
61+
fromJSON = function(input_json) {
62+
this_object <- jsonlite::fromJSON(input_json)
63+
if (!is.null(this_object$`declawed`)) {
64+
self$`declawed` <- this_object$`declawed`
6565
}
6666
self
6767
},
@@ -83,19 +83,19 @@ CatAllOf <- R6::R6Class(
8383
)}
8484
)
8585
jsoncontent <- paste(jsoncontent, collapse = ",")
86-
paste('{', jsoncontent, '}', sep = "")
86+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
8787
},
8888
#' Deserialize JSON string into an instance of CatAllOf
8989
#'
9090
#' @description
9191
#' Deserialize JSON string into an instance of CatAllOf
9292
#'
93-
#' @param CatAllOfJson the JSON input
93+
#' @param input_json the JSON input
9494
#' @return the instance of CatAllOf
9595
#' @export
96-
fromJSONString = function(CatAllOfJson) {
97-
CatAllOfObject <- jsonlite::fromJSON(CatAllOfJson)
98-
self$`declawed` <- CatAllOfObject$`declawed`
96+
fromJSONString = function(input_json) {
97+
this_object <- jsonlite::fromJSON(input_json)
98+
self$`declawed` <- this_object$`declawed`
9999
self
100100
},
101101
#' Validate JSON input with respect to CatAllOf

samples/client/petstore/R/R/category.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ Category <- R6::R6Class(
6666
#' @description
6767
#' Deserialize JSON string into an instance of Category
6868
#'
69-
#' @param CategoryJson the JSON input
69+
#' @param input_json the JSON input
7070
#' @return the instance of Category
7171
#' @export
72-
fromJSON = function(CategoryJson) {
73-
CategoryObject <- jsonlite::fromJSON(CategoryJson)
74-
if (!is.null(CategoryObject$`id`)) {
75-
self$`id` <- CategoryObject$`id`
72+
fromJSON = function(input_json) {
73+
this_object <- jsonlite::fromJSON(input_json)
74+
if (!is.null(this_object$`id`)) {
75+
self$`id` <- this_object$`id`
7676
}
77-
if (!is.null(CategoryObject$`name`)) {
78-
self$`name` <- CategoryObject$`name`
77+
if (!is.null(this_object$`name`)) {
78+
self$`name` <- this_object$`name`
7979
}
8080
self
8181
},
@@ -104,20 +104,20 @@ Category <- R6::R6Class(
104104
)}
105105
)
106106
jsoncontent <- paste(jsoncontent, collapse = ",")
107-
paste('{', jsoncontent, '}', sep = "")
107+
jsonlite::minify(paste('{', jsoncontent, '}', sep = ""))
108108
},
109109
#' Deserialize JSON string into an instance of Category
110110
#'
111111
#' @description
112112
#' Deserialize JSON string into an instance of Category
113113
#'
114-
#' @param CategoryJson the JSON input
114+
#' @param input_json the JSON input
115115
#' @return the instance of Category
116116
#' @export
117-
fromJSONString = function(CategoryJson) {
118-
CategoryObject <- jsonlite::fromJSON(CategoryJson)
119-
self$`id` <- CategoryObject$`id`
120-
self$`name` <- CategoryObject$`name`
117+
fromJSONString = function(input_json) {
118+
this_object <- jsonlite::fromJSON(input_json)
119+
self$`id` <- this_object$`id`
120+
self$`name` <- this_object$`name`
121121
self
122122
},
123123
#' Validate JSON input with respect to Category

0 commit comments

Comments
 (0)