jsonschema

package module
v0.0.0-...-dfda4fa Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: BSD-3-Clause Imports: 14 Imported by: 7

README

Test Setup

git submodule update --init

Test

go test

Note that tests load external schemas by default.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepEqual

func DeepEqual(a1, a2 interface{}) bool

DeepEqual tests for deep equality. It uses normal == equality where possible but will scan elements of arrays, slices, maps, and fields of structs. In maps, keys are compared with == but elements use deep equality. DeepEqual correctly handles recursive types. Functions are equal only if they are both nil. An empty slice is not equal to a nil slice.

Types

type EmbeddedSchemas

type EmbeddedSchemas map[string]*Schema

Using a pointer allows us to handle recursive embedded schemas.

func (*EmbeddedSchemas) UnmarshalArray

func (e *EmbeddedSchemas) UnmarshalArray(b []byte) error

func (*EmbeddedSchemas) UnmarshalJSON

func (e *EmbeddedSchemas) UnmarshalJSON(b []byte) error

func (*EmbeddedSchemas) UnmarshalObject

func (e *EmbeddedSchemas) UnmarshalObject(b []byte) error

func (*EmbeddedSchemas) UnmarshalSingle

func (e *EmbeddedSchemas) UnmarshalSingle(b []byte) error

type NeighborChecker

type NeighborChecker interface {
	CheckNeighbors(map[string]Node)
}

A NeighborChecker is a validator (such as items) whose validate method depends on neighboring schema keys (such as additionalItems). Unlike SchemaSetters which unmarshal the neighboring key's value a second time, NeighborCheckers are directly linked to the neighboring node.

This has the disadvantage that the neighbor must be an actual validator. If maximum was converted to a NeighborChecker, an exclusiveMaximum validator would have to be created even though its validate method would never return anything other than nil.

It has an advantage over SchemaSetter that if resolveRefs changes the value of an embedded schema in the neighboring node, the NeighborChecker gets access to the new value. For this reason validators that depend on neighboring schemas that can have embedded subschemas must be NeighborCheckers, not SchemaSetters.

type Node

type Node struct {
	EmbeddedSchemas
	Validator
}

type Schema

type Schema struct {
	Cache map[string]*Schema
	// contains filtered or unexported fields
}

func Parse

func Parse(schemaBytes io.Reader, loadExternalSchemas bool) (*Schema, error)

func ParseWithCache

func ParseWithCache(schemaBytes io.Reader, loadExternalSchemas bool, schemaCache *map[string]*Schema) (*Schema, error)

func (*Schema) Parse

func (s *Schema) Parse(schemaBytes io.Reader, loadExternalSchemas bool) error

func (*Schema) ParseWithoutRefs

func (s *Schema) ParseWithoutRefs(schemaBytes io.Reader) error

func (*Schema) ResolveRefs

func (s *Schema) ResolveRefs(loadExternal bool)

ResolveRefs starts a depth-first search through a document for schemas containing the 'ref' validator. It completely resolves each one found.

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(bts []byte) error

func (*Schema) Validate

func (s *Schema) Validate(keypath []string, v interface{}) []ValidationError

type SchemaEmbedder

type SchemaEmbedder interface {
	LinkEmbedded() map[string]*Schema
}

A temporary interface for use until code is written to access a validator's EmbeddedSchemas field with reflection.

type SchemaSetter

type SchemaSetter interface {
	SetSchema(map[string]json.RawMessage) error
}

A SchemaSetter is a validator (such as maximum) whose validate method depends on neighboring schema keys (such as exclusiveMaximum). When a SchemaSetter is unmarshaled from JSON, SetSchema is called on its neighbors to see if any of them are relevant to the validator being unmarshaled.

TODO: should this be deprecated in favor of NeighborChecker?

type ValidationError

type ValidationError struct {
	Keypath     []string
	Description string
}

func (*ValidationError) DotNotation

func (e *ValidationError) DotNotation() string

func (*ValidationError) JSONPointer

func (e *ValidationError) JSONPointer() string

type Validator

type Validator interface {
	Validate([]string, interface{}) []ValidationError
}

Jump to

Keyboard shortcuts

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