mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
add validation for query enum parameters in r client (#13415)
This commit is contained in:
parent
7ff47dc0bf
commit
37fb856775
@ -385,15 +385,62 @@
|
|||||||
{{#isExplode}}
|
{{#isExplode}}
|
||||||
# explore
|
# explore
|
||||||
for (query_item in `{{{paramName}}}`) {
|
for (query_item in `{{{paramName}}}`) {
|
||||||
|
{{#items}}
|
||||||
|
{{#isEnum}}
|
||||||
|
# validate enum values
|
||||||
|
if (!(query_item %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||||
|
{{#useDefaultExceptionHandling}}
|
||||||
|
stop("Invalid value for {{{paramName}}} when calling {{classname}}${{operationId}}. Must be {{_enum}}.")
|
||||||
|
{{/useDefaultExceptionHandling}}
|
||||||
|
{{#useRlangExceptionHandling}}
|
||||||
|
rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}.",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}."))
|
||||||
|
{{/useRlangExceptionHandling}}
|
||||||
|
}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/items}}
|
||||||
query_params[["{{{baseName}}}"]] <- c(query_params[["{{{baseName}}}"]], list(`{{{baseName}}}` = query_item))
|
query_params[["{{{baseName}}}"]] <- c(query_params[["{{{baseName}}}"]], list(`{{{baseName}}}` = query_item))
|
||||||
}
|
}
|
||||||
{{/isExplode}}
|
{{/isExplode}}
|
||||||
{{^isExplode}}
|
{{^isExplode}}
|
||||||
# no explore
|
# no explore
|
||||||
|
{{#items}}
|
||||||
|
{{#isEnum}}
|
||||||
|
# validate enum values
|
||||||
|
for (query_item in `{{{paramName}}}`) {
|
||||||
|
if (!(query_item %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||||
|
{{#useDefaultExceptionHandling}}
|
||||||
|
stop("Invalid value for {{{paramName}}} when calling {{classname}}${{operationId}}. Must be {{_enum}}.")
|
||||||
|
{{/useDefaultExceptionHandling}}
|
||||||
|
{{#useRlangExceptionHandling}}
|
||||||
|
rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}.",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}."))
|
||||||
|
{{/useRlangExceptionHandling}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/items}}
|
||||||
query_params[["{{{baseName}}}"]] <- I(paste(lapply(`{{{paramName}}}`, URLencode, reserved = TRUE), collapse = ","))
|
query_params[["{{{baseName}}}"]] <- I(paste(lapply(`{{{paramName}}}`, URLencode, reserved = TRUE), collapse = ","))
|
||||||
{{/isExplode}}
|
{{/isExplode}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
|
{{#isEnum}}
|
||||||
|
if (!(`{{paramName}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||||
|
{{#useDefaultExceptionHandling}}
|
||||||
|
stop("Invalid value for {{{paramName}}} when calling {{classname}}${{operationId}}. Must be {{_enum}}.")
|
||||||
|
{{/useDefaultExceptionHandling}}
|
||||||
|
{{#useRlangExceptionHandling}}
|
||||||
|
rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}.",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}. Must be {{_enum}}."))
|
||||||
|
{{/useRlangExceptionHandling}}
|
||||||
|
}
|
||||||
|
{{/isEnum}}
|
||||||
query_params[["{{baseName}}"]] <- `{{paramName}}`
|
query_params[["{{baseName}}"]] <- `{{paramName}}`
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
|
|
||||||
|
@ -943,6 +943,13 @@ PetApi <- R6::R6Class(
|
|||||||
|
|
||||||
# explore
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
|
# validate enum values
|
||||||
|
if (!(query_item %in% c("available", "pending", "sold"))) {
|
||||||
|
rlang::abort(message = "Invalid value for `status` when calling PetApi$find_pets_by_status. Must be [available, pending, sold].",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `status` when calling PetApi$find_pets_by_status. Must be [available, pending, sold]."))
|
||||||
|
}
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,16 @@ test_that("GetPetById with data_file", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test_that("find_pets_by_status", {
|
test_that("find_pets_by_status", {
|
||||||
|
# input invalid
|
||||||
|
var_status <- c("something") # array[character] | Tags to filter by
|
||||||
|
result <- tryCatch(pet_api$find_pets_by_status(var_status),
|
||||||
|
ApiException = function(ex) ex
|
||||||
|
)
|
||||||
|
|
||||||
|
expect_equal(result$ApiException$reason, "Invalid value for `status` when calling PetApi$find_pets_by_status. Must be [available, pending, sold].")
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("find_pets_by_tags", {
|
||||||
pet_tag_test <- Pet$new("name_test",
|
pet_tag_test <- Pet$new("name_test",
|
||||||
photoUrls = list("photo_test", "second test"),
|
photoUrls = list("photo_test", "second test"),
|
||||||
category = Category$new(id = 4455, name = "test_cat"),
|
category = Category$new(id = 4455, name = "test_cat"),
|
||||||
|
@ -943,6 +943,13 @@ PetApi <- R6::R6Class(
|
|||||||
|
|
||||||
# explore
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
|
# validate enum values
|
||||||
|
if (!(query_item %in% c("available", "pending", "sold"))) {
|
||||||
|
rlang::abort(message = "Invalid value for `status` when calling PetApi$find_pets_by_status. Must be [available, pending, sold].",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `status` when calling PetApi$find_pets_by_status. Must be [available, pending, sold]."))
|
||||||
|
}
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,6 +943,13 @@ PetApi <- R6::R6Class(
|
|||||||
|
|
||||||
# explore
|
# explore
|
||||||
for (query_item in `status`) {
|
for (query_item in `status`) {
|
||||||
|
# validate enum values
|
||||||
|
if (!(query_item %in% c("available", "pending", "sold"))) {
|
||||||
|
rlang::abort(message = "Invalid value for `status` when calling PetApi$FindPetsByStatus. Must be [available, pending, sold].",
|
||||||
|
.subclass = "ApiException",
|
||||||
|
ApiException = ApiException$new(status = 0,
|
||||||
|
reason = "Invalid value for `status` when calling PetApi$FindPetsByStatus. Must be [available, pending, sold]."))
|
||||||
|
}
|
||||||
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
query_params[["status"]] <- c(query_params[["status"]], list(`status` = query_item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user