Skip to content

Commit e18f361

Browse files
Ramanthwing328
authored andcommitted
Fix/r/serialization fix and minor 3xx resp fix (#3817)
* fix(qlik): fix for minor serialization bug * fix(r): add petsore generated classes * fix(r): indendation fixes
1 parent 8d67acc commit e18f361

6 files changed

Lines changed: 99 additions & 28 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
resp <- apiResponse$response
165165
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
166166
apiResponse$content
167+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
168+
apiResponse
167169
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
168170
apiResponse
169171
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

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

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
local.optional.var <- list(...)
2424
{{#requiredVars}}
2525
if (!missing(`{{baseName}}`)) {
26-
{{^isListContainer}}
26+
{{^isContainer}}
2727
{{#isInteger}}
2828
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
2929
{{/isInteger}}
@@ -48,8 +48,8 @@
4848
{{^isPrimitiveType}}
4949
stopifnot(R6::is.R6(`{{baseName}}`))
5050
{{/isPrimitiveType}}
51-
{{/isListContainer}}
52-
{{#isListContainer}}
51+
{{/isContainer}}
52+
{{#isContainer}}
5353
{{#isPrimitiveType}}
5454
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
5555
sapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
@@ -58,13 +58,13 @@
5858
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
5959
sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
6060
{{/isPrimitiveType}}
61-
{{/isListContainer}}
61+
{{/isContainer}}
6262
self$`{{baseName}}` <- `{{baseName}}`
6363
}
6464
{{/requiredVars}}
6565
{{#optionalVars}}
6666
if (!is.null(`{{baseName}}`)) {
67-
{{^isListContainer}}
67+
{{^isContainer}}
6868
{{#isInteger}}
6969
stopifnot(is.numeric(`{{baseName}}`), length(`{{baseName}}`) == 1)
7070
{{/isInteger}}
@@ -89,8 +89,8 @@
8989
{{^isPrimitiveType}}
9090
stopifnot(R6::is.R6(`{{baseName}}`))
9191
{{/isPrimitiveType}}
92-
{{/isListContainer}}
93-
{{#isListContainer}}
92+
{{/isContainer}}
93+
{{#isContainer}}
9494
{{#isPrimitiveType}}
9595
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
9696
sapply(`{{baseName}}`, function(x) stopifnot(is.character(x)))
@@ -99,7 +99,7 @@
9999
stopifnot(is.vector(`{{baseName}}`), length(`{{baseName}}`) != 0)
100100
sapply(`{{baseName}}`, function(x) stopifnot(R6::is.R6(x)))
101101
{{/isPrimitiveType}}
102-
{{/isListContainer}}
102+
{{/isContainer}}
103103
self$`{{baseName}}` <- `{{baseName}}`
104104
}
105105
{{/optionalVars}}
@@ -109,22 +109,32 @@
109109
{{#vars}}
110110
if (!is.null(self$`{{baseName}}`)) {
111111
{{classname}}Object[['{{baseName}}']] <-
112-
{{#isListContainer}}
113-
{{#isPrimitiveType}}
112+
{{#isContainer}}
113+
{{#isListContainer}}
114+
{{#isPrimitiveType}}
114115
self$`{{baseName}}`
116+
{{/isPrimitiveType}}
117+
{{^isPrimitiveType}}
118+
lapply(self$`{{baseName}}`, function(x) x$toJSON())
115119
{{/isPrimitiveType}}
116-
{{^isPrimitiveType}}
117-
sapply(self$`{{baseName}}`, function(x) x$toJSON())
118-
{{/isPrimitiveType}}
119-
{{/isListContainer}}
120-
{{^isListContainer}}
121-
{{#isPrimitiveType}}
120+
{{/isListContainer}}
121+
{{#isMapContainer}}
122+
{{#isPrimitiveType}}
122123
self$`{{baseName}}`
123-
{{/isPrimitiveType}}
124-
{{^isPrimitiveType}}
124+
{{/isPrimitiveType}}
125+
{{^isPrimitiveType}}
126+
lapply(self$`{{baseName}}`, function(x) x$toJSON())
127+
{{/isPrimitiveType}}
128+
{{/isMapContainer}}
129+
{{/isContainer}}
130+
{{^isContainer}}
131+
{{#isPrimitiveType}}
132+
self$`{{baseName}}`
133+
{{/isPrimitiveType}}
134+
{{^isPrimitiveType}}
125135
self$`{{baseName}}`$toJSON()
126-
{{/isPrimitiveType}}
127-
{{/isListContainer}}
136+
{{/isPrimitiveType}}
137+
{{/isContainer}}
128138
}
129139
{{/vars}}
130140
@@ -156,38 +166,57 @@
156166
if (!is.null(self$`{{baseName}}`)) {
157167
sprintf(
158168
'"{{baseName}}":
169+
{{#isContainer}}
159170
{{#isListContainer}}
160171
{{#isPrimitiveType}}
161172
{{#isNumeric}}[%d]{{/isNumeric}}{{^isNumeric}}[%s]{{/isNumeric}}
162173
{{/isPrimitiveType}}
163174
{{^isPrimitiveType}}[%s]
164175
{{/isPrimitiveType}}
165176
{{/isListContainer}}
166-
{{^isListContainer}}
177+
{{#isMapContainer}}
178+
{{#isPrimitiveType}}
179+
{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}}
180+
{{/isPrimitiveType}}
181+
{{^isPrimitiveType}}%s
182+
{{/isPrimitiveType}}
183+
{{/isMapContainer}}
184+
{{/isContainer}}
185+
{{^isContainer}}
167186
{{#isPrimitiveType}}
168187
{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}"%s"{{/isNumeric}}
169188
{{/isPrimitiveType}}
170189
{{^isPrimitiveType}}%s
171190
{{/isPrimitiveType}}
172-
{{/isListContainer}}',
191+
{{/isContainer}}',
192+
{{#isContainer}}
173193
{{#isListContainer}}
174194
{{#isPrimitiveType}}
175195
paste(unlist(lapply(self$`{{{baseName}}}`, function(x) paste0('"', x, '"'))), collapse=",")
176196
{{/isPrimitiveType}}
177197
{{^isPrimitiveType}}
178-
paste(unlist(lapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA))), collapse=",")
198+
paste(sapply(self$`{{{baseName}}}`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA)), collapse=",")
179199
{{/isPrimitiveType}}
180200
{{/isListContainer}}
181-
{{^isListContainer}}
201+
{{#isMapContainer}}
202+
{{#isPrimitiveType}}
203+
jsonlite::toJSON(lapply(self$`{{{baseName}}}`, function(x){ x }), auto_unbox = TRUE, digits=NA)
204+
{{/isPrimitiveType}}
205+
{{^isPrimitiveType}}
206+
jsonlite::toJSON(lapply(self$`{{{baseName}}}`, function(x){ x$toJSON() }), auto_unbox = TRUE, digits=NA)
207+
{{/isPrimitiveType}}
208+
{{/isMapContainer}}
209+
{{/isContainer}}
210+
{{^isContainer}}
182211
{{#isPrimitiveType}}
183212
self$`{{baseName}}`
184213
{{/isPrimitiveType}}
185214
{{^isPrimitiveType}}
186215
jsonlite::toJSON(self$`{{baseName}}`$toJSON(), auto_unbox=TRUE, digits = NA)
187216
{{/isPrimitiveType}}
188-
{{/isListContainer}}
217+
{{/isContainer}}
189218
)}{{#hasMore}},{{/hasMore}}
190-
{{/vars}}
219+
{{/vars}}
191220
)
192221
jsoncontent <- paste(jsoncontent, collapse = ",")
193222
paste('{', jsoncontent, '}', sep = "")

samples/client/petstore/R/R/pet.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Pet <- R6::R6Class(
8484
}
8585
if (!is.null(self$`tags`)) {
8686
PetObject[['tags']] <-
87-
sapply(self$`tags`, function(x) x$toJSON())
87+
lapply(self$`tags`, function(x) x$toJSON())
8888
}
8989
if (!is.null(self$`status`)) {
9090
PetObject[['status']] <-
@@ -151,7 +151,7 @@ Pet <- R6::R6Class(
151151
'"tags":
152152
[%s]
153153
',
154-
paste(unlist(lapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA))), collapse=",")
154+
paste(sapply(self$`tags`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA)), collapse=",")
155155
)},
156156
if (!is.null(self$`status`)) {
157157
sprintf(

samples/client/petstore/R/R/pet_api.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ PetApi <- R6::R6Class(
336336
resp <- apiResponse$response
337337
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
338338
apiResponse$content
339+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
340+
apiResponse
339341
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
340342
apiResponse
341343
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -384,6 +386,8 @@ PetApi <- R6::R6Class(
384386
resp <- apiResponse$response
385387
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
386388
apiResponse$content
389+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
390+
apiResponse
387391
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
388392
apiResponse
389393
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -432,6 +436,8 @@ PetApi <- R6::R6Class(
432436
resp <- apiResponse$response
433437
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
434438
apiResponse$content
439+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
440+
apiResponse
435441
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
436442
apiResponse
437443
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -482,6 +488,8 @@ PetApi <- R6::R6Class(
482488
resp <- apiResponse$response
483489
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
484490
apiResponse$content
491+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
492+
apiResponse
485493
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
486494
apiResponse
487495
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -532,6 +540,8 @@ PetApi <- R6::R6Class(
532540
resp <- apiResponse$response
533541
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
534542
apiResponse$content
543+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
544+
apiResponse
535545
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
536546
apiResponse
537547
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -586,6 +596,8 @@ PetApi <- R6::R6Class(
586596
resp <- apiResponse$response
587597
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
588598
apiResponse$content
599+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
600+
apiResponse
589601
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
590602
apiResponse
591603
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -634,6 +646,8 @@ PetApi <- R6::R6Class(
634646
resp <- apiResponse$response
635647
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
636648
apiResponse$content
649+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
650+
apiResponse
637651
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
638652
apiResponse
639653
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -685,6 +699,8 @@ PetApi <- R6::R6Class(
685699
resp <- apiResponse$response
686700
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
687701
apiResponse$content
702+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
703+
apiResponse
688704
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
689705
apiResponse
690706
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

samples/client/petstore/R/R/store_api.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ StoreApi <- R6::R6Class(
179179
resp <- apiResponse$response
180180
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
181181
apiResponse$content
182+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
183+
apiResponse
182184
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
183185
apiResponse
184186
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -223,6 +225,8 @@ StoreApi <- R6::R6Class(
223225
resp <- apiResponse$response
224226
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
225227
apiResponse$content
228+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
229+
apiResponse
226230
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
227231
apiResponse
228232
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -269,6 +273,8 @@ StoreApi <- R6::R6Class(
269273
resp <- apiResponse$response
270274
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
271275
apiResponse$content
276+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
277+
apiResponse
272278
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
273279
apiResponse
274280
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -319,6 +325,8 @@ StoreApi <- R6::R6Class(
319325
resp <- apiResponse$response
320326
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
321327
apiResponse$content
328+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
329+
apiResponse
322330
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
323331
apiResponse
324332
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

samples/client/petstore/R/R/user_api.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ UserApi <- R6::R6Class(
296296
resp <- apiResponse$response
297297
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
298298
apiResponse$content
299+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
300+
apiResponse
299301
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
300302
apiResponse
301303
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -342,6 +344,8 @@ UserApi <- R6::R6Class(
342344
resp <- apiResponse$response
343345
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
344346
apiResponse$content
347+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
348+
apiResponse
345349
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
346350
apiResponse
347351
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -389,6 +393,8 @@ UserApi <- R6::R6Class(
389393
resp <- apiResponse$response
390394
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
391395
apiResponse$content
396+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
397+
apiResponse
392398
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
393399
apiResponse
394400
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -436,6 +442,8 @@ UserApi <- R6::R6Class(
436442
resp <- apiResponse$response
437443
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
438444
apiResponse$content
445+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
446+
apiResponse
439447
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
440448
apiResponse
441449
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -480,6 +488,8 @@ UserApi <- R6::R6Class(
480488
resp <- apiResponse$response
481489
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
482490
apiResponse$content
491+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
492+
apiResponse
483493
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
484494
apiResponse
485495
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -530,6 +540,8 @@ UserApi <- R6::R6Class(
530540
resp <- apiResponse$response
531541
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
532542
apiResponse$content
543+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
544+
apiResponse
533545
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
534546
apiResponse
535547
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -584,6 +596,8 @@ UserApi <- R6::R6Class(
584596
resp <- apiResponse$response
585597
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
586598
apiResponse$content
599+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
600+
apiResponse
587601
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
588602
apiResponse
589603
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
@@ -620,6 +634,8 @@ UserApi <- R6::R6Class(
620634
resp <- apiResponse$response
621635
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
622636
apiResponse$content
637+
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
638+
apiResponse
623639
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
624640
apiResponse
625641
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {

0 commit comments

Comments
 (0)