Skip to contents

Assembles the <family>/v1 schema for a config family: an object with an algorithm discriminator and an algorithm-specific payload (config / hyperparameters), plus an allOf of if/then clauses that validate the payload against the per-algorithm leaf schema (<family>/<algorithm>/v1) selected by algorithm. The algorithm enum, the leaf $ref URLs, and the allOf table are all derived from the classes, so the dispatcher cannot drift from the leaves it dispatches to.

Usage

S7_dispatcher_JSONSchema(
  classes,
  id,
  discriminator = "algorithm",
  payload = "config",
  base = NULL,
  title = NULL,
  description = "",
  discriminator_description = "Algorithm name.",
  record = FALSE,
  instance_schema_url = NULL
)

Arguments

classes

List of S7 classes: the family's per-variant subclasses (each carries a computed constant discriminator property).

id

Character: Dispatcher $id URL (e.g. "https://schema.rtemis.org/decomposition/v1/schema.json").

discriminator

Character: Name of the property that selects the variant (e.g. "algorithm", "type").

payload

Character or NULL: Name of the variant-specific field (e.g. "config", "hyperparameters"). NULL selects top-level mode, where the variant's fields are siblings of the discriminator (see Details).

base

Optional S7 class: The family base class. Its own prop_*-declared properties are shared by every variant, so they are emitted here rather than on any leaf (see Details).

title

Optional Character: Schema title.

description

Character: Schema description. If empty, omitted.

discriminator_description

Character: Description of the discriminator property.

record

Logical: If TRUE, dispatch to the variants' record schemas (<family>/<variant>/v1/record.json) rather than their input schemas. The discriminator and payload are required either way; what changes is which leaf each if/then branch applies.

instance_schema_url

Character or NULL: If set, adds a $schema const property so instances can self-identify.

Value

Named list: the dispatcher JSON Schema. Serialize with write_JSONSchema.

Details

The leaf URLs are derived from id: for a dispatcher .../<family>/v1/schema.json, algorithm A maps to .../<family>/<tolower(A)>/v1/schema.json – matching S7_to_JSONSchema's id convention for the leaves.

Two shapes, matching how the R classes serialize:

  • Nested payload (payload set): the variant's parameters live in one object (config / hyperparameters), so each then narrows that property to the leaf $ref. Leaves are closed (additionalProperties: false) and independently valid.

  • Top-level mode (payload = NULL): the variant's fields are siblings of the discriminator (as in ResamplerConfig), so each then applies the leaf $ref to the whole object. additionalProperties is evaluated per-schema and would not see the leaf's properties, so strictness comes from draft 2020-12's unevaluatedProperties: false, which does account for properties evaluated by the applied $ref. Leaves for this mode must be generated open (closed = FALSE in S7_to_JSONSchema) so they compose.

base closes the loop with S7_to_JSONSchema's base argument, which subtracts the family base's properties from every leaf: the dispatcher adds them back at the top level, from the same PropertySpec, so the shared fields are declared once. Base properties carrying no spec are class machinery (the computed payload list, run state) and are skipped, as is the discriminator, which is generated from the variant enum.

Author

EDG

Examples

if (FALSE) { # \dontrun{
schema <- S7_dispatcher_JSONSchema(
  classes = list(PCAConfig, ICAConfig),
  id = "https://schema.rtemis.org/decomposition/v1/schema.json",
  payload = "config"
)
} # }