Skip to content

Commit 839ed04

Browse files
committed
refactor pr
1 parent 0fba5cb commit 839ed04

File tree

99 files changed

+1542
-1227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1542
-1227
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,32 @@
8686
},
8787

8888
#' @description
89-
#' Serialize {{{classname}}} to JSON string.
89+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
90+
toJSON = function() {
91+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
92+
return(self$toSimpleType())
93+
},
94+
95+
#' @description
96+
#' Convert {{{classname}}} to a base R type
9097
#'
91-
#' @return JSON string representation of the {{{classname}}}.
92-
toJSONString = function() {
98+
#' @return A base R type, e.g. a list or numeric/character array.
99+
toSimpleType = function() {
93100
if (!is.null(self$actual_instance)) {
94-
as.character(jsonlite::minify((self$actual_instance$toJSONString())))
101+
return(self$actual_instance$toSimpleType())
95102
} else {
96103
NULL
97104
}
98105
},
99106

100107
#' @description
101-
#' Serialize {{{classname}}} to JSON.
108+
#' Serialize {{{classname}}} to JSON string.
102109
#'
103-
#' @return JSON representation of the {{{classname}}}.
104-
toJSON = function() {
105-
if (!is.null(self$actual_instance)) {
106-
self$actual_instance$toJSON()
107-
} else {
108-
NULL
109-
}
110+
#' @param ... Parameters passed to `jsonlite::toJSON`
111+
#' @return JSON string representation of the {{{classname}}}.
112+
toJSONString = function(...) {
113+
json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...)
114+
return(as.character(jsonlite::minify(json)))
110115
},
111116
112117
#' @description

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@
3838
},
3939

4040
#' @description
41-
#' To JSON String
42-
#'
43-
#' @return {{{classname}}} in JSON format
41+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
4442
toJSON = function() {
45-
jsonlite::toJSON(private$value, auto_unbox = TRUE)
43+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
44+
return(self$toSimpleType())
45+
},
46+
47+
#' @description
48+
#' Convert {{{classname}}} to a base R type
49+
#'
50+
#' @return A base R type, e.g. a list or numeric/character array.
51+
toSimpleType = function() {
52+
return(private$value)
4653
},
4754

