#' Create a new Library
#'
#' @description
#' Library Class
#'
#' @docType class
#' @title Library
#' @description Library Class
#' @format An \code{R6Class} generator object
#' @field id integer [optional]
#' @field name character
#' @field version character
#' @field createdAt The date and time when the feature was created. character [optional]
#' @field updatedAt The date and time when the feature was last updated. character [optional]
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @keywords internal
Library <- R6::R6Class(
"Library",
public = list(
`id` = NULL,
`name` = NULL,
`version` = NULL,
`createdAt` = NULL,
`updatedAt` = NULL,
#' @description
#' Initialize a new Library class.
#'
#' @param name name
#' @param version version
#' @param id id
#' @param createdAt The date and time when the feature was created.
#' @param updatedAt The date and time when the feature was last updated.
#' @param ... Other optional arguments.
initialize = function(`name`, `version`, `id` = NULL, `createdAt` = NULL, `updatedAt` = NULL, ...) {
if (!missing(`name`)) {
if (!(is.character(`name`) && length(`name`) == 1)) {
stop(paste("Error! Invalid data for `name`. Must be a string:", `name`))
}
self$`name` <- `name`
}
if (!missing(`version`)) {
if (!(is.character(`version`) && length(`version`) == 1)) {
stop(paste("Error! Invalid data for `version`. Must be a string:", `version`))
}
self$`version` <- `version`
}
if (!is.null(`id`)) {
if (!(is.numeric(`id`) && length(`id`) == 1)) {
stop(paste("Error! Invalid data for `id`. Must be an integer:", `id`))
}
self$`id` <- `id`
}
if (!is.null(`createdAt`)) {
if (!is.character(`createdAt`)) {
stop(paste("Error! Invalid data for `createdAt`. Must be a string:", `createdAt`))
}
self$`createdAt` <- `createdAt`
}
if (!is.null(`updatedAt`)) {
if (!is.character(`updatedAt`)) {
stop(paste("Error! Invalid data for `updatedAt`. Must be a string:", `updatedAt`))
}
self$`updatedAt` <- `updatedAt`
}
},
#' @description
#' To JSON String
#'
#' @return Library in JSON format
toJSON = function() {
LibraryObject <- list()
if (!is.null(self$`id`)) {
LibraryObject[["id"]] <-
self$`id`
}
if (!is.null(self$`name`)) {
LibraryObject[["name"]] <-
self$`name`
}
if (!is.null(self$`version`)) {
LibraryObject[["version"]] <-
self$`version`
}
if (!is.null(self$`createdAt`)) {
LibraryObject[["createdAt"]] <-
self$`createdAt`
}
if (!is.null(self$`updatedAt`)) {
LibraryObject[["updatedAt"]] <-
self$`updatedAt`
}
LibraryObject
},
#' @description
#' Deserialize JSON string into an instance of Library
#'
#' @param input_json the JSON input
#' @return the instance of Library
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`id`)) {
self$`id` <- this_object$`id`
}
if (!is.null(this_object$`name`)) {
self$`name` <- this_object$`name`
}
if (!is.null(this_object$`version`)) {
self$`version` <- this_object$`version`
}
if (!is.null(this_object$`createdAt`)) {
self$`createdAt` <- this_object$`createdAt`
}
if (!is.null(this_object$`updatedAt`)) {
self$`updatedAt` <- this_object$`updatedAt`
}
self
},
#' @description
#' To JSON String
#'
#' @return Library in JSON format
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`id`)) {
sprintf(
'"id":
%d
',
self$`id`
)
},
if (!is.null(self$`name`)) {
sprintf(
'"name":
"%s"
',
self$`name`
)
},
if (!is.null(self$`version`)) {
sprintf(
'"version":
"%s"
',
self$`version`
)
},
if (!is.null(self$`createdAt`)) {
sprintf(
'"createdAt":
"%s"
',
self$`createdAt`
)
},
if (!is.null(self$`updatedAt`)) {
sprintf(
'"updatedAt":
"%s"
',
self$`updatedAt`
)
}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
json_string <- as.character(jsonlite::minify(paste("{", jsoncontent, "}", sep = "")))
},
#' @description
#' Deserialize JSON string into an instance of Library
#'
#' @param input_json the JSON input
#' @return the instance of Library
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
self$`id` <- this_object$`id`
self$`name` <- this_object$`name`
self$`version` <- this_object$`version`
self$`createdAt` <- this_object$`createdAt`
self$`updatedAt` <- this_object$`updatedAt`
self
},
#' @description
#' Validate JSON input with respect to Library and throw an exception if invalid
#'
#' @param input the JSON input
validateJSON = function(input) {
input_json <- jsonlite::fromJSON(input)
# check the required field `name`
if (!is.null(input_json$`name`)) {
if (!(is.character(input_json$`name`) && length(input_json$`name`) == 1)) {
stop(paste("Error! Invalid data for `name`. Must be a string:", input_json$`name`))
}
} else {
stop(paste("The JSON input `", input, "` is invalid for Library: the required field `name` is missing."))
}
# check the required field `version`
if (!is.null(input_json$`version`)) {
if (!(is.character(input_json$`version`) && length(input_json$`version`) == 1)) {
stop(paste("Error! Invalid data for `version`. Must be a string:", input_json$`version`))
}
} else {
stop(paste("The JSON input `", input, "` is invalid for Library: the required field `version` is missing."))
}
},
#' @description
#' To string (JSON format)
#'
#' @return String representation of Library
toString = function() {
self$toJSONString()
},
#' @description
#' Return true if the values in all fields are valid.
#'
#' @return true if the values in all fields are valid.
isValid = function() {
# check if the required `name` is null
if (is.null(self$`name`)) {
return(FALSE)
}
# check if the required `version` is null
if (is.null(self$`version`)) {
return(FALSE)
}
TRUE
},
#' @description
#' Return a list of invalid fields (if any).
#'
#' @return A list of invalid fields (if any).
getInvalidFields = function() {
invalid_fields <- list()
# check if the required `name` is null
if (is.null(self$`name`)) {
invalid_fields["name"] <- "Non-nullable required field `name` cannot be null."
}
# check if the required `version` is null
if (is.null(self$`version`)) {
invalid_fields["version"] <- "Non-nullable required field `version` cannot be null."
}
invalid_fields
},
#' @description
#' Print the object
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
# Library$unlock()
#
## Below is an example to define the print function
# Library$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
# Library$lock()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.