jsonschema

package
v0.6.2-0...-d734bc3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dereference

func Dereference(fetcher Fetcher, schemas ...Instance) error

Types

type Fetcher

type Fetcher interface {
	GetSchema(uri *url.URL) (s Instance, ok bool, err error) // Retrieve a schema
}

Fetcher fetches a parsed schema, given a URL. The URL may be unclean (have hash fragments)

type Instance

type Instance map[string]interface{}

Instance is an instance of a parsed JSON schema (in generic map[string]interface{} form)

func Merge

func Merge(schemas []Instance) (Instance, error)

Merge merges multiple schema instances into a single one, folding in properties that do not overlap, and

func Sorted

func Sorted(schemas []Instance) ([]Instance, error)

Sorted produces a sorted slice of schemas, based on the following rules:

If one schema is referenced by another in a $ref, then that schema appears before the other

For schemas that are independent of one another, the one with the greatest number of form properties (/definitions/form/properties) appears before those that have fewer.

If two schemas have no dependencies and have the same number of properties, the one that appears first in the initial list will be first in the result.

func (Instance) ID

func (s Instance) ID() string

ID returns the identifier ("$id") of the schema, if present

type Map

type Map map[string]Instance

Map is a simple map of schema URIs to schema instances, serving as a static schema Fetcher

func Load

func Load(filepaths []string) (Map, error)

Load scans the provided list of files and directories recursively and produces a Map of schema id to parsed instance documents

func (Map) Add

func (m Map) Add(src ...io.Reader) error

Add an un-parsed schema to the map. This will parse it, and place it into the map based on the $id present in the schema

func (Map) GetSchema

func (m Map) GetSchema(url *url.URL) (Instance, bool, error)

GetSchema retrieves a schema from the map, given a possibly unclean URL.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates an instance document against its schema

func NewValidator

func NewValidator(schema io.ReadCloser) *Validator

NewValidator creates a JSON schema validator instance for the given schema document

func (*Validator) Validate

func (v *Validator) Validate(instance []byte) error

Validate validates the current schema against an instance JSON document

Jump to

Keyboard shortcuts

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