[R][Client] allow to initialize enum classes without parameters (#18183)

* allow empty initialization of enum classes

* regenerate samples
This commit is contained in:
Jonas Emmert 2024-03-21 04:21:41 +01:00 committed by GitHub
parent ed8b7ec7f6
commit 2600eb92dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 6 deletions

View File

@ -21,11 +21,21 @@
val <- unlist(local.optional.var) val <- unlist(local.optional.var)
enumvec <- .parse_{{name}}() enumvec <- .parse_{{name}}()
if (length(val) == 0L) {
val = "DUMMY_ENUM"
} else {
stopifnot(length(val) == 1L) stopifnot(length(val) == 1L)
}
if (!val %in% enumvec) if (!val %in% enumvec) {
if (!(val=="DUMMY_ENUM")) {
stop("Use one of the valid values: ", stop("Use one of the valid values: ",
paste0(enumvec, collapse = ", ")) paste0(enumvec, collapse = ", "))
}
warning("Initializing {{{classname}}} with DUMMY_ENUM. Use one of the valid values: ",
paste0(enumvec, collapse = ", "),
". If you did not manually initialize {{{classname}}}, this may already be overwritten by an enum loaded from a JSON config.")
}
private$value <- val private$value <- val
}, },
#' To JSON string #' To JSON string

View File

@ -20,11 +20,21 @@ StringEnumRef <- R6::R6Class(
val <- unlist(local.optional.var) val <- unlist(local.optional.var)
enumvec <- .parse_StringEnumRef() enumvec <- .parse_StringEnumRef()
if (length(val) == 0L) {
val = "DUMMY_ENUM"
} else {
stopifnot(length(val) == 1L) stopifnot(length(val) == 1L)
}
if (!val %in% enumvec) if (!val %in% enumvec) {
if (!(val=="DUMMY_ENUM")) {
stop("Use one of the valid values: ", stop("Use one of the valid values: ",
paste0(enumvec, collapse = ", ")) paste0(enumvec, collapse = ", "))
}
warning("Initializing StringEnumRef with DUMMY_ENUM. Use one of the valid values: ",
paste0(enumvec, collapse = ", "),
". If you did not manually initialize StringEnumRef, this may already be overwritten by an enum loaded from a JSON config.")
}
private$value <- val private$value <- val
}, },
#' To JSON string #' To JSON string