4855
#' @description
@@ -60,10 +67,11 @@
6067
#' @description
6168
#' To JSON String
6269
#'
70+
#' @param ... Parameters passed to `jsonlite::toJSON`
6371
#' @return {{{classname}}} in JSON format
64-
toJSONString = function() {
65-
as.character(jsonlite::toJSON(private$value,
66-
auto_unbox = TRUE))
72+
toJSONString = function(...) {
73+
json <- jsonlite::toJSON(self$toSimpleType(), auto_unbox = TRUE, ...)
74+
return(as.character(jsonlite::minify(json)))
6775
},
6876
6977
#' @description

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@
203203
},
204204
205205
#' @description
206-
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toList()` instead.
206+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
207207
toJSON = function() {
208-
.Deprecated(new = "toList", msg = "Use the '$toList()' method instead since that is more learly named. Use '$toJSONstring()' to get a JSON string")
209-
return(self$toList())
208+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
209+
return(self$toSimpleType())
210210
},
211211
212212
#' @description
@@ -222,6 +222,14 @@
222222
#' df
223223
#' }
224224
toList = function() {
225+
return(self$toSimpleType())
226+
},
227+
228+
#' @description
229+
#' Convert {{{classname}}} to a base R type
230+
#'
231+
#' @return A base R type, e.g. a list or numeric/character array.
232+
toSimpleType = function() {
225233
{{classname}}Object <- list()
226234
{{#vars}}
227235
if (!is.null(self$`{{name}}`)) {
@@ -232,15 +240,15 @@
232240
self$`{{name}}`
233241
{{/isPrimitiveType}}
234242
{{^isPrimitiveType}}
235-
lapply(self$`{{name}}`, function(x) x$toList())
243+
lapply(self$`{{name}}`, function(x) x$toSimpleType())
236244
{{/isPrimitiveType}}
237245
{{/isArray}}
238246
{{#isMap}}
239247
{{#isPrimitiveType}}
240248
self$`{{name}}`
241249
{{/isPrimitiveType}}
242250
{{^isPrimitiveType}}
243-
lapply(self$`{{name}}`, function(x) x$toList())
251+
lapply(self$`{{name}}`, function(x) x$toSimpleType())
244252
{{/isPrimitiveType}}
245253
{{/isMap}}
246254
{{/isContainer}}
@@ -249,7 +257,7 @@
249257
self$`{{name}}`
250258
{{/isPrimitiveType}}
251259
{{^isPrimitiveType}}
252-
self$`{{name}}`$toList()
260+
self$`{{name}}`$toSimpleType()
253261
{{/isPrimitiveType}}
254262
{{/isContainer}}
255263
}
@@ -320,23 +328,17 @@
320328
#' @description
321329
#' To JSON String
322330
#'
323-
#' @param minify Logical. If `TRUE` remove all indentation and white space
324331
#' @param ... Parameters passed to `jsonlite::toJSON`
325332
#' @return {{{classname}}} in JSON format
326-
toJSONString = function(minify = TRUE, ...) {
327-
json_obj <- self$toList()
328-
333+
toJSONString = function(...) {
334+
simple <- self$toSimpleType()
329335
{{#isAdditionalPropertiesTrue}}
330336
for (key in names(self$additional_properties)) {
331-
json_obj[[key]] <- self$additional_properties[[key]]
337+
simple[[key]] <- self$additional_properties[[key]]
332338
}
333339
{{/isAdditionalPropertiesTrue}}
334-
335-
json_string <- jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA, ...)
336-
if (minify) {
337-
json_string <- jsonlite::minify(json_string)
338-
}
339-
return(as.character(json_string))
340+
json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...)
341+
return(as.character(jsonlite::minify(json)))
340342
},
341343
342344
#' @description

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,35 @@
139139
140140
#' @description
141141
#' Serialize {{{classname}}} to JSON string.
142-
#'
142+
#'
143+
#' @param ... Parameters passed to `jsonlite::toJSON`
143144
#' @return JSON string representation of the {{{classname}}}.
144-
toJSONString = function() {
145+
toJSONString = function(...) {
146+
simple <- self$toSimpleType()
145147
if (!is.null(self$actual_instance)) {
146-
as.character(jsonlite::minify(self$actual_instance$toJSONString()))
148+
json <- jsonlite::toJSON(simple, auto_unbox = TRUE, ...)
149+
return(as.character(jsonlite::minify(json)))
147150
} else {
148-
NULL
151+
return(NULL)
149152
}
150153
},
151154
152155
#' @description
153-
#' Serialize {{{classname}}} to JSON.
154-
#'
155-
#' @return JSON representation of the {{{classname}}}.
156+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
156157
toJSON = function() {
158+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
159+
return(self$toSimpleType())
160+
},
161+
162+
#' @description
163+
#' Convert {{{classname}}} to a base R type
164+
#'
165+
#' @return A base R type, e.g. a list or numeric/character array.
166+
toSimpleType = function() {
157167
if (!is.null(self$actual_instance)) {
158-
self$actual_instance$toJSON()
168+
return(self$actual_instance$toSimpleType())
159169
} else {
160-
NULL
170+
return(NULL)
161171
}
162172
},
163173

samples/client/echo_api/r/R/bird.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Bird <- R6::R6Class(
4040
},
4141

4242
#' @description
43-
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toList()` instead.
43+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
4444
toJSON = function() {
45-
.Deprecated(new = "toList", msg = "Use the '$toList()' method instead since that is more learly named. Use '$toJSONstring()' to get a JSON string")
46-
return(self$toList())
45+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
46+
return(self$toSimpleType())
4747
},
4848

