Nathan Baulch 9f1fa0e440
Fix another batch of spelling typos (#13915)
* Fix typos

* Remove repeated words

* Minor grammar fixes
2022-11-07 21:30:24 +08:00

258 lines
7.8 KiB
R

#' Create a new DanishPig
#'
#' @description
#' DanishPig Class
#'
#' @docType class
#' @title DanishPig
#' @description DanishPig Class
#' @format An \code{R6Class} generator object
#' @field className character
#' @field size integer
#' @field _field_list a list of fields list(character)
#' @field additional_properties additional properties list(character) [optional]
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
DanishPig <- R6::R6Class(
"DanishPig",
public = list(
`className` = NULL,
`size` = NULL,
`_field_list` = c("className", "size"),
`additional_properties` = list(),
#' Initialize a new DanishPig class.
#'
#' @description
#' Initialize a new DanishPig class.
#'
#' @param className className
#' @param size size
#' @param additional_properties additional properties (optional)
#' @param ... Other optional arguments.
#' @export
initialize = function(`className`, `size`, additional_properties = NULL, ...) {
if (!missing(`className`)) {
if (!(is.character(`className`) && length(`className`) == 1)) {
stop(paste("Error! Invalid data for `className`. Must be a string:", `className`))
}
self$`className` <- `className`
}
if (!missing(`size`)) {
if (!(is.numeric(`size`) && length(`size`) == 1)) {
stop(paste("Error! Invalid data for `size`. Must be an integer:", `size`))
}
self$`size` <- `size`
}
if (!is.null(additional_properties)) {
for (key in names(additional_properties)) {
self$additional_properties[[key]] <- additional_properties[[key]]
}
}
},
#' To JSON string
#'
#' @description
#' To JSON String
#'
#' @return DanishPig in JSON format
#' @export
toJSON = function() {
DanishPigObject <- list()
if (!is.null(self$`className`)) {
DanishPigObject[["className"]] <-
self$`className`
}
if (!is.null(self$`size`)) {
DanishPigObject[["size"]] <-
self$`size`
}
for (key in names(self$additional_properties)) {
DanishPigObject[[key]] <- self$additional_properties[[key]]
}
DanishPigObject
},
#' Deserialize JSON string into an instance of DanishPig
#'
#' @description
#' Deserialize JSON string into an instance of DanishPig
#'
#' @param input_json the JSON input
#' @return the instance of DanishPig
#' @export
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`className`)) {
self$`className` <- this_object$`className`
}
if (!is.null(this_object$`size`)) {
self$`size` <- this_object$`size`
}
# process additional properties/fields in the payload
for (key in names(this_object)) {
if (!(key %in% self$`_field_list`)) { # json key not in list of fields
self$additional_properties[[key]] <- this_object[[key]]
}
}
self
},
#' To JSON string
#'
#' @description
#' To JSON String
#'
#' @return DanishPig in JSON format
#' @export
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`className`)) {
sprintf(
'"className":
"%s"
',
self$`className`
)
},
if (!is.null(self$`size`)) {
sprintf(
'"size":
%d
',
self$`size`
)
}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
json_obj <- jsonlite::fromJSON(json_string)
for (key in names(self$additional_properties)) {
json_obj[[key]] <- self$additional_properties[[key]]
}
json_string <- as.character(jsonlite::minify(jsonlite::toJSON(json_obj, auto_unbox = TRUE, digits = NA)))
},
#' Deserialize JSON string into an instance of DanishPig
#'
#' @description
#' Deserialize JSON string into an instance of DanishPig
#'
#' @param input_json the JSON input
#' @return the instance of DanishPig
#' @export
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`className` <- this_object$`className`
self$`size` <- this_object$`size`
# process additional properties/fields in the payload
for (key in names(this_object)) {
if (!(key %in% self$`_field_list`)) { # json key not in list of fields
self$additional_properties[[key]] <- this_object[[key]]
}
}
self
},
#' Validate JSON input with respect to DanishPig
#'
#' @description
#' Validate JSON input with respect to DanishPig and throw an exception if invalid
#'
#' @param input the JSON input
#' @export
validateJSON = function(input) {
input_json <- jsonlite::fromJSON(input)
# check the required field `className`
if (!is.null(input_json$`className`)) {
if (!(is.character(input_json$`className`) && length(input_json$`className`) == 1)) {
stop(paste("Error! Invalid data for `className`. Must be a string:", input_json$`className`))
}
} else {
stop(paste("The JSON input `", input, "` is invalid for DanishPig: the required field `className` is missing."))
}
# check the required field `size`
if (!is.null(input_json$`size`)) {
if (!(is.numeric(input_json$`size`) && length(input_json$`size`) == 1)) {
stop(paste("Error! Invalid data for `size`. Must be an integer:", input_json$`size`))
}
} else {
stop(paste("The JSON input `", input, "` is invalid for DanishPig: the required field `size` is missing."))
}
},
#' To string (JSON format)
#'
#' @description
#' To string (JSON format)
#'
#' @return String representation of DanishPig
#' @export
toString = function() {
self$toJSONString()
},
#' Return true if the values in all fields are valid.
#'
#' @description
#' Return true if the values in all fields are valid.
#'
#' @return true if the values in all fields are valid.
#' @export
isValid = function() {
# check if the required `className` is null
if (is.null(self$`className`)) {
return(FALSE)
}
# check if the required `size` is null
if (is.null(self$`size`)) {
return(FALSE)
}
TRUE
},
#' Return a list of invalid fields (if any).
#'
#' @description
#' Return a list of invalid fields (if any).
#'
#' @return A list of invalid fields (if any).
#' @export
getInvalidFields = function() {
invalid_fields <- list()
# check if the required `className` is null
if (is.null(self$`className`)) {
invalid_fields["className"] <- "Non-nullable required field `className` cannot be null."
}
# check if the required `size` is null
if (is.null(self$`size`)) {
invalid_fields["size"] <- "Non-nullable required field `size` cannot be null."
}
invalid_fields
},
#' Print the object
#'
#' @description
#' Print the object
#'
#' @export
print = function() {
print(jsonlite::prettify(self$toJSONString()))
invisible(self)
}
),
# Lock the class to prevent modifications to the method or field
lock_class = TRUE
)
## Uncomment below to unlock the class to allow modifications of the method or field
# DanishPig$unlock()
#
## Below is an example to define the print function
# DanishPig$set("public", "print", function(...) {
# print(jsonlite::prettify(self$toJSONString()))
# invisible(self)
# })
## Uncomment below to lock the class to prevent modifications to the method or field
# DanishPig$lock()