Skip to content

Commit bdf8cd2

Browse files
committed
Merge branch 'fix/r-client-deserialization' of https://github.com/mattpollock/openapi-generator into mattpollock-fix/r-client-deserialization
2 parents 10d5aa7 + 511f575 commit bdf8cd2

File tree

6 files changed

+66
-18
lines changed

6 files changed

+66
-18
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ ApiClient <- R6::R6Class(
351351
return_obj <- NULL
352352
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
353353
354+
# for deserialization, uniqueness requirements do not matter
355+
return_type <- gsub(pattern = "^(set|array)\\[",
356+
replacement = "collection\\[",
357+
x = return_type)
358+
354359
# To handle the "map" type
355360
if (startsWith(return_type, "map(")) {
356361
inner_return_type <- regmatches(return_type,
@@ -359,10 +364,10 @@ ApiClient <- R6::R6Class(
359364
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
360365
})
361366
names(return_obj) <- names(obj)
362-
} else if (startsWith(return_type, "array[")) {
363-
# To handle the "array" type
367+
} else if (startsWith(return_type, "collection[")) {
368+
# To handle the "array" and "set" types
364369
inner_return_type <- regmatches(return_type,
365-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
370+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
366371
if (c(inner_return_type) %in% primitive_types) {
367372
return_obj <- vector("list", length = length(obj))
368373
if (length(obj) > 0) {
@@ -371,6 +376,9 @@ ApiClient <- R6::R6Class(
371376
}
372377
}
373378
} else {
379+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
380+
obj <- obj[[1]]
381+
}
374382
if (!is.null(nrow(obj))) {
375383
return_obj <- vector("list", length = nrow(obj))
376384
if (nrow(obj) > 0) {

modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ ApiClient <- R6::R6Class(
363363
return_obj <- NULL
364364
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
365365
366+
# for deserialization, uniqueness requirements do not matter
367+
return_type <- gsub(pattern = "^(set|array)\\[",
368+
replacement = "collection\\[",
369+
x = return_type)
370+
366371
# To handle the "map" type
367372
if (startsWith(return_type, "map(")) {
368373
inner_return_type <- regmatches(return_type,
@@ -371,10 +376,10 @@ ApiClient <- R6::R6Class(
371376
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
372377
})
373378
names(return_obj) <- names(obj)
374-
} else if (startsWith(return_type, "array[")) {
375-
# To handle the "array" type
379+
} else if (startsWith(return_type, "collection[")) {
380+
# To handle the "array" and "set" types
376381
inner_return_type <- regmatches(return_type,
377-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
382+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
378383
if (c(inner_return_type) %in% primitive_types) {
379384
return_obj <- vector("list", length = length(obj))
380385
if (length(obj) > 0) {
@@ -383,6 +388,9 @@ ApiClient <- R6::R6Class(
383388
}
384389
}
385390
} else {
391+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
392+
obj <- obj[[1]]
393+
}
386394
if (!is.null(nrow(obj))) {
387395
return_obj <- vector("list", length = nrow(obj))
388396
if (nrow(obj) > 0) {

samples/client/echo_api/r/R/api_client.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ ApiClient <- R6::R6Class(
303303
return_obj <- NULL
304304
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
305305

306+
# for deserialization, uniqueness requirements do not matter
307+
return_type <- gsub(pattern = "^(set|array)\\[",
308+
replacement = "collection\\[",
309+
x = return_type)
310+
306311
# To handle the "map" type
307312
if (startsWith(return_type, "map(")) {
308313
inner_return_type <- regmatches(return_type,
@@ -311,10 +316,10 @@ ApiClient <- R6::R6Class(
311316
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
312317
})
313318
names(return_obj) <- names(obj)
314-
} else if (startsWith(return_type, "array[")) {
315-
# To handle the "array" type
319+
} else if (startsWith(return_type, "collection[")) {
320+
# To handle the "array" and "set" types
316321
inner_return_type <- regmatches(return_type,
317-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
322+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
318323
if (c(inner_return_type) %in% primitive_types) {
319324
return_obj <- vector("list", length = length(obj))
320325
if (length(obj) > 0) {
@@ -323,6 +328,9 @@ ApiClient <- R6::R6Class(
323328
}
324329
}
325330
} else {
331+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
332+
obj <- obj[[1]]
333+
}
326334
if (!is.null(nrow(obj))) {
327335
return_obj <- vector("list", length = nrow(obj))
328336
if (nrow(obj) > 0) {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ ApiClient <- R6::R6Class(
352352
return_obj <- NULL
353353
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
354354

355+
# for deserialization, uniqueness requirements do not matter
356+
return_type <- gsub(pattern = "^(set|array)\\[",
357+
replacement = "collection\\[",
358+
x = return_type)
359+
355360
# To handle the "map" type
356361
if (startsWith(return_type, "map(")) {
357362
inner_return_type <- regmatches(return_type,
@@ -360,10 +365,10 @@ ApiClient <- R6::R6Class(
360365
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
361366
})
362367
names(return_obj) <- names(obj)
363-
} else if (startsWith(return_type, "array[")) {
364-
# To handle the "array" type
368+
} else if (startsWith(return_type, "collection[")) {
369+
# To handle the "array" and "set" types
365370
inner_return_type <- regmatches(return_type,
366-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
371+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
367372
if (c(inner_return_type) %in% primitive_types) {
368373
return_obj <- vector("list", length = length(obj))
369374
if (length(obj) > 0) {
@@ -372,6 +377,9 @@ ApiClient <- R6::R6Class(
372377
}
373378
}
374379
} else {
380+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
381+
obj <- obj[[1]]
382+
}
375383
if (!is.null(nrow(obj))) {
376384
return_obj <- vector("list", length = nrow(obj))
377385
if (nrow(obj) > 0) {

samples/client/petstore/R-httr2/R/api_client.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ ApiClient <- R6::R6Class(
352352
return_obj <- NULL
353353
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
354354

355+
# for deserialization, uniqueness requirements do not matter
356+
return_type <- gsub(pattern = "^(set|array)\\[",
357+
replacement = "collection\\[",
358+
x = return_type)
359+
355360
# To handle the "map" type
356361
if (startsWith(return_type, "map(")) {
357362
inner_return_type <- regmatches(return_type,
@@ -360,10 +365,10 @@ ApiClient <- R6::R6Class(
360365
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
361366
})
362367
names(return_obj) <- names(obj)
363-
} else if (startsWith(return_type, "array[")) {
364-
# To handle the "array" type
368+
} else if (startsWith(return_type, "collection[")) {
369+
# To handle the "array" and "set" types
365370
inner_return_type <- regmatches(return_type,
366-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
371+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
367372
if (c(inner_return_type) %in% primitive_types) {
368373
return_obj <- vector("list", length = length(obj))
369374
if (length(obj) > 0) {
@@ -372,6 +377,9 @@ ApiClient <- R6::R6Class(
372377
}
373378
}
374379
} else {
380+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
381+
obj <- obj[[1]]
382+
}
375383
if (!is.null(nrow(obj))) {
376384
return_obj <- vector("list", length = nrow(obj))
377385
if (nrow(obj) > 0) {

samples/client/petstore/R/R/api_client.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ ApiClient <- R6::R6Class(
332332
return_obj <- NULL
333333
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
334334

335+
# for deserialization, uniqueness requirements do not matter
336+
return_type <- gsub(pattern = "^(set|array)\\[",
337+
replacement = "collection\\[",
338+
x = return_type)
339+
335340
# To handle the "map" type
336341
if (startsWith(return_type, "map(")) {
337342
inner_return_type <- regmatches(return_type,
@@ -340,10 +345,10 @@ ApiClient <- R6::R6Class(
340345
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
341346
})
342347
names(return_obj) <- names(obj)
343-
} else if (startsWith(return_type, "array[")) {
344-
# To handle the "array" type
348+
} else if (startsWith(return_type, "collection[")) {
349+
# To handle the "array" and "set" types
345350
inner_return_type <- regmatches(return_type,
346-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
351+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
347352
if (c(inner_return_type) %in% primitive_types) {
348353
return_obj <- vector("list", length = length(obj))
349354
if (length(obj) > 0) {
@@ -352,6 +357,9 @@ ApiClient <- R6::R6Class(
352357
}
353358
}
354359
} else {
360+
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
361+
obj <- obj[[1]]
362+
}
355363
if (!is.null(nrow(obj))) {
356364
return_obj <- vector("list", length = nrow(obj))
357365
if (nrow(obj) > 0) {

0 commit comments

Comments
 (0)