jsonschema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 11 Imported by: 13

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 idomatically 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 Extract

func Extract(data *cue.Instance, cfg *Config) (f *ast.File, err error)

Extract converts JSON Schema data into an equivalent CUE representation.

The generated CUE schema is guaranteed to deem valid any value that is a valid instance of the source JSON schema.

Types

type Config

type Config struct {
	PkgName string

	ID string // URL of the original source, corresponding to the $id field.

	// 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.
	//
	// The default mapping is
	//    {}                     {"Schema"}
	//    {"definitions", foo}   {"Defs", strings.Title(foo)}
	//    {"$defs", foo}         {"Defs", strings.Title(foo)}
	Map func(pos token.Pos, path []string) ([]string, error)
	// contains filtered or unexported fields
}

A Config configures a JSON Schema encoding or decoding.

Jump to

Keyboard shortcuts

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