Skip to content

Commit 9f5e3fc

Browse files
committed
handle set/array
1 parent 5b321d1 commit 9f5e3fc

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,9 @@ ApiClient <- R6::R6Class(
351351
return_obj <- NULL
352352
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
353353
354-
return_type <- gsub(pattern = "^(set|list)\\[",
355-
replacement = "array\\[",
354+
# for deserialization, uniqueness requirements do not matter
355+
return_type <- gsub(pattern = "^(set|array)\\[",
356+
replacement = "collection\\[",
356357
x = return_type)
357358
358359
# To handle the "map" type
@@ -363,10 +364,10 @@ ApiClient <- R6::R6Class(
363364
self$deserializeObj(obj[[name]], inner_return_type, pkg_env)
364365
})
365366
names(return_obj) <- names(obj)
366-
} else if (startsWith(return_type, "array[")) {
367-
# To handle the "array" type
367+
} else if (startsWith(return_type, "collection[")) {
368+
# To handle the "array" or "set" types
368369
inner_return_type <- regmatches(return_type,
369-
regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2]
370+
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
370371
if (c(inner_return_type) %in% primitive_types) {
371372
return_obj <- vector("list", length = length(obj))
372373
if (length(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" or "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/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" or "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)