From 5b321d175ad82301ae2dbc2860edab9116e37976 Mon Sep 17 00:00:00 2001 From: Matthew Pollock Date: Wed, 14 Jan 2026 15:32:04 -0500 Subject: [PATCH 1/3] unpack dataframes within a list --- .../src/main/resources/r/api_client.mustache | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index 2a50b0263bda..f6b547af36f9 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -351,6 +351,10 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + return_type <- gsub(pattern = "^(set|list)\\[", + replacement = "array\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -371,6 +375,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { From 9f5e3fc972c86148fcdddd3b6b6b1286435b1ae0 Mon Sep 17 00:00:00 2001 From: Matthew Pollock Date: Wed, 14 Jan 2026 15:45:27 -0500 Subject: [PATCH 2/3] handle set/array --- .../src/main/resources/r/api_client.mustache | 11 ++++++----- samples/client/echo_api/r/R/api_client.R | 14 +++++++++++--- samples/client/petstore/R/R/api_client.R | 14 +++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index f6b547af36f9..081eca3b52cb 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -351,8 +351,9 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") - return_type <- gsub(pattern = "^(set|list)\\[", - replacement = "array\\[", + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", x = return_type) # To handle the "map" type @@ -363,10 +364,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" or "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { diff --git a/samples/client/echo_api/r/R/api_client.R b/samples/client/echo_api/r/R/api_client.R index 78edd45d748b..03d7a8da46a2 100644 --- a/samples/client/echo_api/r/R/api_client.R +++ b/samples/client/echo_api/r/R/api_client.R @@ -303,6 +303,11 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -311,10 +316,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" or "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { @@ -323,6 +328,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 561b7fae7f0e..4d5c07535238 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -332,6 +332,11 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -340,10 +345,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" or "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { @@ -352,6 +357,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { From 511f575a3e95f6fa6458b19e8867bf8ec38f24ee Mon Sep 17 00:00:00 2001 From: Matthew Pollock Date: Thu, 15 Jan 2026 07:07:34 -0500 Subject: [PATCH 3/3] update httr2 client --- .../src/main/resources/r/api_client.mustache | 2 +- .../r/libraries/httr2/api_client.mustache | 14 +++++++++++--- samples/client/echo_api/r/R/api_client.R | 2 +- .../client/petstore/R-httr2-wrapper/R/api_client.R | 14 +++++++++++--- samples/client/petstore/R-httr2/R/api_client.R | 14 +++++++++++--- samples/client/petstore/R/R/api_client.R | 2 +- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/r/api_client.mustache b/modules/openapi-generator/src/main/resources/r/api_client.mustache index 081eca3b52cb..f9be35e0c804 100644 --- a/modules/openapi-generator/src/main/resources/r/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/api_client.mustache @@ -365,7 +365,7 @@ ApiClient <- R6::R6Class( }) names(return_obj) <- names(obj) } else if (startsWith(return_type, "collection[")) { - # To handle the "array" or "set" types + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { diff --git a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache index 3020d69ff821..2d120bfa5cb9 100644 --- a/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache @@ -363,6 +363,11 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -371,10 +376,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { @@ -383,6 +388,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { diff --git a/samples/client/echo_api/r/R/api_client.R b/samples/client/echo_api/r/R/api_client.R index 03d7a8da46a2..3bbb4f0e42c0 100644 --- a/samples/client/echo_api/r/R/api_client.R +++ b/samples/client/echo_api/r/R/api_client.R @@ -317,7 +317,7 @@ ApiClient <- R6::R6Class( }) names(return_obj) <- names(obj) } else if (startsWith(return_type, "collection[")) { - # To handle the "array" or "set" types + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { diff --git a/samples/client/petstore/R-httr2-wrapper/R/api_client.R b/samples/client/petstore/R-httr2-wrapper/R/api_client.R index 954f772e3914..ec7868dd37a0 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/api_client.R +++ b/samples/client/petstore/R-httr2-wrapper/R/api_client.R @@ -352,6 +352,11 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -360,10 +365,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { @@ -372,6 +377,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { diff --git a/samples/client/petstore/R-httr2/R/api_client.R b/samples/client/petstore/R-httr2/R/api_client.R index 954f772e3914..ec7868dd37a0 100644 --- a/samples/client/petstore/R-httr2/R/api_client.R +++ b/samples/client/petstore/R-httr2/R/api_client.R @@ -352,6 +352,11 @@ ApiClient <- R6::R6Class( return_obj <- NULL primitive_types <- c("character", "numeric", "integer", "logical", "complex") + # for deserialization, uniqueness requirements do not matter + return_type <- gsub(pattern = "^(set|array)\\[", + replacement = "collection\\[", + x = return_type) + # To handle the "map" type if (startsWith(return_type, "map(")) { inner_return_type <- regmatches(return_type, @@ -360,10 +365,10 @@ ApiClient <- R6::R6Class( self$deserializeObj(obj[[name]], inner_return_type, pkg_env) }) names(return_obj) <- names(obj) - } else if (startsWith(return_type, "array[")) { - # To handle the "array" type + } else if (startsWith(return_type, "collection[")) { + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, - regexec(pattern = "array\\[(.*)\\]", return_type))[[1]][2] + regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) { return_obj <- vector("list", length = length(obj)) if (length(obj) > 0) { @@ -372,6 +377,9 @@ ApiClient <- R6::R6Class( } } } else { + if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) { + obj <- obj[[1]] + } if (!is.null(nrow(obj))) { return_obj <- vector("list", length = nrow(obj)) if (nrow(obj) > 0) { diff --git a/samples/client/petstore/R/R/api_client.R b/samples/client/petstore/R/R/api_client.R index 4d5c07535238..f680486fe951 100644 --- a/samples/client/petstore/R/R/api_client.R +++ b/samples/client/petstore/R/R/api_client.R @@ -346,7 +346,7 @@ ApiClient <- R6::R6Class( }) names(return_obj) <- names(obj) } else if (startsWith(return_type, "collection[")) { - # To handle the "array" or "set" types + # To handle the "array" and "set" types inner_return_type <- regmatches(return_type, regexec(pattern = "collection\\[(.*)\\]", return_type))[[1]][2] if (c(inner_return_type) %in% primitive_types) {