Emits the schema for one ChartConfig subclass: every property it declares
or inherits, typed from its PropertySpec, plus a constant for the type
discriminator. The result is self-contained – it validates a chart document
on its own, without the family dispatcher.
Arguments
- cls
S7 class: A ChartConfig subclass.
- id
Character: The schema's
$idURL.- title
Character: Human-readable schema title.
- description
Character: What this chart is.
- complete
Logical: If TRUE, emit the output-config kind, requiring every property.
Value
Named list: The JSON Schema, ready for jsonlite::toJSON().
Details
Two kinds, differing only in what they require:
complete = FALSE(an input config) requires onlytype. The author sets a subset and the interface fills in the rest.complete = TRUE(an output config) requires every property, so a document that claims to be complete can be checked rather than trusted. The chart's own properties may still be null – "this chart has no title" is a fact worth recording – but the provenance maps may not: a document that cannot say where its values came from is not complete, whatever it claims.
Neither emits a default: what an interface fills in is not a fact about
the document. Shared structural class rules are emitted in allOf, including
inherited rules. Input schemas allow omitted values to be resolved by an
interface; record schemas require every value. Numeric ordering, bound-column
contents, and statistical/data-dependent checks still run during construction
or compilation and cannot be inferred from JSON Schema validation alone.
Examples
schema <- chart_schema(
ScatterConfig,
id = "https://schema.rtemis.org/chart/scatter/v1/schema.json",
title = "rtemis ScatterConfig",
description = "Scatter chart."
)
names(schema[["properties"]])#> [1] "type" "dat_path" "title" "origin"
#> [5] "writer" "legend_position" "legend_placement" "x"
#> [9] "y" "size" "group" "hover"
#> [13] "fit_name" "rug" "fit" "se"
#> [17] "se_times" "rsq" "diagonal" "diagonal_color"
#> [21] "n_fit" "fit_alpha" "palette" "square"
#> [25] "equal_axes" "pad" "xlim" "ylim"
#> [29] "xlab" "ylab" "margin_top" "margin_right"
#> [33] "margin_bottom" "margin_left"