forked from loafle/openapi-generator-original
better enum status validation (#13486)
This commit is contained in:
parent
5f9910dcab
commit
e146afbea1
@ -52,6 +52,11 @@
|
||||
{{#requiredVars}}
|
||||
if (!missing(`{{name}}`)) {
|
||||
{{^isContainer}}
|
||||
{{#isEnum}}
|
||||
if (!(`{{name}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||
stop(paste("Error! \"", `{{name}}`, "\" cannot be assigned to `{{name}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = ""))
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{#isInteger}}
|
||||
stopifnot(is.numeric(`{{name}}`), length(`{{name}}`) == 1)
|
||||
{{/isInteger}}
|
||||
@ -97,6 +102,11 @@
|
||||
{{#optionalVars}}
|
||||
if (!is.null(`{{name}}`)) {
|
||||
{{^isContainer}}
|
||||
{{#isEnum}}
|
||||
if (!(`{{name}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||
stop(paste("Error! \"", `{{name}}`, "\" cannot be assigned to `{{name}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = ""))
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{#isInteger}}
|
||||
stopifnot(is.numeric(`{{name}}`), length(`{{name}}`) == 1)
|
||||
{{/isInteger}}
|
||||
@ -219,6 +229,11 @@
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isEnum}}
|
||||
if (!is.null(this_object$`{{baseName}}`) && !(this_object$`{{baseName}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||
stop(paste("Error! \"", this_object$`{{baseName}}`, "\" cannot be assigned to `{{baseName}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = ""))
|
||||
}
|
||||
{{/isEnum}}
|
||||
self$`{{name}}` <- this_object$`{{baseName}}`
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
@ -340,6 +355,11 @@
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isEnum}}
|
||||
if (!is.null(this_object$`{{baseName}}`) && !(this_object$`{{baseName}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) {
|
||||
stop(paste("Error! \"", this_object$`{{baseName}}`, "\" cannot be assigned to `{{baseName}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = ""))
|
||||
}
|
||||
{{/isEnum}}
|
||||
self$`{{name}}` <- this_object$`{{name}}`
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
|
@ -63,6 +63,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- `shipDate`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -138,6 +141,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
if (!is.null(this_object$`complete`)) {
|
||||
@ -232,6 +238,9 @@ Order <- R6::R6Class(
|
||||
self$`petId` <- this_object$`petId`
|
||||
self$`quantity` <- this_object$`quantity`
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
self$`complete` <- this_object$`complete`
|
||||
# process additional properties/fields in the payload
|
||||
|
@ -69,6 +69,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- `tags`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -145,6 +148,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
# process additional properties/fields in the payload
|
||||
@ -237,6 +243,9 @@ Pet <- R6::R6Class(
|
||||
self$`name` <- this_object$`name`
|
||||
self$`photoUrls` <- ApiClient$new()$deserializeObj(this_object$`photoUrls`, "array[character]", loadNamespace("petstore"))
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
# process additional properties/fields in the payload
|
||||
for (key in names(this_object)) {
|
||||
|
@ -39,6 +39,9 @@ Zebra <- R6::R6Class(
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
if (!(`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", `type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
@ -82,6 +85,9 @@ Zebra <- R6::R6Class(
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
@ -140,6 +146,9 @@ Zebra <- R6::R6Class(
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
# process additional properties/fields in the payload
|
||||
|
@ -21,6 +21,18 @@ pet_api$api_client$username <- "username123"
|
||||
pet_api$api_client$password <- "password123"
|
||||
result <- pet_api$add_pet(pet)
|
||||
|
||||
test_that("Invalid enum value test", {
|
||||
expect_error(Pet$new("name_test",
|
||||
photoUrls = list("photo_test", "second test"),
|
||||
category = Category$new(id = 450, name = "test_cat"),
|
||||
id = pet_id,
|
||||
tags = list(
|
||||
Tag$new(id = 123, name = "tag_test"), Tag$new(id = 456, name = "unknown")
|
||||
),
|
||||
status = "error_available"
|
||||
), "Error! \"error_available\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".")
|
||||
})
|
||||
|
||||
test_that("Additional Properties test", {
|
||||
# test tag
|
||||
t <- Tag$new(id = 393, name = "something")
|
||||
|
@ -58,6 +58,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- `shipDate`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -124,6 +127,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
if (!is.null(this_object$`complete`)) {
|
||||
@ -206,6 +212,9 @@ Order <- R6::R6Class(
|
||||
self$`petId` <- this_object$`petId`
|
||||
self$`quantity` <- this_object$`quantity`
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
self$`complete` <- this_object$`complete`
|
||||
self
|
||||
|
@ -64,6 +64,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- `tags`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -131,6 +134,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
self
|
||||
@ -211,6 +217,9 @@ Pet <- R6::R6Class(
|
||||
self$`name` <- this_object$`name`
|
||||
self$`photoUrls` <- ApiClient$new()$deserializeObj(this_object$`photoUrls`, "array[character]", loadNamespace("petstore"))
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
self
|
||||
},
|
||||
|
@ -34,6 +34,9 @@ Zebra <- R6::R6Class(
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
if (!(`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", `type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
@ -68,6 +71,9 @@ Zebra <- R6::R6Class(
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
@ -114,6 +120,9 @@ Zebra <- R6::R6Class(
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
self
|
||||
|
@ -63,6 +63,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- `shipDate`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -138,6 +141,9 @@ Order <- R6::R6Class(
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
if (!is.null(this_object$`complete`)) {
|
||||
@ -232,6 +238,9 @@ Order <- R6::R6Class(
|
||||
self$`petId` <- this_object$`petId`
|
||||
self$`quantity` <- this_object$`quantity`
|
||||
self$`shipDate` <- this_object$`shipDate`
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("placed", "approved", "delivered"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"placed\", \"approved\", \"delivered\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
self$`complete` <- this_object$`complete`
|
||||
# process additional properties/fields in the payload
|
||||
|
@ -69,6 +69,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- `tags`
|
||||
}
|
||||
if (!is.null(`status`)) {
|
||||
if (!(`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", `status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`status`), length(`status`) == 1)
|
||||
self$`status` <- `status`
|
||||
}
|
||||
@ -145,6 +148,9 @@ Pet <- R6::R6Class(
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
}
|
||||
if (!is.null(this_object$`status`)) {
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
}
|
||||
# process additional properties/fields in the payload
|
||||
@ -237,6 +243,9 @@ Pet <- R6::R6Class(
|
||||
self$`name` <- this_object$`name`
|
||||
self$`photoUrls` <- ApiClient$new()$deserializeObj(this_object$`photoUrls`, "array[character]", loadNamespace("petstore"))
|
||||
self$`tags` <- ApiClient$new()$deserializeObj(this_object$`tags`, "array[Tag]", loadNamespace("petstore"))
|
||||
if (!is.null(this_object$`status`) && !(this_object$`status` %in% c("available", "pending", "sold"))) {
|
||||
stop(paste("Error! \"", this_object$`status`, "\" cannot be assigned to `status`. Must be \"available\", \"pending\", \"sold\".", sep = ""))
|
||||
}
|
||||
self$`status` <- this_object$`status`
|
||||
# process additional properties/fields in the payload
|
||||
for (key in names(this_object)) {
|
||||
|
@ -39,6 +39,9 @@ Zebra <- R6::R6Class(
|
||||
self$`className` <- `className`
|
||||
}
|
||||
if (!is.null(`type`)) {
|
||||
if (!(`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", `type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
stopifnot(is.character(`type`), length(`type`) == 1)
|
||||
self$`type` <- `type`
|
||||
}
|
||||
@ -82,6 +85,9 @@ Zebra <- R6::R6Class(
|
||||
fromJSON = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`)) {
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
}
|
||||
if (!is.null(this_object$`className`)) {
|
||||
@ -140,6 +146,9 @@ Zebra <- R6::R6Class(
|
||||
#' @export
|
||||
fromJSONString = function(input_json) {
|
||||
this_object <- jsonlite::fromJSON(input_json)
|
||||
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
|
||||
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
|
||||
}
|
||||
self$`type` <- this_object$`type`
|
||||
self$`className` <- this_object$`className`
|
||||
# process additional properties/fields in the payload
|
||||
|
Loading…
x
Reference in New Issue
Block a user