Documentation ¶
Overview ¶
Package jsonschema converts JSON Schema to CUE
JSON Schema data is presented in CUE, so any of the supported encodings that can represent JSON Schema data can be used as a source.
Package jsonschema implements the JSON schema standard.
Mapping and Linking ¶
JSON Schema are often defined in a single file. CUE, on the other hand idiomatically defines schema as a definition.
CUE:
$schema: which schema is used for validation. $id: which validation does this schema provide. Foo: _ @jsonschema(sc) @source(https://...) // What schema is used to validate.
NOTE: JSON Schema is a draft standard and may undergo backwards incompatible changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMapURL ¶ added in v0.10.0
DefaultMapURL implements the default schema ID to import path mapping. It trims off any ".json" suffix and uses the package name "schema" if the final component of the path isn't a valid CUE identifier.
Types ¶
type Config ¶
type Config struct { PkgName string // ID sets the URL of the original source, corresponding to the $id field. ID string // JSON reference of location containing schema. The empty string indicates // that there is a single schema at the root. // // Examples: // "#/" top-level fields are schemas. // "#/components/schemas" the canonical OpenAPI location. Root string // Map maps the locations of schemas and definitions to a new location. // References are updated accordingly. A returned label must be // an identifier or string literal. // // The default mapping is // {} {} // {"definitions", foo} {#foo} or {#, foo} // {"$defs", foo} {#foo} or {#, foo} Map func(pos token.Pos, path []string) ([]ast.Label, error) // MapURL maps a URL reference as found in $ref to // an import path for a package. // If this is nil, [DefaultMapURL] will be used. MapURL func(u *url.URL) (importPath string, err error) // Strict reports an error for unsupported features, rather than ignoring // them. Strict bool // contains filtered or unexported fields }
A Config configures a JSON Schema encoding or decoding.