Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions modules/openapi-generator/src/main/resources/r/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions samples/client/echo_api/r/R/api_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions samples/client/petstore/R-httr2-wrapper/R/api_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions samples/client/petstore/R-httr2/R/api_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions samples/client/petstore/R/R/api_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading