Documentation
¶
Overview ¶
Package schema is hyper's own schema engine — the reading rule and the object shape it reads against (§3, §12, ADR-0081). A scalar is read against the schema at its position, never compared with it: the value's characters are read as the declared type, in the text form §12 fixes, and the quoting YAML required is lexical rather than part of the value. additionalProperties: false is forced at every level rather than authored, so an object's Properties are its complete key set and nothing here ever widens them.
This is not the input-schema subset a Manifest's Operation writes in (four keywords, authored, closed by §12 on its own). It is the schema hyper holds for its own five artefacts, compiled in rather than written anywhere a reviewer reads — Check is what "hyper reads it against hyper's own schema for that artefact" means.
Index ¶
Constants ¶
const ( CodeMismatch = "schema-mismatch" CodeUnknownKey = "unknown-key" )
The two codes hyper's own schema declines under (§4, §12). additionalProperties: false is forced rather than authored, so CodeUnknownKey refuses the one constraint hyper imposes and CodeMismatch refuses a value against what an author wrote — a value whose characters will not read as the declared type, a key the schema declares that the file does not supply, and a value outside its enum are all one check and this one code (ADR-0081).
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check reads root against s and returns one problem per position that does not fit. root is nil where the file supplied no document at all, which reads the same as an object that supplied none of its keys — a required property is schema-mismatch there like anywhere else, at the file's own position for lack of a line of its own to name.
func CheckAt ¶
CheckAt is Check, starting the walk at field rather than at the document root. A name-keyed mapping's own members — a Manifest's operations:, an Operation's http: block — each read their own value against a fixed schema of their own, and the problems they report need the full dotted path to that position rather than one relative to it.
func DurationSeconds ¶
DurationSeconds is an authored duration read as the number of seconds it names — 30s, 2m, 1h, 1d — and false where value is not a duration this grammar admits, which is schema-mismatch at every authored position and no duration for a caller to convert.
It is here rather than at the surface that renders one because the grammar is here: the pattern above is what refuses a value at load, and a second reading of it elsewhere is a second spelling of one closed set (§3, §9).
Types ¶
type Scalar ¶
type Scalar struct {
// contains filtered or unexported fields
}
Scalar is one value read against the type declared at its position: not the characters it arrived as, but §12's two columns for that type — the text it leaves as in a `path:`, `query:`, `headers:` or `command:` position, and the JSON token it leaves as in a `body:` one.
It is one value with two renderings rather than two values, because §12 states one table with two columns and the type decides both: `integer` is decimal digits in a path and a JSON number in a body, and nothing about the value differs between them. A caller holding one of these has already had the reading performed and cannot re-read it differently.
The reading is ADR-0081's, stated once by readsAs above and performed here: the characters are read *as* the declared type rather than compared with a type of their own, so the quoting YAML required is lexical and `"2592000"` and `2592000` are one value at an `integer` position. What this adds to readsAs is the answer — a check needs to know only whether a value reads, and a Run needs what it read to.
func ReadScalar ¶
ReadScalar reads value against the type declared at its position and answers what it read to, or false where the characters will not read as that type — which is `schema-mismatch` at every authored position (§4, ADR-0081) and a usage error at a Probe's `--input`, where nothing authored declined (§9, ADR-0060).
object and array read as nothing at all: both are refused at both sinks, both being reached through a hole and a hole filling a scalar position (§12, ADR-0078). The one place an `array` input reaches anything is the `shell` Capability's argv, which is no sink on that table — `hyper` execs the list rather than serialising it.
func (Scalar) JSON ¶
JSON is what the value writes in a `body:` position — §12's first column, as one JSON token: a quoted string, or the bare literal a number and a boolean are. It is a token rather than a value because a body is serialised compact with its keys in the order they were authored (§3), which is not an encoding encoding/json can be asked for.
type Schema ¶
type Schema struct {
Type Type
// Enum constrains a scalar Type's legal text; empty means unconstrained.
Enum []string
// Properties is legal only where Type == Object, and is the complete
// key set at that position — additionalProperties: false is forced
// rather than authored (§12).
Properties []Property
// Items is legal only where Type == Array, and describes every member.
Items *Schema
// Open marks an Object position that is a mapping keyed by name rather
// than a fixed shape — a Target declaration's auth: mapping, whose
// members are credential slots the repository names itself, is the
// first of these (§4). The generic engine still admits exactly one key
// at the position that holds it and still requires the value to be a
// mapping; it stops there. Reading what a name-keyed mapping's members
// must look like is that position's own rule and its own code, the way
// artefact.checkCredentialSlots reads a credential slot's shape.
Open bool
}
Schema describes what hyper admits at one position.