Skip to content

Commit 511f575

Browse files
committed
update httr2 client
1 parent 9f5e3fc commit 511f575

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ ApiClient <- R6::R6Class(
365365
})
366366
names(return_obj) <- names(obj)
367367
} else if (startsWith(return_type, "collection[")) {
368-
# To handle the "array" or "set" types
368+
# To handle the "array" and "set" types
369369
inner_return_type <- regmatches(return_type,
370370
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
371371
if (c(inner_return_type) %in% primitive_types) {

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ ApiClient <- R6::R6Class(
317317
})
318318
names(return_obj) <- names(obj)
319319
} else if (startsWith(return_type, "collection[")) {
320-
# To handle the "array" or "set" types
320+
# To handle the "array" and "set" types
321321
inner_return_type <- regmatches(return_type,
322322
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
323323
if (c(inner_return_type) %in% primitive_types) {

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ ApiClient <- R6::R6Class(
346346
})
347347
names(return_obj) <- names(obj)
348348
} else if (startsWith(return_type, "collection[")) {
349-
# To handle the "array" or "set" types
349+
# To handle the "array" and "set" types
350350
inner_return_type <- regmatches(return_type,
351351
regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2]
352352
if (c(inner_return_type) %in% primitive_types) {

0 commit comments

Comments
 (0)