Documentation
¶
Overview ¶
Package typebox ports the parts of TypeBox 1.3.27 Value that PiG needs over JSON Schema data: Check, Errors, Clean, Default and Clone, with the format registry and the keyword spellings TypeBox accepts.
Index ¶
- func Check(schema, value any) bool
- func Clean(schema, value any) any
- func Clone(value any) any
- func CompilePattern(pattern string) (*regexp.Regexp, error)
- func CompilerSchema(value any) any
- func Default(schema, value any) any
- func Formats() map[string]func(string) bool
- func Plain(value any) any
- func RegisterFormats(compiler *jsonschema.Compiler)
- type Checker
- type Ordered
- type ValueError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check is Value.Check: whether value matches schema. A schema the validator cannot compile matches nothing.
func Clean ¶
Clean is Value.Clean (value/clean): it removes the properties and tuple elements schema does not evaluate. It mutates value and returns the result.
func Clone ¶
Clone is Value.Clone: a deep copy of a JSON value; objects keep their kind (map or ordered object).
func CompilePattern ¶
CompilePattern is regexp.Compile for a schema's pattern text (patternProperties keys and the like), cached so a schema checked again does not compile its patterns again. A *regexp.Regexp is safe for concurrent use.
func CompilerSchema ¶
CompilerSchema translates the positional items and dependencies TypeBox accepts alongside current JSON Schema keywords into their draft-2020 spellings for the validator, without changing the schema used for conversion or error traversal.
func Default ¶
Default is Value.Default (value/default): it fills absent values that have a schema default. It mutates value and returns the result; an absent root is passed as nil and returned as nil when schema gives it no default.
func Formats ¶
Formats returns the formats of typebox's registry that Pig ports, by name. Every call returns the same map.
func Plain ¶
Plain returns value with every *chordjson.Object as a map[string]any and every Go number as float64, the form the validator reads. Other values are returned as they are.
func RegisterFormats ¶
func RegisterFormats(compiler *jsonschema.Compiler)
RegisterFormats makes the compiler assert the typebox formats.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker is Check for one schema compiled once: Value.Check on a schema a caller holds does not serialize it again for every value. A schema the validator cannot compile matches nothing.
func NewChecker ¶
NewChecker compiles schema (through the compiled-schema cache) for repeated checks.
type Ordered ¶
type Ordered struct {
// contains filtered or unexported fields
}
Ordered is a schema object read from JSON with its members in the order they were declared in, which TypeBox visits them in (properties, patternProperties, dependencies) and JSON.stringify writes them in. It keeps the members as a map as well, built once when the schema is decoded, so a reader looks a member up, or asks for its map, without copying. An Ordered is immutable after NewOrdered: it is safe for concurrent readers and is released with the schema holding it.
func NewOrdered ¶
NewOrdered is the object whose members are members, listed in keys order. Neither is changed afterwards by the caller.
type ValueError ¶
type ValueError struct {
Keyword string
SchemaPath string
InstancePath string
Message string
// contains filtered or unexported fields
}
ValueError is one error of Errors, as TypeBox reports it: the keyword that failed, the schema path of the failing schema, the instance path of the failing value ("" for the root; member names appended unescaped, as TypeBox does) and the en_US message.
func (ValueError) ParamsObject ¶
func (e ValueError) ParamsObject() *chordjson.Object
ParamsObject is the error's params object, its members in the order TypeBox writes them (empty for none).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package engine is TypeBox 1.3.27's type-system engine (build/type/{action,engine,extends,script} and the parts of build/type/types and build/system the engine uses), ported once for the host.
|
Package engine is TypeBox 1.3.27's type-system engine (build/type/{action,engine,extends,script} and the parts of build/type/types and build/system the engine uses), ported once for the host. |