Skip to content

Commit 7e4f3c9

Browse files
authored
[R] Add fromJSONString method to oneOf/anyOf in R client (#13223)
* add fromJSONString method to oneOf/anyOf in R client * update code samples
1 parent 3239f28 commit 7e4f3c9

Some content is hidden

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

47 files changed

+169
-6517
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if (!is.null(result$ApiException)) {
7777
dput(result$ApiException$toString())
7878
{{#errorObjectType}}
7979
# error object
80-
dput(result$ApiException$error_object)
80+
dput(result$ApiException$error_object$toJSONString())
8181
{{/errorObjectType}}
8282
}{{#returnType}} else {
8383
# deserialized response object

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
#'
4040
#' @description
4141
#' Deserialize JSON string into an instance of {{{classname}}}.
42+
#' An alias to the method `fromJSON`.
43+
#'
44+
#' @param input The input JSON.
45+
#' @return An instance of {{{classname}}}.
46+
#' @export
47+
fromJSONString = function(input) {
48+
self$fromJSON(input)
49+
},
50+
#' Deserialize JSON string into an instance of {{{classname}}}.
51+
#'
52+
#' @description
53+
#' Deserialize JSON string into an instance of {{{classname}}}.
4254
#'
4355
#' @param input The input JSON.
4456
#' @return An instance of {{{classname}}}.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
#'
4040
#' @description
4141
#' Deserialize JSON string into an instance of {{{classname}}}.
42+
#' An alias to the method `fromJSON` .
43+
#'
44+
#' @param input The input JSON.
45+
#' @return An instance of {{{classname}}}.
46+
#' @export
47+
fromJSONString = function(input) {
48+
self$fromJSON(input)
49+
},
50+
#' Deserialize JSON string into an instance of {{{classname}}}.
51+
#'
52+
#' @description
53+
#' Deserialize JSON string into an instance of {{{classname}}}.
4254
#'
4355
#' @param input The input JSON.
4456
#' @return An instance of {{{classname}}}.

samples/client/petstore/R-httr2-wrapper/R/any_of_pig.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ AnyOfPig <- R6::R6Class(
4949
#'
5050
#' @description
5151
#' Deserialize JSON string into an instance of AnyOfPig.
52+
#' An alias to the method `fromJSON`.
53+
#'
54+
#' @param input The input JSON.
55+
#' @return An instance of AnyOfPig.
56+
#' @export
57+
fromJSONString = function(input) {
58+
self$fromJSON(input)
59+
},
60+
#' Deserialize JSON string into an instance of AnyOfPig.
61+
#'
62+
#' @description
63+
#' Deserialize JSON string into an instance of AnyOfPig.
5264
#'
5365
#' @param input The input JSON.
5466
#' @return An instance of AnyOfPig.

samples/client/petstore/R-httr2-wrapper/R/pig.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ Pig <- R6::R6Class(
4949
#'
5050
#' @description
5151
#' Deserialize JSON string into an instance of Pig.
52+
#' An alias to the method `fromJSON` .
53+
#'
54+
#' @param input The input JSON.
55+
#' @return An instance of Pig.
56+
#' @export
57+
fromJSONString = function(input) {
58+
self$fromJSON(input)
59+
},
60+
#' Deserialize JSON string into an instance of Pig.
61+
#'
62+
#' @description
63+
#' Deserialize JSON string into an instance of Pig.
5264
#'
5365
#' @param input The input JSON.
5466
#' @return An instance of Pig.

samples/client/petstore/R-httr2-wrapper/docs/FakeApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if (!is.null(result$ApiException)) {
3535
print("Exception occurs when calling `fake_data_file`:")
3636
dput(result$ApiException$toString())
3737
# error object
38-
dput(result$ApiException$error_object)
38+
dput(result$ApiException$error_object$toJSONString())
3939
} else {
4040
# deserialized response object
4141
print("The response is ...")
@@ -93,7 +93,7 @@ if (!is.null(result$ApiException)) {
9393
print("Exception occurs when calling `fake_regular_expression`:")
9494
dput(result$ApiException$toString())
9595
# error object
96-
dput(result$ApiException$error_object)
96+
dput(result$ApiException$error_object$toJSONString())
9797
}
9898
# This endpoint doesn't return data
9999
```

samples/client/petstore/R-httr2-wrapper/docs/PetApi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if (!is.null(result$ApiException)) {
4545
print("Exception occurs when calling `add_pet`:")
4646
dput(result$ApiException$toString())
4747
# error object
48-
dput(result$ApiException$error_object)
48+
dput(result$ApiException$error_object$toJSONString())
4949
} else {
5050
# deserialized response object
5151
print("The response is ...")
@@ -106,7 +106,7 @@ if (!is.null(result$ApiException)) {
106106
print("Exception occurs when calling `delete_pet`:")
107107
dput(result$ApiException$toString())
108108
# error object
109-
dput(result$ApiException$error_object)
109+
dput(result$ApiException$error_object$toJSONString())
110110
}
111111
# This endpoint doesn't return data
112112
```
@@ -164,7 +164,7 @@ if (!is.null(result$ApiException)) {
164164
print("Exception occurs when calling `find_pets_by_status`:")
165165
dput(result$ApiException$toString())
166166
# error object
167-
dput(result$ApiException$error_object)
167+
dput(result$ApiException$error_object$toJSONString())
168168
} else {
169169
# deserialized response object
170170
print("The response is ...")
@@ -226,7 +226,7 @@ if (!is.null(result$ApiException)) {
226226
print("Exception occurs when calling `find_pets_by_tags`:")
227227
dput(result$ApiException$toString())
228228
# error object
229-
dput(result$ApiException$error_object)
229+
dput(result$ApiException$error_object$toJSONString())
230230
} else {
231231
# deserialized response object
232232
print("The response is ...")
@@ -288,7 +288,7 @@ if (!is.null(result$ApiException)) {
288288
print("Exception occurs when calling `get_pet_by_id`:")
289289
dput(result$ApiException$toString())
290290
# error object
291-
dput(result$ApiException$error_object)
291+
dput(result$ApiException$error_object$toJSONString())
292292
} else {
293293
# deserialized response object
294294
print("The response is ...")
@@ -353,7 +353,7 @@ if (!is.null(result$ApiException)) {
353353
print("Exception occurs when calling `get_pet_by_id_streaming`:")
354354
dput(result$ApiException$toString())
355355
# error object
356-
dput(result$ApiException$error_object)
356+
dput(result$ApiException$error_object$toJSONString())
357357
} else {
358358
# deserialized response object
359359
print("The response is ...")
@@ -418,7 +418,7 @@ if (!is.null(result$ApiException)) {
418418
print("Exception occurs when calling `test_header`:")
419419
dput(result$ApiException$toString())
420420
# error object
421-
dput(result$ApiException$error_object)
421+
dput(result$ApiException$error_object$toJSONString())
422422
} else {
423423
# deserialized response object
424424
print("The response is ...")
@@ -481,7 +481,7 @@ if (!is.null(result$ApiException)) {
481481
print("Exception occurs when calling `update_pet`:")
482482
dput(result$ApiException$toString())
483483
# error object
484-
dput(result$ApiException$error_object)
484+
dput(result$ApiException$error_object$toJSONString())
485485
} else {
486486
# deserialized response object
487487
print("The response is ...")
@@ -543,7 +543,7 @@ if (!is.null(result$ApiException)) {
543543
print("Exception occurs when calling `update_pet_with_form`:")
544544
dput(result$ApiException$toString())
545545
# error object
546-
dput(result$ApiException$error_object)
546+
dput(result$ApiException$error_object$toJSONString())
547547
}
548548
# This endpoint doesn't return data
549549
```
@@ -604,7 +604,7 @@ if (!is.null(result$ApiException)) {
604604
print("Exception occurs when calling `upload_file`:")
605605
dput(result$ApiException$toString())
606606
# error object
607-
dput(result$ApiException$error_object)
607+
dput(result$ApiException$error_object$toJSONString())
608608
} else {
609609
# deserialized response object
610610
print("The response is ...")

samples/client/petstore/R-httr2-wrapper/docs/StoreApi.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (!is.null(result$ApiException)) {
3434
print("Exception occurs when calling `delete_order`:")
3535
dput(result$ApiException$toString())
3636
# error object
37-
dput(result$ApiException$error_object)
37+
dput(result$ApiException$error_object$toJSONString())
3838
}
3939
# This endpoint doesn't return data
4040
```
@@ -91,7 +91,7 @@ if (!is.null(result$ApiException)) {
9191
print("Exception occurs when calling `get_inventory`:")
9292
dput(result$ApiException$toString())
9393
# error object
94-
dput(result$ApiException$error_object)
94+
dput(result$ApiException$error_object$toJSONString())
9595
} else {
9696
# deserialized response object
9797
print("The response is ...")
@@ -147,7 +147,7 @@ if (!is.null(result$ApiException)) {
147147
print("Exception occurs when calling `get_order_by_id`:")
148148
dput(result$ApiException$toString())
149149
# error object
150-
dput(result$ApiException$error_object)
150+
dput(result$ApiException$error_object$toJSONString())
151151
} else {
152152
# deserialized response object
153153
print("The response is ...")
@@ -208,7 +208,7 @@ if (!is.null(result$ApiException)) {
208208
print("Exception occurs when calling `place_order`:")
209209
dput(result$ApiException$toString())
210210
# error object
211-
dput(result$ApiException$error_object)
211+
dput(result$ApiException$error_object$toJSONString())
212212
} else {
213213
# deserialized response object
214214
print("The response is ...")

samples/client/petstore/R-httr2-wrapper/docs/UserApi.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (!is.null(result$ApiException)) {
4040
print("Exception occurs when calling `create_user`:")
4141
dput(result$ApiException$toString())
4242
# error object
43-
dput(result$ApiException$error_object)
43+
dput(result$ApiException$error_object$toJSONString())
4444
}
4545
# This endpoint doesn't return data
4646
```
@@ -95,7 +95,7 @@ if (!is.null(result$ApiException)) {
9595
print("Exception occurs when calling `create_users_with_array_input`:")
9696
dput(result$ApiException$toString())
9797
# error object
98-
dput(result$ApiException$error_object)
98+
dput(result$ApiException$error_object$toJSONString())
9999
}
100100
# This endpoint doesn't return data
101101
```
@@ -150,7 +150,7 @@ if (!is.null(result$ApiException)) {
150150
print("Exception occurs when calling `create_users_with_list_input`:")
151151
dput(result$ApiException$toString())
152152
# error object
153-
dput(result$ApiException$error_object)
153+
dput(result$ApiException$error_object$toJSONString())
154154
}
155155
# This endpoint doesn't return data
156156
```
@@ -205,7 +205,7 @@ if (!is.null(result$ApiException)) {
205205
print("Exception occurs when calling `delete_user`:")
206206
dput(result$ApiException$toString())
207207
# error object
208-
dput(result$ApiException$error_object)
208+
dput(result$ApiException$error_object$toJSONString())
209209
}
210210
# This endpoint doesn't return data
211211
```
@@ -261,7 +261,7 @@ if (!is.null(result$ApiException)) {
261261
print("Exception occurs when calling `get_user_by_name`:")
262262
dput(result$ApiException$toString())
263263
# error object
264-
dput(result$ApiException$error_object)
264+
dput(result$ApiException$error_object$toJSONString())
265265
} else {
266266
# deserialized response object
267267
print("The response is ...")
@@ -323,7 +323,7 @@ if (!is.null(result$ApiException)) {
323323
print("Exception occurs when calling `login_user`:")
324324
dput(result$ApiException$toString())
325325
# error object
326-
dput(result$ApiException$error_object)
326+
dput(result$ApiException$error_object$toJSONString())
327327
} else {
328328
# deserialized response object
329329
print("The response is ...")
@@ -383,7 +383,7 @@ if (!is.null(result$ApiException)) {
383383
print("Exception occurs when calling `logout_user`:")
384384
dput(result$ApiException$toString())
385385
# error object
386-
dput(result$ApiException$error_object)
386+
dput(result$ApiException$error_object$toJSONString())
387387
}
388388
# This endpoint doesn't return data
389389
```
@@ -436,7 +436,7 @@ if (!is.null(result$ApiException)) {
436436
print("Exception occurs when calling `update_user`:")
437437
dput(result$ApiException$toString())
438438
# error object
439-
dput(result$ApiException$error_object)
439+
dput(result$ApiException$error_object$toJSONString())
440440
}
441441
# This endpoint doesn't return data
442442
```

0 commit comments

Comments
 (0)