Skip to content

Commit c3970d7

Browse files
authored
update r model doc (#12676)
1 parent 7d768f2 commit c3970d7

17 files changed

Lines changed: 805 additions & 103 deletions

File tree

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

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
{{#model}}
33
#' @docType class
44
#' @title {{classname}}
5-
#'
65
#' @description {{classname}} Class
7-
#'
86
#' @format An \code{R6Class} generator object
9-
#'
107
{{#vars}}
118
#' @field {{name}} {{title}} {{#isContainer}}{{#isArray}}list( {{/isArray}}{{#isMap}}named list( {{/isMap}}{{/isContainer}}{{^isPrimitiveType}}\link{{=<% %>=}}{<%/isPrimitiveType%><%={{ }}=%>{{#isContainer}}{{#items}}{{dataType}}{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}{{=<% %>=}}<%^isPrimitiveType%>}<%={{ }}=%>{{/isPrimitiveType}}{{#isContainer}}{{#isArray}} ){{/isArray}}{{#isMap}} ){{/isMap}}{{/isContainer}} {{^required}}[optional]{{/required}}
12-
#'
139
{{/vars}}
1410
#' @importFrom R6 R6Class
1511
#' @importFrom jsonlite fromJSON toJSON
@@ -27,6 +23,19 @@
2723
{{#vars}}
2824
`{{{name}}}` = NULL,
2925
{{/vars}}
26+
#' Initialize a new {{{classname}}} class.
27+
#'
28+
#' @description
29+
#' Initialize a new {{{classname}}} class.
30+
#'
31+
{{#requiredVars}}
32+
#' @param {{name}} {{{description}}}{{^description}}{{{name}}}{{/description}}
33+
{{/requiredVars}}
34+
{{#optionalVars}}
35+
#' @param {{name}} {{{description}}}{{^description}}{{{name}}}{{/description}}{{#defaultValue}}. Default to {{{.}}}.{{/defaultValue}}
36+
{{/optionalVars}}
37+
#' @param ... Other optional arguments.
38+
#' @export
3039
initialize = function(
3140
{{#requiredVars}}`{{name}}`, {{/requiredVars}}{{#optionalVars}}`{{name}}`={{{defaultValue}}}{{^defaultValue}}NULL{{/defaultValue}}, {{/optionalVars}}...
3241
) {
@@ -119,6 +128,13 @@
119128
}
120129
{{/optionalVars}}
121130
},
131+
#' To JSON string
132+
#'
133+
#' @description
134+
#' To JSON String
135+
#'
136+
#' @return {{{classname}}} in JSON format
137+
#' @export
122138
toJSON = function() {
123139
{{classname}}Object <- list()
124140
{{#vars}}
@@ -155,6 +171,14 @@
155171
156172
{{classname}}Object
157173
},
174+
#' Deserialize JSON string into an instance of {{{classname}}}
175+
#'
176+
#' @description
177+
#' Deserialize JSON string into an instance of {{{classname}}}
178+
#'
179+
#' @param {{classname}}Json the JSON input
180+
#' @return the instance of {{{classname}}}
181+
#' @export
158182
fromJSON = function({{classname}}Json) {
159183
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
160184
{{#vars}}
@@ -176,6 +200,13 @@
176200
{{/vars}}
177201
self
178202
},
203+
#' To JSON string
204+
#'
205+
#' @description
206+
#' To JSON String
207+
#'
208+
#' @return {{{classname}}} in JSON format
209+
#' @export
179210
toJSONString = function() {
180211
jsoncontent <- c(
181212
{{#vars}}
@@ -237,6 +268,14 @@
237268
jsoncontent <- paste(jsoncontent, collapse = ",")
238269
paste('{', jsoncontent, '}', sep = "")
239270
},
271+
#' Deserialize JSON string into an instance of {{{classname}}}
272+
#'
273+
#' @description
274+
#' Deserialize JSON string into an instance of {{{classname}}}
275+
#'
276+
#' @param {{classname}}Json the JSON input
277+
#' @return the instance of {{{classname}}}
278+
#' @export
240279
fromJSONString = function({{classname}}Json) {
241280
{{classname}}Object <- jsonlite::fromJSON({{classname}}Json)
242281
{{#vars}}
@@ -255,6 +294,13 @@
255294
{{/vars}}
256295
self
257296
},
297+
#' Validate JSON input with respect to {{classname}}
298+
#'
299+
#' @description
300+
#' Validate JSON input with respect to {{classname}} and throw an exception if invalid
301+
#'
302+
#' @param input the JSON input
303+
#' @export
258304
validateJSON = function(input) {
259305
input_json <- jsonlite::fromJSON(input)
260306
{{#requiredVars}}

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@
88

99
#' @docType class
1010
#' @title AllofTagApiResponse
11-
#'
1211
#' @description AllofTagApiResponse Class
13-
#'
1412
#' @format An \code{R6Class} generator object
15-
#'
1613
#' @field id integer [optional]
17-
#'
1814
#' @field name character [optional]
19-
#'
2015
#' @field code integer [optional]
21-
#'
2216
#' @field type character [optional]
23-
#'
2417
#' @field message character [optional]
25-
#'
2618
#' @importFrom R6 R6Class
2719
#' @importFrom jsonlite fromJSON toJSON
2820
#' @export
@@ -34,6 +26,18 @@ AllofTagApiResponse <- R6::R6Class(
3426
`code` = NULL,
3527
`type` = NULL,
3628
`message` = NULL,
29+
#' Initialize a new AllofTagApiResponse class.
30+
#'
31+
#' @description
32+
#' Initialize a new AllofTagApiResponse class.
33+
#'
34+
#' @param id id
35+
#' @param name name
36+
#' @param code code
37+
#' @param type type
38+
#' @param message message
39+
#' @param ... Other optional arguments.
40+
#' @export
3741
initialize = function(
3842
`id`=NULL, `name`=NULL, `code`=NULL, `type`=NULL, `message`=NULL, ...
3943
) {
@@ -58,6 +62,13 @@ AllofTagApiResponse <- R6::R6Class(
5862
self$`message` <- `message`
5963
}
6064
},
65+
#' To JSON string
66+
#'
67+
#' @description
68+
#' To JSON String
69+
#'
70+
#' @return AllofTagApiResponse in JSON format
71+
#' @export
6172
toJSON = function() {
6273
AllofTagApiResponseObject <- list()
6374
if (!is.null(self$`id`)) {
@@ -83,6 +94,14 @@ AllofTagApiResponse <- R6::R6Class(
8394

8495
AllofTagApiResponseObject
8596
},
97+
#' Deserialize JSON string into an instance of AllofTagApiResponse
98+
#'
99+
#' @description
100+
#' Deserialize JSON string into an instance of AllofTagApiResponse
101+
#'
102+
#' @param AllofTagApiResponseJson the JSON input
103+
#' @return the instance of AllofTagApiResponse
104+
#' @export
86105
fromJSON = function(AllofTagApiResponseJson) {
87106
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
88107
if (!is.null(AllofTagApiResponseObject$`id`)) {
@@ -102,6 +121,13 @@ AllofTagApiResponse <- R6::R6Class(
102121
}
103122
self
104123
},
124+
#' To JSON string
125+
#'
126+
#' @description
127+
#' To JSON String
128+
#'
129+
#' @return AllofTagApiResponse in JSON format
130+
#' @export
105131
toJSONString = function() {
106132
jsoncontent <- c(
107133
if (!is.null(self$`id`)) {
@@ -143,6 +169,14 @@ AllofTagApiResponse <- R6::R6Class(
143169
jsoncontent <- paste(jsoncontent, collapse = ",")
144170
paste('{', jsoncontent, '}', sep = "")
145171
},
172+
#' Deserialize JSON string into an instance of AllofTagApiResponse
173+
#'
174+
#' @description
175+
#' Deserialize JSON string into an instance of AllofTagApiResponse
176+
#'
177+
#' @param AllofTagApiResponseJson the JSON input
178+
#' @return the instance of AllofTagApiResponse
179+
#' @export
146180
fromJSONString = function(AllofTagApiResponseJson) {
147181
AllofTagApiResponseObject <- jsonlite::fromJSON(AllofTagApiResponseJson)
148182
self$`id` <- AllofTagApiResponseObject$`id`
@@ -152,6 +186,13 @@ AllofTagApiResponse <- R6::R6Class(
152186
self$`message` <- AllofTagApiResponseObject$`message`
153187
self
154188
},
189+
#' Validate JSON input with respect to AllofTagApiResponse
190+
#'
191+
#' @description
192+
#' Validate JSON input with respect to AllofTagApiResponse and throw an exception if invalid
193+
#'
194+
#' @param input the JSON input
195+
#' @export
155196
validateJSON = function(input) {
156197
input_json <- jsonlite::fromJSON(input)
157198
}

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88

99
#' @docType class
1010
#' @title Animal
11-
#'
1211
#' @description Animal Class
13-
#'
1412
#' @format An \code{R6Class} generator object
15-
#'
1613
#' @field className character
17-
#'
1814
#' @field color character [optional]
19-
#'
2015
#' @importFrom R6 R6Class
2116
#' @importFrom jsonlite fromJSON toJSON
2217
#' @export
@@ -25,6 +20,15 @@ Animal <- R6::R6Class(
2520
public = list(
2621
`className` = NULL,
2722
`color` = NULL,
23+
#' Initialize a new Animal class.
24+
#'
25+
#' @description
26+
#' Initialize a new Animal class.
27+
#'
28+
#' @param className className
29+
#' @param color color. Default to 'red'.
30+
#' @param ... Other optional arguments.
31+
#' @export
2832
initialize = function(
2933
`className`, `color`='red', ...
3034
) {
@@ -37,6 +41,13 @@ Animal <- R6::R6Class(
3741
self$`color` <- `color`
3842
}
3943
},
44+
#' To JSON string
45+
#'
46+
#' @description
47+
#' To JSON String
48+
#'
49+
#' @return Animal in JSON format
50+
#' @export
4051
toJSON = function() {
4152
AnimalObject <- list()
4253
if (!is.null(self$`className`)) {
@@ -50,6 +61,14 @@ Animal <- R6::R6Class(
5061

5162
AnimalObject
5263
},
64+
#' Deserialize JSON string into an instance of Animal
65+
#'
66+
#' @description
67+
#' Deserialize JSON string into an instance of Animal
68+
#'
69+
#' @param AnimalJson the JSON input
70+
#' @return the instance of Animal
71+
#' @export
5372
fromJSON = function(AnimalJson) {
5473
AnimalObject <- jsonlite::fromJSON(AnimalJson)
5574
if (!is.null(AnimalObject$`className`)) {
@@ -60,6 +79,13 @@ Animal <- R6::R6Class(
6079
}
6180
self
6281
},
82+
#' To JSON string
83+
#'
84+
#' @description
85+
#' To JSON String
86+
#'
87+
#' @return Animal in JSON format
88+
#' @export
6389
toJSONString = function() {
6490
jsoncontent <- c(
6591
if (!is.null(self$`className`)) {
@@ -80,12 +106,27 @@ Animal <- R6::R6Class(
80106
jsoncontent <- paste(jsoncontent, collapse = ",")
81107
paste('{', jsoncontent, '}', sep = "")
82108
},
109+
#' Deserialize JSON string into an instance of Animal
110+
#'
111+
#' @description
112+
#' Deserialize JSON string into an instance of Animal
113+
#'
114+
#' @param AnimalJson the JSON input
115+
#' @return the instance of Animal
116+
#' @export
83117
fromJSONString = function(AnimalJson) {
84118
AnimalObject <- jsonlite::fromJSON(AnimalJson)
85119
self$`className` <- AnimalObject$`className`
86120
self$`color` <- AnimalObject$`color`
87121
self
88122
},
123+
#' Validate JSON input with respect to Animal
124+
#'
125+
#' @description
126+
#' Validate JSON input with respect to Animal and throw an exception if invalid
127+
#'
128+
#' @param input the JSON input
129+
#' @export
89130
validateJSON = function(input) {
90131
input_json <- jsonlite::fromJSON(input)
91132
# check the required field `className`

0 commit comments

Comments
 (0)