Documentation
¶
Overview ¶
Package configschema validates configuration against JSON Schema, as one implementation of config.Schema.
The core defines what validating a configuration means and takes no position on how a schema is expressed; this module supplies the dialect, the library and the ingestion. That split is what keeps a JSON Schema dependency out of the twenty-five adapter modules that depend on config and do not want one — see the composable schema validation spec, D7.
Several components each declare the configuration they need, mounted where the assembling code decides, and the Store validates the merged result against all of them at once:
config.NewStore(ctx,
config.WithFiles(fsys, "app.yaml"),
config.WithSchemaAt("plugins.cache", cacheSchema),
config.WithSchemaAt("server", serverSchema, config.Required),
)
Every failure names the document that raised it, because a report aggregating several components is not actionable if it cannot say whose expectation was violated.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is a compiled JSON Schema document that satisfies config.Schema.
func FromJSON ¶
FromJSON compiles a JSON Schema document.
name identifies the contributor in failure reports — use the component's name rather than a filename, because it is what a reader has to act on.
Compilation happens here rather than at validation time so a malformed document fails once, at wiring, instead of on every load.
func FromStruct ¶
FromStruct derives a JSON Schema from the `config:` tags this estate already uses to declare configuration.
It exists because no off-the-shelf reflector can do this job. Checked against invopop/jsonschema v0.14.0: it reflects Go **structure**, and these tags encode **path**. Given
Host string `config:"server.host"`
on a flat struct, a reflector emits a flat property named for the Go field and ignores the tag entirely. The nesting a dotted path implies is not present in the type, so nothing can infer it — expanding it has to be done here.
Recognised tags, matching what config's own tag schema reads:
config:"a.b.c" the dotted path, and the only required tag validate:"required" marks the key required at its own level enum:"x,y,z" restricts the value description:"..." carried into the schema
A field with no `config:` tag is skipped, and one tagged `-` is excluded.
func (*Schema) Validate ¶
Validate implements config.Schema.
at is where this document was mounted. The schema is written in its own terms — "enabled", "ttl" — and failures are reported at the full path, because a relative key is not one a user could edit.