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..f9be35e0c804 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,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, @@ -359,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" 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) { @@ -371,6 +376,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/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 78edd45d748b..3bbb4f0e42c0 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" 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) { @@ -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-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 561b7fae7f0e..f680486fe951 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" 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) { @@ -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) {