The read direction of S7_to_JSONSchema: reads each property's
PropertySpec back out of the schema and assembles a live S7 class whose
properties carry the same types, bounds, enums, containers, and validators as
the class the schema was generated from.
Usage
JSONSchema_to_S7(
schema,
defaults = NULL,
refs = NULL,
name = NULL,
package = NULL,
authoring = NULL,
declarations = NULL,
schemas = NULL,
decode_reference = NULL,
parent = NULL,
policies = NULL
)Arguments
- schema
Named list: A JSON Schema, as produced by S7_to_JSONSchema or parsed from the published tree with
jsonlite::fromJSON(simplifyVector = FALSE).- defaults
Optional named list: Format version 1 defaults artifact, or explicit property declaration values for an independently supplied schema.
- refs
Optional named list: Property name to S7 class, for properties published as a
$refto another schema.- name
Optional Character: Class name. Defaults to the schema
title.- package
Optional Character: Package name recorded on the class.
Optional named list: Property name to logical authorship policy, from the separate authoring artifact under this schema's
$id.- declarations
Optional List: Declaration descriptors keyed by schema pointer.
- schemas
Optional List: Complete parsed schema graph keyed by canonical ID. Used with a format version 1 artifact to reconstruct typed references without source classes.
- decode_reference
Optional Function: Reference decoder for a custom artifact graph.
- parent
Optional S7 class: Reconstructed parent type.
- policies
Optional List: Serialized input policy descriptors.
Details
Defaults are supplied in a separate versioned artifact keyed by schema $id.
The published schemas carry no default keywords. Absent declaration defaults remain absent;
constructing a non-nullable property without a default requires a value.
Properties holding a nested config are published as a $ref to that config's
own schema. Supply the parsed graph through schemas and the format version 1
artifact through defaults to reconstruct these references. Independently
supplied S7 reference classes can be passed through refs.
Reconstructed constructors use declaration defaults; input resolution policies
remain separate metadata on the class.
Examples
# A schema as `S7_to_JSONSchema()` emits it: standard keywords carry the
# bounds, `x-rtemis` carries the leaf type.
schema <- list(
title = "Demo",
properties = list(
k = list(
type = "integer",
minimum = 1L,
maximum = 10L,
description = "Number of components.",
`x-rtemis` = list(type = "integer")
)
)
)
Demo <- JSONSchema_to_S7(schema, defaults = list(k = 2L))
Demo()@k#> [1] 2Demo(k = 5L)@k#> [1] 5# The reconstructed class enforces the schema's bounds.
tryCatch(Demo(k = 99L), error = conditionMessage)#> [1] "<Demo> object properties are invalid:\n- @k must be <= 10."