typebox

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(schema, value any) bool

Check is Value.Check: whether value matches schema. A schema the validator cannot compile matches nothing.

func Clean

func Clean(schema, value any) any

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

func Clone(value any) any

Clone is Value.Clone: a deep copy of a JSON value; objects keep their kind (map or ordered object).

func CompilePattern

func CompilePattern(pattern string) (*regexp.Regexp, error)

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

func CompilerSchema(value any) any

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

func Default(schema, value any) any

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

func Formats() map[string]func(string) bool

Formats returns the formats of typebox's registry that Pig ports, by name. Every call returns the same map.

func Plain

func Plain(value any) any

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 ValueError

type ValueError struct {
	InstancePath string
	Message      string
}

ValueError is one error of Errors: the instance path of the failing value ("" for the root; member names appended unescaped, as TypeBox does) and the en_US message.

func Errors

func Errors(schema, value any) []ValueError

Errors is Value.Errors(schema, value).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL