MaxKeywordErrStringLen sets how long a value can be before it's length is truncated when printing error strings a special value of -1 disables output trimming
var MaxKeywordErrStringLen = 20
func DataType(data interface{}) string
DataType attempts to parse the underlying data type from the raw data interface
func DataTypeWithHint(data interface{}, hint string) string
DataTypeWithHint attempts to parse the underlying data type by leveraging the schema expectations for better results
func FetchSchema(ctx context.Context, uri string, schema *Schema) error
FetchSchema downloads and loads a schema from a remote location
func GetKeywordInsertOrder(prop string) int
GetKeywordInsertOrder returns the insert index of the given keyword
func GetKeywordOrder(prop string) int
GetKeywordOrder returns the order index of the given keyword or defaults to 1
func InvalidValueString(data interface{}) string
InvalidValueString returns the errored value as a string
func IsLocalSchemaID(id string) bool
IsLocalSchemaID validates if a given id is a local id
func IsNotSupportedKeyword(prop string) bool
IsNotSupportedKeyword is a utility function to clarify when a given keyword, while expected is not supported
func IsRegisteredKeyword(prop string) bool
IsRegisteredKeyword validates if a given prop string is a registered keyword
func IsRegistryLoaded() bool
IsRegistryLoaded checks if any keywords are present
func LoadDraft2019_09()
LoadDraft2019_09 loads the keywords for schema validation based on draft2019_09 this is also the default keyword set loaded automatically if no other is loaded
func RegisterKeyword(prop string, maker KeyMaker)
RegisterKeyword registers a keyword with the registry
func ResetSchemaRegistry()
ResetSchemaRegistry resets the main SchemaRegistry
func SafeResolveURL(ctxURL, resURL string) (string, error)
SafeResolveURL resolves a string url against the current context url
func SetKeywordOrder(prop string, order int)
SetKeywordOrder assignes a given order to a keyword
AdditionalItems defines the additionalItems JSON Schema keyword
type AdditionalItems Schema
func (ai *AdditionalItems) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for AdditionalItems
func (ai *AdditionalItems) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for AdditionalItems
func (ai *AdditionalItems) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for AdditionalItems
func (ai *AdditionalItems) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for AdditionalItems
AdditionalProperties defines the additionalProperties JSON Schema keyword
type AdditionalProperties Schema
func (ap *AdditionalProperties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for AdditionalProperties
func (ap *AdditionalProperties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for AdditionalProperties
func (ap *AdditionalProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for AdditionalProperties
func (ap *AdditionalProperties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for AdditionalProperties
AllOf defines the allOf JSON Schema keyword
type AllOf []*Schema
func (a AllOf) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for AllOf
func (a AllOf) JSONProp(name string) interface{}
JSONProp implements the JSONPather for AllOf
func (a *AllOf) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for AllOf
func (a *AllOf) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for AllOf
func (a *AllOf) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for AllOf
Anchor defines the $anchor JSON Schema keyword
type Anchor string
func (a *Anchor) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Anchor
func (a *Anchor) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Anchor
func (a *Anchor) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Anchor
AnyOf defines the anyOf JSON Schema keyword
type AnyOf []*Schema
func (a AnyOf) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for AnyOf
func (a AnyOf) JSONProp(name string) interface{}
JSONProp implements the JSONPather for AnyOf
func (a *AnyOf) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for AnyOf
func (a *AnyOf) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for AnyOf
func (a *AnyOf) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for AnyOf
Comment defines the comment JSON Schema keyword
type Comment string
func (c *Comment) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Comment
func (c *Comment) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Comment
func (c *Comment) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Comment
Const defines the const JSON Schema keyword
type Const json.RawMessage
func (c Const) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Const
func (c Const) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Const
func (c *Const) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Const
func (c *Const) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Const
func (c Const) String() string
String implements the Stringer for Const
func (c *Const) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Const
func (c Const) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Const
Contains defines the contains JSON Schema keyword
type Contains Schema
func (c Contains) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Contains
func (c Contains) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Contains
func (c *Contains) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Contains
func (c *Contains) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Contains
func (c *Contains) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Contains
func (c *Contains) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Contains
Default defines the default JSON Schema keyword
type Default struct {
// contains filtered or unexported fields
}
func (d *Default) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Default
func (d *Default) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Default
func (d *Default) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Default
func (d *Default) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Default
Defs defines the $defs JSON Schema keyword
type Defs map[string]*Schema
func (d Defs) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Defs
func (d Defs) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Defs
func (d *Defs) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Defs
func (d *Defs) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Defs
func (d Defs) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Defs
DependentRequired defines the dependentRequired JSON Schema keyword
type DependentRequired map[string]PropertyDependency
func (d DependentRequired) JSONChildren() (r map[string]JSONPather)
JSONChildren implements the JSONContainer interface for DependentRequired
func (d DependentRequired) JSONProp(name string) interface{}
JSONProp implements the JSONPather for DependentRequired
func (d DependentRequired) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for DependentRequired
func (d *DependentRequired) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for DependentRequired
func (d *DependentRequired) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for DependentRequired
func (d *DependentRequired) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for DependentRequired
func (d *DependentRequired) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for DependentRequired
DependentSchemas defines the dependentSchemas JSON Schema keyword
type DependentSchemas map[string]SchemaDependency
func (d DependentSchemas) JSONChildren() (r map[string]JSONPather)
JSONChildren implements the JSONContainer interface for DependentSchemas
func (d DependentSchemas) JSONProp(name string) interface{}
JSONProp implements the JSONPather for DependentSchemas
func (d *DependentSchemas) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for DependentSchemas
func (d *DependentSchemas) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for DependentSchemas
func (d *DependentSchemas) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for DependentSchemas
func (d *DependentSchemas) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for DependentSchemas
Description defines the description JSON Schema keyword
type Description string
func (d *Description) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Description
func (d *Description) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Description
func (d *Description) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Description
Else defines the else JSON Schema keyword
type Else Schema
func (e Else) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Else
func (e Else) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Else
func (e Else) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Else
func (e *Else) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Else
func (e *Else) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Else
func (e *Else) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Else
func (e *Else) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Else
Enum defines the enum JSON Schema keyword
type Enum []Const
func (e Enum) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Enum
func (e Enum) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Enum
func (e *Enum) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Enum
func (e *Enum) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Enum
func (e Enum) String() string
String implements the Stringer for Enum
func (e Enum) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Enum
Examples defines the examples JSON Schema keyword
type Examples []interface{}
func (e *Examples) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Examples
func (e *Examples) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Examples
func (e *Examples) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Examples
ExclusiveMaximum defines the exclusiveMaximum JSON Schema keyword
type ExclusiveMaximum float64
func (m *ExclusiveMaximum) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for ExclusiveMaximum
func (m *ExclusiveMaximum) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for ExclusiveMaximum
func (m ExclusiveMaximum) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for ExclusiveMaximum
ExclusiveMinimum defines the exclusiveMinimum JSON Schema keyword
type ExclusiveMinimum float64
func (m *ExclusiveMinimum) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for ExclusiveMinimum
func (m *ExclusiveMinimum) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for ExclusiveMinimum
func (m ExclusiveMinimum) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for ExclusiveMinimum
Format defines the format JSON Schema keyword
type Format string
func (f *Format) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Format
func (f *Format) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Format
func (f Format) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Format
ID defines the $id JSON Schema keyword
type ID string
func (i *ID) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for ID
func (i *ID) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for ID
func (i *ID) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for ID
If defines the if JSON Schema keyword
type If Schema
func (f If) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for If
func (f If) JSONProp(name string) interface{}
JSONProp implements the JSONPather for If
func (f If) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for If
func (f *If) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for If
func (f *If) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for If
func (f *If) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for If
func (f *If) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for If
Items defines the items JSON Schema keyword
type Items struct { Schemas []*Schema // contains filtered or unexported fields }
func (it Items) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Items
func (it Items) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Items
func (it Items) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Items
func (it *Items) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Items
func (it *Items) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Items
func (it *Items) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Items
func (it Items) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Items
JSONContainer is an interface that enables tree traversal by listing the immideate children of an object
type JSONContainer interface { // JSONChildren should return all immidiate children of this element JSONChildren() map[string]JSONPather }
JSONPather makes validators traversible by JSON-pointers, which is required to support references in JSON schemas.
type JSONPather interface { // JSONProp take a string references for a given JSON property // implementations must return any matching property of that name // or nil if no such subproperty exists. // Note this also applies to array values, which are expected to interpret // valid numbers as an array index JSONProp(name string) interface{} }
KeyError represents a single error in an instance of a schema The only absolutely-required property is Message.
type KeyError struct { // PropertyPath is a string path that leads to the // property that produced the error PropertyPath string `json:"propertyPath,omitempty"` // InvalidValue is the value that returned the error InvalidValue interface{} `json:"invalidValue,omitempty"` // Message is a human-readable description of the error Message string `json:"message"` }
func (v KeyError) Error() string
Error implements the error interface for KeyError
KeyMaker is a function that generates instances of a Keyword. Calls to KeyMaker will be passed directly to json.Marshal, so the returned value should be a pointer
type KeyMaker func() Keyword
Keyword is an interface for anything that can validate. JSON-Schema keywords are all examples of Keyword
type Keyword interface { // ValidateKeyword checks decoded JSON data and writes // validation errors (if any) to an outparam slice of KeyErrors ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{}) // Register builds up the schema tree by evaluating the current key // and the current location pointer which is later used with resolve to // navigate the schema tree and substitute the propper schema for a given // reference. Register(uri string, registry *SchemaRegistry) // Resolve unraps a pointer to the destination schema // It usually starts with a $ref validation call which // uses the pointer token by token to navigate the // schema tree to get to the last schema in the chain. // Since every keyword can have it's specifics around resolving // each keyword need to implement it's own version of Resolve. // Terminal keywords should respond with nil as it's not a schema // Keywords that wrap a schema should return the appropriate schema. // In case of a non-existing location it will fail to resolve, return nil // on ref resolution and error out. Resolve(pointer jptr.Pointer, uri string) *Schema }
func GetKeyword(prop string) Keyword
GetKeyword returns a new instance of the keyword
func NewAdditionalItems() Keyword
NewAdditionalItems allocates a new AdditionalItems keyword
func NewAdditionalProperties() Keyword
NewAdditionalProperties allocates a new AdditionalProperties keyword
func NewAllOf() Keyword
NewAllOf allocates a new AllOf keyword
func NewAnchor() Keyword
NewAnchor allocates a new Anchor keyword
func NewAnyOf() Keyword
NewAnyOf allocates a new AnyOf keyword
func NewComment() Keyword
NewComment allocates a new Comment keyword
func NewConst() Keyword
NewConst allocates a new Const keyword
func NewContains() Keyword
NewContains allocates a new Contains keyword
func NewDefault() Keyword
NewDefault allocates a new Default keyword
func NewDefs() Keyword
NewDefs allocates a new Defs keyword
func NewDependentRequired() Keyword
NewDependentRequired allocates a new DependentRequired keyword
func NewDependentSchemas() Keyword
NewDependentSchemas allocates a new DependentSchemas keyword
func NewDescription() Keyword
NewDescription allocates a new Description keyword
func NewElse() Keyword
NewElse allocates a new Else keyword
func NewEnum() Keyword
NewEnum allocates a new Enum keyword
func NewExamples() Keyword
NewExamples allocates a new Examples keyword
func NewExclusiveMaximum() Keyword
NewExclusiveMaximum allocates a new ExclusiveMaximum keyword
func NewExclusiveMinimum() Keyword
NewExclusiveMinimum allocates a new ExclusiveMinimum keyword
func NewFormat() Keyword
NewFormat allocates a new Format keyword
func NewID() Keyword
NewID allocates a new Id keyword
func NewIf() Keyword
NewIf allocates a new If keyword
func NewItems() Keyword
NewItems allocates a new Items keyword
func NewMaxContains() Keyword
NewMaxContains allocates a new MaxContains keyword
func NewMaxItems() Keyword
NewMaxItems allocates a new MaxItems keyword
func NewMaxLength() Keyword
NewMaxLength allocates a new MaxLength keyword
func NewMaxProperties() Keyword
NewMaxProperties allocates a new MaxProperties keyword
func NewMaximum() Keyword
NewMaximum allocates a new Maximum keyword
func NewMinContains() Keyword
NewMinContains allocates a new MinContains keyword
func NewMinItems() Keyword
NewMinItems allocates a new MinItems keyword
func NewMinLength() Keyword
NewMinLength allocates a new MinLength keyword
func NewMinProperties() Keyword
NewMinProperties allocates a new MinProperties keyword
func NewMinimum() Keyword
NewMinimum allocates a new Minimum keyword
func NewMultipleOf() Keyword
NewMultipleOf allocates a new MultipleOf keyword
func NewNot() Keyword
NewNot allocates a new Not keyword
func NewOneOf() Keyword
NewOneOf allocates a new OneOf keyword
func NewPattern() Keyword
NewPattern allocates a new Pattern keyword
func NewPatternProperties() Keyword
NewPatternProperties allocates a new PatternProperties keyword
func NewProperties() Keyword
NewProperties allocates a new Properties keyword
func NewPropertyNames() Keyword
NewPropertyNames allocates a new PropertyNames keyword
func NewReadOnly() Keyword
NewReadOnly allocates a new ReadOnly keyword
func NewRecursiveAnchor() Keyword
NewRecursiveAnchor allocates a new RecursiveAnchor keyword
func NewRecursiveRef() Keyword
NewRecursiveRef allocates a new RecursiveRef keyword
func NewRef() Keyword
NewRef allocates a new Ref keyword
func NewRequired() Keyword
NewRequired allocates a new Required keyword
func NewSchema() Keyword
NewSchema allocates a new Schema Keyword/Validator
func NewSchemaURI() Keyword
NewSchemaURI allocates a new SchemaURI keyword
func NewThen() Keyword
NewThen allocates a new Then keyword
func NewTitle() Keyword
NewTitle allocates a new Title keyword
func NewType() Keyword
NewType allocates a new Type keyword
func NewUnevaluatedItems() Keyword
NewUnevaluatedItems allocates a new UnevaluatedItems keyword
func NewUnevaluatedProperties() Keyword
NewUnevaluatedProperties allocates a new UnevaluatedProperties keyword
func NewUniqueItems() Keyword
NewUniqueItems allocates a new UniqueItems keyword
func NewVoid() Keyword
NewVoid allocates a new Void keyword
func NewWriteOnly() Keyword
NewWriteOnly allocates a new WriteOnly keyword
MaxContains defines the maxContains JSON Schema keyword
type MaxContains int
func (m *MaxContains) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MaxContains
func (m *MaxContains) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MaxContains
func (m MaxContains) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MaxContains
MaxItems defines the maxItems JSON Schema keyword
type MaxItems int
func (m *MaxItems) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MaxItems
func (m *MaxItems) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MaxItems
func (m MaxItems) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MaxItems
MaxLength defines the maxLenght JSON Schema keyword
type MaxLength int
func (m *MaxLength) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MaxLength
func (m *MaxLength) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MaxLength
func (m MaxLength) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MaxLength
MaxProperties defines the maxProperties JSON Schema keyword
type MaxProperties int
func (m *MaxProperties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MaxProperties
func (m *MaxProperties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MaxProperties
func (m MaxProperties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MaxProperties
Maximum defines the maximum JSON Schema keyword
type Maximum float64
func (m *Maximum) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Maximum
func (m *Maximum) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Maximum
func (m Maximum) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Maximum
MinContains defines the minContains JSON Schema keyword
type MinContains int
func (m *MinContains) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MinContains
func (m *MinContains) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MinContains
func (m MinContains) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MinContains
MinItems defines the minItems JSON Schema keyword
type MinItems int
func (m *MinItems) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MinItems
func (m *MinItems) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MinItems
func (m MinItems) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MinItems
MinLength defines the maxLenght JSON Schema keyword
type MinLength int
func (m *MinLength) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MinLength
func (m *MinLength) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MinLength
func (m MinLength) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MinLength
MinProperties defines the minProperties JSON Schema keyword
type MinProperties int
func (m *MinProperties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MinProperties
func (m *MinProperties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MinProperties
func (m MinProperties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MinProperties
Minimum defines the minimum JSON Schema keyword
type Minimum float64
func (m *Minimum) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Minimum
func (m *Minimum) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Minimum
func (m Minimum) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Minimum
MultipleOf defines the multipleOf JSON Schema keyword
type MultipleOf float64
func (m *MultipleOf) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for MultipleOf
func (m *MultipleOf) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for MultipleOf
func (m MultipleOf) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for MultipleOf
Not defines the not JSON Schema keyword
type Not Schema
func (n Not) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Not
func (n Not) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Not
func (n Not) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Not
func (n *Not) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Not
func (n *Not) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Not
func (n *Not) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Not
func (n *Not) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Not
OneOf defines the oneOf JSON Schema keyword
type OneOf []*Schema
func (o OneOf) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for OneOf
func (o OneOf) JSONProp(name string) interface{}
JSONProp implements the JSONPather for OneOf
func (o *OneOf) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for OneOf
func (o *OneOf) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for OneOf
func (o *OneOf) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for OneOf
Pattern defines the pattern JSON Schema keyword
type Pattern regexp.Regexp
func (p Pattern) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Pattern
func (p *Pattern) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Pattern
func (p *Pattern) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Pattern
func (p *Pattern) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Pattern
func (p Pattern) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Pattern
PatternProperties defines the patternProperties JSON Schema keyword
type PatternProperties []patternSchema
func (p PatternProperties) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for PatternProperties
func (p PatternProperties) JSONProp(name string) interface{}
JSONProp implements the JSONPather for PatternProperties
func (p PatternProperties) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for PatternProperties
func (p *PatternProperties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for PatternProperties
func (p *PatternProperties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for PatternProperties
func (p *PatternProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for PatternProperties
func (p PatternProperties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for PatternProperties
Properties defines the properties JSON Schema keyword
type Properties map[string]*Schema
func (p Properties) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Properties
func (p Properties) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Properties
func (p *Properties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Properties
func (p *Properties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Properties
func (p Properties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Properties
PropertyDependency is the internal representation of a dependent property
type PropertyDependency struct {
// contains filtered or unexported fields
}
func (p PropertyDependency) JSONProp(name string) interface{}
JSONProp implements the JSONPather for PropertyDependency
func (p *PropertyDependency) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for PropertyDependency
func (p *PropertyDependency) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for PropertyDependency
func (p *PropertyDependency) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for PropertyDependency
PropertyNames defines the propertyNames JSON Schema keyword
type PropertyNames Schema
func (p PropertyNames) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for PropertyNames
func (p PropertyNames) JSONProp(name string) interface{}
JSONProp implements the JSONPather for PropertyNames
func (p PropertyNames) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for PropertyNames
func (p *PropertyNames) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for PropertyNames
func (p *PropertyNames) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for PropertyNames
func (p *PropertyNames) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for PropertyNames
func (p *PropertyNames) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for PropertyNames
ReadOnly defines the readOnly JSON Schema keyword
type ReadOnly bool
func (r *ReadOnly) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for ReadOnly
func (r *ReadOnly) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for ReadOnly
func (r *ReadOnly) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for ReadOnly
RecursiveAnchor defines the $recursiveAnchor JSON Schema keyword
type RecursiveAnchor Schema
func (r *RecursiveAnchor) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for RecursiveAnchor
func (r *RecursiveAnchor) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for RecursiveAnchor
func (r *RecursiveAnchor) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for RecursiveAnchor
func (r *RecursiveAnchor) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for RecursiveAnchor
RecursiveRef defines the $recursiveRef JSON Schema keyword
type RecursiveRef struct {
// contains filtered or unexported fields
}
func (r RecursiveRef) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for RecursiveRef
func (r *RecursiveRef) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for RecursiveRef
func (r *RecursiveRef) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for RecursiveRef
func (r *RecursiveRef) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for RecursiveRef
func (r *RecursiveRef) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for RecursiveRef
Ref defines the $ref JSON Schema keyword
type Ref struct {
// contains filtered or unexported fields
}
func (r Ref) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Ref
func (r *Ref) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Ref
func (r *Ref) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Ref
func (r *Ref) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Ref
func (r *Ref) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Ref
Required defines the required JSON Schema keyword
type Required []string
func (r Required) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Required
func (r *Required) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Required
func (r *Required) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Required
func (r Required) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Required
Schema is the top-level structure defining a json schema
type Schema struct {
// contains filtered or unexported fields
}
func Must(jsonString string) *Schema
Must turns a JSON string into a *Schema, panicing if parsing fails. Useful for declaring Schemas in Go code.
func (s *Schema) HasKeyword(key string) bool
HasKeyword is a utility function for checking if the given schema has an instance of the required keyword
func (s Schema) JSONChildren() map[string]JSONPather
JSONChildren implements the JSONContainer interface for Schema
func (s Schema) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Schema
func (s Schema) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Schema
func (s *Schema) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Schema
func (s *Schema) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Schema
func (s *Schema) TopLevelType() string
TopLevelType returns a string representing the schema's top-level type.
func (s *Schema) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Schema
func (s *Schema) Validate(ctx context.Context, data interface{}) *ValidationState
Validate initiates a fresh validation state and triggers the evaluation
func (s *Schema) ValidateBytes(ctx context.Context, data []byte) ([]KeyError, error)
ValidateBytes performs schema validation against a slice of json byte data
func (s *Schema) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword uses the schema to check an instance, collecting validation errors in a slice
SchemaDependency is the internal representation of a dependent schema
type SchemaDependency struct {
// contains filtered or unexported fields
}
func (d SchemaDependency) JSONProp(name string) interface{}
JSONProp implements the JSONPather for SchemaDependency
func (d SchemaDependency) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for SchemaDependency
func (d *SchemaDependency) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for SchemaDependency
func (d *SchemaDependency) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for SchemaDependency
func (d *SchemaDependency) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for SchemaDependency
SchemaRegistry maintains a lookup table between schema string references and actual schemas
type SchemaRegistry struct {
// contains filtered or unexported fields
}
func GetSchemaRegistry() *SchemaRegistry
GetSchemaRegistry provides an accessor to a globally available schema registry
func (sr *SchemaRegistry) Get(ctx context.Context, uri string) *Schema
Get fetches a schema from the top level context registry or fetches it from a remote
func (sr *SchemaRegistry) GetKnown(uri string) *Schema
GetKnown fetches a schema from the top level context registry
func (sr *SchemaRegistry) GetLocal(uri string) *Schema
GetLocal fetches a schema from the local context registry
func (sr *SchemaRegistry) Register(sch *Schema)
Register registers a schema to the top level context
func (sr *SchemaRegistry) RegisterLocal(sch *Schema)
RegisterLocal registers a schema to a local context
SchemaURI defines the $schema JSON Schema keyword
type SchemaURI string
func (s *SchemaURI) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for SchemaURI
func (s *SchemaURI) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for SchemaURI
func (s *SchemaURI) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for SchemaURI
Then defines the then JSON Schema keyword
type Then Schema
func (t Then) JSONChildren() (res map[string]JSONPather)
JSONChildren implements the JSONContainer interface for Then
func (t Then) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Then
func (t Then) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Then
func (t *Then) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Then
func (t *Then) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Then
func (t *Then) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Then
func (t *Then) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Then
Title defines the title JSON Schema keyword
type Title string
func (t *Title) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Title
func (t *Title) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Title
func (t *Title) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Title
Type defines the type JSON Schema keyword
type Type struct {
// contains filtered or unexported fields
}
func (t Type) JSONProp(name string) interface{}
JSONProp implements the JSONPather for Type
func (t Type) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for Type
func (t *Type) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Type
func (t *Type) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Type
func (t Type) String() string
String implements the Stringer for Type
func (t *Type) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for Type
func (t Type) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Type
UnevaluatedItems defines the unevaluatedItems JSON Schema keyword
type UnevaluatedItems Schema
func (ui *UnevaluatedItems) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for UnevaluatedItems
func (ui *UnevaluatedItems) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for UnevaluatedItems
func (ui *UnevaluatedItems) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for UnevaluatedItems
func (ui *UnevaluatedItems) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for UnevaluatedItems
UnevaluatedProperties defines the unevaluatedProperties JSON Schema keyword
type UnevaluatedProperties Schema
func (up *UnevaluatedProperties) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for UnevaluatedProperties
func (up *UnevaluatedProperties) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for UnevaluatedProperties
func (up *UnevaluatedProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for UnevaluatedProperties
func (up *UnevaluatedProperties) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for UnevaluatedProperties
UniqueItems defines the uniqueItems JSON Schema keyword
type UniqueItems bool
func (u *UniqueItems) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for UniqueItems
func (u *UniqueItems) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for UniqueItems
func (u UniqueItems) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for UniqueItems
ValidationState holds the schema validation state The aim is to have one global validation state and use local sub states when evaluating parallel branches TODO(arqu): make sure this is safe for concurrent use
type ValidationState struct { Local *Schema Root *Schema RecursiveAnchor *Schema BaseURI string InstanceLocation *jptr.Pointer RelativeLocation *jptr.Pointer BaseRelativeLocation *jptr.Pointer LocalRegistry *SchemaRegistry EvaluatedPropertyNames *map[string]bool LocalEvaluatedPropertyNames *map[string]bool LastEvaluatedIndex int LocalLastEvaluatedIndex int Misc map[string]interface{} Errs *[]KeyError }
func NewValidationState(s *Schema) *ValidationState
NewValidationState creates a new ValidationState with the provided location pointers and data instance
func (vs *ValidationState) AddError(data interface{}, msg string)
AddError creates and appends a KeyError to errs of the current state
func (vs *ValidationState) AddSubErrors(errs ...KeyError)
AddSubErrors appends a list of KeyError to the current state
func (vs *ValidationState) ClearState()
ClearState resets a schema to it's core elements
func (vs *ValidationState) DescendBase(token ...string)
DescendBase descends the base relative pointer relative to itself
func (vs *ValidationState) DescendBaseFromState(base *ValidationState, token ...string)
DescendBaseFromState descends the base relative pointer relative to the provided state
func (vs *ValidationState) DescendInstance(token ...string)
DescendInstance descends the instance pointer relative to itself
func (vs *ValidationState) DescendInstanceFromState(base *ValidationState, token ...string)
DescendInstanceFromState descends the instance pointer relative to the provided state
func (vs *ValidationState) DescendRelative(token ...string)
DescendRelative descends the relative pointer relative to itself
func (vs *ValidationState) DescendRelativeFromState(base *ValidationState, token ...string)
DescendRelativeFromState descends the relative pointer relative to the provided state
func (vs *ValidationState) IsEvaluatedKey(key string) bool
IsEvaluatedKey checks if the key is evaluated against the state context
func (vs *ValidationState) IsLocallyEvaluatedKey(key string) bool
IsLocallyEvaluatedKey checks if the key is evaluated against the local state context
func (vs *ValidationState) IsValid() bool
IsValid returns if the current state is valid
func (vs *ValidationState) NewSubState() *ValidationState
NewSubState creates a new ValidationState from an existing ValidationState
func (vs *ValidationState) SetEvaluatedIndex(i int)
SetEvaluatedIndex sets the evaluation index for the current state
func (vs *ValidationState) SetEvaluatedKey(key string)
SetEvaluatedKey updates the evaluation properties of the current state
func (vs *ValidationState) UpdateEvaluatedPropsAndItems(subState *ValidationState)
UpdateEvaluatedPropsAndItems is a utility function to join evaluated properties and set the current evaluation position index
Void is a placeholder definition for a keyword
type Void struct{}
func (vo *Void) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for Void
func (vo *Void) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for Void
func (vo *Void) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for Void
WriteOnly defines the writeOnly JSON Schema keyword
type WriteOnly bool
func (w *WriteOnly) Register(uri string, registry *SchemaRegistry)
Register implements the Keyword interface for WriteOnly
func (w *WriteOnly) Resolve(pointer jptr.Pointer, uri string) *Schema
Resolve implements the Keyword interface for WriteOnly
func (w *WriteOnly) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{})
ValidateKeyword implements the Keyword interface for WriteOnly