assert_config_contract: Assert a generated config schema honors the input-schema...

View source: R/schema_contract.R

assert_config_contractR Documentation

Assert a generated config schema honors the input-schema contract

Description

Checks one generated JSON Schema against the rules a config document must obey, and throws if any is broken. Shared by every package that publishes to schema.rtemis.org – rtemis and rtemis.draw – so one registry cannot hold documents held to two standards.

Usage

assert_config_contract(schema, id = schema[["$id"]], structural = character())

Arguments

schema

Named list: The generated schema, as S7_to_JSONSchema() or S7_dispatcher_JSONSchema() returns it.

id

Character: The schema's ⁠$id⁠, used to name it in the error.

structural

Character: Keys this schema may require because they carry the document's shape rather than a value – a family dispatcher's discriminator. Empty for a leaf or a flat config.

Details

Five rules, each recorded where it is raised:

  • No top-level required beyond the key carrying the document's shape: a family dispatcher's discriminator, which selects the variant whose settings are its siblings. A config is otherwise a partial expression of intent.

  • No default: defaults are versioned separately, in defaults/v1.

  • No conditional demand for a key (then/⁠else⁠ with required, or dependentRequired): an implementation could satisfy it by filling a value, which makes it a resolution rule and belongs to the record form.

  • No R construct named in a description: the corpus is language-independent and is read by R, by the Rust CLI, by the browser, and by a model that writes no code at all.

  • No R spelling of a value in a description: NULL, TRUE, FALSE, NA and the ⁠@property⁠ accessor are R, not JSON.

The first three are about what a config may demand, and record schemas are not subject to them: a record states what a run used, so everything in it is required. The last two are about prose, which every published document has; assert_description_language() applies just those, for a record or a result class that does not come through here.

Value

The schema, invisibly, so it can wrap a write call. Throws with class simpleError listing every rule broken, so one run reports all of them rather than the first.

Author(s)

EDG

Examples

assert_config_contract(
  list(type = "object", properties = list(k = list(type = "integer"))),
  "https://schema.rtemis.org/example/v1/schema.json"
)

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.