Documentation ¶
Index ¶
- func DeepEqual(a1, a2 interface{}) bool
- type EmbeddedSchemas
- type NeighborChecker
- type Node
- type Schema
- func (s *Schema) Parse(schemaBytes io.Reader, loadExternalSchemas bool) error
- func (s *Schema) ParseWithoutRefs(schemaBytes io.Reader) error
- func (s *Schema) ResolveRefs(loadExternal bool)
- func (s *Schema) UnmarshalJSON(bts []byte) error
- func (s *Schema) Validate(keypath []string, v interface{}) []ValidationError
- type SchemaEmbedder
- type SchemaSetter
- type ValidationError
- type Validator
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 ¶
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 ¶
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 ¶
func ParseWithCache ¶
func (*Schema) ResolveRefs ¶
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 (*Schema) Validate ¶
func (s *Schema) Validate(keypath []string, v interface{}) []ValidationError
type SchemaEmbedder ¶
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 ¶
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
}