Skip to contents

The schema object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superset of the JSON Schema Specification Draft 2020-12.

Usage

class_schema(
  type = c("string", "number", "integer", "boolean", "array", "object"),
  ...,
  nullable = FALSE,
  description = character(),
  format = character()
)

Arguments

type

Factor (or coercible to factor). The type of object being defined. Currently must be one of "string", "number", "integer", "boolean", "array", or "object".

...

These dots are for future extensions and must be empty.

nullable

Logical scalar (default FALSE). Whether the parameter can be set to NULL.

description

Character scalar (optional). A description of the object defined by the schema.

format

Character scalar (optional). The format of the object. Essentially a sub-type.

Value

A schema S7 object describing the data type, with fields type, nullable, description, and format.

Examples

class_schema("string")
#> <rapid::schema>
#>  @ type       : Factor w/ 6 levels "string","number",..: 1
#>  .. - attr(*, "initialized")= logi TRUE
#>  @ nullable   : logi FALSE
#>  @ description: chr(0) 
#>  @ format     : chr(0) 
class_schema("string", nullable = TRUE, description = "A nullable string.")
#> <rapid::schema>
#>  @ type       : Factor w/ 6 levels "string","number",..: 1
#>  .. - attr(*, "initialized")= logi TRUE
#>  @ nullable   : logi TRUE
#>  @ description: chr "A nullable string."
#>  @ format     : chr(0)