4949
#' @description
@@ -59,6 +59,14 @@ Bird <- R6::R6Class(
5959
#' df
6060
#' }
6161
toList = function() {
62+
return(self$toSimpleType())
63+
},
64+
65+
#' @description
66+
#' Convert Bird to a base R type
67+
#'
68+
#' @return A base R type, e.g. a list or numeric/character array.
69+
toSimpleType = function() {
6270
BirdObject <- list()
6371
if (!is.null(self$`size`)) {
6472
BirdObject[["size"]] <-
@@ -90,18 +98,12 @@ Bird <- R6::R6Class(
9098
#' @description
9199
#' To JSON String
92100
#'
93-
#' @param minify Logical. If `TRUE` remove all indentation and white space
94101
#' @param ... Parameters passed to `jsonlite::toJSON`
95102
#' @return Bird in JSON format
96-
toJSONString = function(minify = TRUE, ...) {
97-
json_obj <- self$toList()
98-
99-
100-
json_string <- jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA, ...)
101-
if (minify) {
102-
json_string <- jsonlite::minify(json_string)
103-
}
104-
return(as.character(json_string))
103+
toJSONString = function(...) {
104+
simple <- self$toSimpleType()
105+
json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...)
106+
return(as.character(jsonlite::minify(json)))
105107
},
106108

107109
#' @description

samples/client/echo_api/r/R/category.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Category <- R6::R6Class(
4040
},
4141

4242
#' @description
43-
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toList()` instead.
43+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
4444
toJSON = function() {
45-
.Deprecated(new = "toList", msg = "Use the '$toList()' method instead since that is more learly named. Use '$toJSONstring()' to get a JSON string")
46-
return(self$toList())
45+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
46+
return(self$toSimpleType())
4747
},
4848

4949
#' @description
@@ -59,6 +59,14 @@ Category <- R6::R6Class(
5959
#' df
6060
#' }
6161
toList = function() {
62+
return(self$toSimpleType())
63+
},
64+
65+
#' @description
66+
#' Convert Category to a base R type
67+
#'
68+
#' @return A base R type, e.g. a list or numeric/character array.
69+
toSimpleType = function() {
6270
CategoryObject <- list()
6371
if (!is.null(self$`id`)) {
6472
CategoryObject[["id"]] <-
@@ -90,18 +98,12 @@ Category <- R6::R6Class(
9098
#' @description
9199
#' To JSON String
92100
#'
93-
#' @param minify Logical. If `TRUE` remove all indentation and white space
94101
#' @param ... Parameters passed to `jsonlite::toJSON`
95102
#' @return Category in JSON format
96-
toJSONString = function(minify = TRUE, ...) {
97-
json_obj <- self$toList()
98-
99-
100-
json_string <- jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA, ...)
101-
if (minify) {
102-
json_string <- jsonlite::minify(json_string)
103-
}
104-
return(as.character(json_string))
103+
toJSONString = function(...) {
104+
simple <- self$toSimpleType()
105+
json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...)
106+
return(as.character(jsonlite::minify(json)))
105107
},
106108

107109
#' @description

samples/client/echo_api/r/R/data_query.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ DataQuery <- R6::R6Class(
6767
},
6868

6969
#' @description
70-
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toList()` instead.
70+
#' Convert to a list. This method was misnamed, it actually returns a list. Use `toSimpleType()` instead.
7171
toJSON = function() {
72-
.Deprecated(new = "toList", msg = "Use the '$toList()' method instead since that is more learly named. Use '$toJSONstring()' to get a JSON string")
73-
return(self$toList())
72+
.Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more learly named. Use '$toJSONString()' to get a JSON string")
73+
return(self$toSimpleType())
7474
},
7575

7676
#' @description
@@ -86,6 +86,14 @@ DataQuery <- R6::R6Class(
8686
#' df
8787
#' }
8888
toList = function() {
89+
return(self$toSimpleType())
90+
},
91+
92+
#' @description
93+
#' Convert DataQuery to a base R type
94+
#'
95+
#' @return A base R type, e.g. a list or numeric/character array.
96+
toSimpleType = function() {
8997
DataQueryObject <- list()
9098
if (!is.null(self$`id`)) {
9199
DataQueryObject[["id"]] <-
@@ -138,18 +146,12 @@ DataQuery <- R6::R6Class(
138146
#' @description
139147
#' To JSON String
140148
#'
141-
#' @param minify Logical. If `TRUE` remove all indentation and white space
142149
#' @param ... Parameters passed to `jsonlite::toJSON`
143150
#' @return DataQuery in JSON format
144-
toJSONString = function(minify = TRUE, ...) {
145-
json_obj <- self$toList()
146-
147-
148-
json_string <- jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA, ...)
149-
if (minify) {
150-
json_string <- jsonlite::minify(json_string)
151-
}
152-
return(as.character(json_string))
151+
toJSONString = function(...) {
152+
simple <- self$toSimpleType()
153+
json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...)
154+
return(as.character(jsonlite::minify(json)))
153155
},
154156

155157
#' @description

0 commit comments

Comments
 (0)