Skip to contents

Add a schema definition

Usage

schema_add_def(x, name, value, overwrite = FALSE)

Arguments

x

A SchemaDoc.

name

Definition name to add.

value

Schema fragment using the same list syntax accepted by schema_doc(), or a fragment produced by helpers such as schema_check(), to store in $defs.

overwrite

Logical flag indicating whether an existing definition of the same name should be replaced.

Value

A modified SchemaDoc.

Examples

schema <- schema_doc(schema_check("string"))
schema <- schema_add_def(schema, "text", schema_check("string"))
schema
#> {
#>   "$defs": {
#>     "text": {
#>       "check": {
#>         "kind": "string"
#>       }
#>     }
#>   },
#>   "check": {
#>     "kind": "string"
#>   }
#> }

names(as.list(schema)$`$defs`)
#> [1] "text"