...

Package gojsonschema

import "github.com/xeipuuv/gojsonschema"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
type AdditionalPropertyNotAllowedError
type ArrayContainsError
type ArrayMaxItemsError
type ArrayMaxPropertiesError
type ArrayMinItemsError
type ArrayMinPropertiesError
type ArrayNoAdditionalItemsError
type ConditionElseError
type ConditionThenError
type ConstError
type DateFormatChecker
    func (f DateFormatChecker) IsFormat(input interface{}) bool
type DateTimeFormatChecker
    func (f DateTimeFormatChecker) IsFormat(input interface{}) bool
type DefaultJSONLoaderFactory
    func (d DefaultJSONLoaderFactory) New(source string) JSONLoader
type DefaultLocale
    func (l DefaultLocale) AdditionalPropertyNotAllowed() string
    func (l DefaultLocale) ArrayContains() string
    func (l DefaultLocale) ArrayMaxItems() string
    func (l DefaultLocale) ArrayMaxProperties() string
    func (l DefaultLocale) ArrayMinItems() string
    func (l DefaultLocale) ArrayMinProperties() string
    func (l DefaultLocale) ArrayNoAdditionalItems() string
    func (l DefaultLocale) ArrayNotEnoughItems() string
    func (l DefaultLocale) CannotBeGT() string
    func (l DefaultLocale) CannotBeUsedWithout() string
    func (l DefaultLocale) ConditionElse() string
    func (l DefaultLocale) ConditionThen() string
    func (l DefaultLocale) Const() string
    func (l DefaultLocale) DoesNotMatchFormat() string
    func (l DefaultLocale) DoesNotMatchPattern() string
    func (l DefaultLocale) Duplicated() string
    func (l DefaultLocale) Enum() string
    func (l DefaultLocale) ErrorFormat() string
    func (l DefaultLocale) False() string
    func (l DefaultLocale) GreaterThanZero() string
    func (l DefaultLocale) HttpBadStatus() string
    func (l DefaultLocale) Internal() string
    func (l DefaultLocale) InvalidPropertyName() string
    func (l DefaultLocale) InvalidPropertyPattern() string
    func (l DefaultLocale) InvalidType() string
    func (l DefaultLocale) KeyCannotBeGreaterThan() string
    func (l DefaultLocale) KeyItemsMustBeOfType() string
    func (l DefaultLocale) KeyItemsMustBeUnique() string
    func (l DefaultLocale) MissingDependency() string
    func (l DefaultLocale) MultipleOf() string
    func (l DefaultLocale) MustBeGTEZero() string
    func (l DefaultLocale) MustBeOfA() string
    func (l DefaultLocale) MustBeOfAn() string
    func (l DefaultLocale) MustBeOfType() string
    func (l DefaultLocale) MustBeValidFormat() string
    func (l DefaultLocale) MustBeValidRegex() string
    func (l DefaultLocale) NotAValidType() string
    func (l DefaultLocale) NumberAllOf() string
    func (l DefaultLocale) NumberAnyOf() string
    func (l DefaultLocale) NumberGT() string
    func (l DefaultLocale) NumberGTE() string
    func (l DefaultLocale) NumberLT() string
    func (l DefaultLocale) NumberLTE() string
    func (l DefaultLocale) NumberNot() string
    func (l DefaultLocale) NumberOneOf() string
    func (l DefaultLocale) ParseError() string
    func (l DefaultLocale) ReferenceMustBeCanonical() string
    func (l DefaultLocale) RegexPattern() string
    func (l DefaultLocale) Required() string
    func (l DefaultLocale) StringGTE() string
    func (l DefaultLocale) StringLTE() string
    func (l DefaultLocale) Unique() string
type DoesNotMatchFormatError
type DoesNotMatchPatternError
type Draft
type EmailFormatChecker
    func (f EmailFormatChecker) IsFormat(input interface{}) bool
type EnumError
type ErrorDetails
type FalseError
type FileSystemJSONLoaderFactory
    func (f FileSystemJSONLoaderFactory) New(source string) JSONLoader
type FormatChecker
type FormatCheckerChain
    func (c *FormatCheckerChain) Add(name string, f FormatChecker) *FormatCheckerChain
    func (c *FormatCheckerChain) Has(name string) bool
    func (c *FormatCheckerChain) IsFormat(name string, input interface{}) bool
    func (c *FormatCheckerChain) Remove(name string) *FormatCheckerChain
type HostnameFormatChecker
    func (f HostnameFormatChecker) IsFormat(input interface{}) bool
type IPV4FormatChecker
    func (f IPV4FormatChecker) IsFormat(input interface{}) bool
type IPV6FormatChecker
    func (f IPV6FormatChecker) IsFormat(input interface{}) bool
type InternalError
type InvalidPropertyNameError
type InvalidPropertyPatternError
type InvalidTypeError
type ItemsMustBeUniqueError
type JSONLoader
    func NewBytesLoader(source []byte) JSONLoader
    func NewGoLoader(source interface{}) JSONLoader
    func NewRawLoader(source interface{}) JSONLoader
    func NewReaderLoader(source io.Reader) (JSONLoader, io.Reader)
    func NewReferenceLoader(source string) JSONLoader
    func NewReferenceLoaderFileSystem(source string, fs http.FileSystem) JSONLoader
    func NewStringLoader(source string) JSONLoader
    func NewWriterLoader(source io.Writer) (JSONLoader, io.Writer)
type JSONLoaderFactory
type JSONPointerFormatChecker
    func (f JSONPointerFormatChecker) IsFormat(input interface{}) bool
type JsonContext
    func NewJsonContext(head string, tail *JsonContext) *JsonContext
    func (c *JsonContext) String(del ...string) string
type MissingDependencyError
type MultipleOfError
type NumberAllOfError
type NumberAnyOfError
type NumberGTEError
type NumberGTError
type NumberLTEError
type NumberLTError
type NumberNotError
type NumberOneOfError
type RegexFormatChecker
    func (f RegexFormatChecker) IsFormat(input interface{}) bool
type RelativeJSONPointerFormatChecker
    func (f RelativeJSONPointerFormatChecker) IsFormat(input interface{}) bool
type RequiredError
type Result
    func Validate(ls JSONLoader, ld JSONLoader) (*Result, error)
    func (v *Result) AddError(err ResultError, details ErrorDetails)
    func (v *Result) Errors() []ResultError
    func (v *Result) Valid() bool
type ResultError
type ResultErrorFields
    func (v *ResultErrorFields) Context() *JsonContext
    func (v *ResultErrorFields) Description() string
    func (v *ResultErrorFields) DescriptionFormat() string
    func (v *ResultErrorFields) Details() ErrorDetails
    func (v *ResultErrorFields) Field() string
    func (v *ResultErrorFields) SetContext(context *JsonContext)
    func (v *ResultErrorFields) SetDescription(description string)
    func (v *ResultErrorFields) SetDescriptionFormat(descriptionFormat string)
    func (v *ResultErrorFields) SetDetails(details ErrorDetails)
    func (v *ResultErrorFields) SetType(errorType string)
    func (v *ResultErrorFields) SetValue(value interface{})
    func (v ResultErrorFields) String() string
    func (v *ResultErrorFields) Type() string
    func (v *ResultErrorFields) Value() interface{}
type Schema
    func NewSchema(l JSONLoader) (*Schema, error)
    func (d *Schema) SetRootSchemaName(name string)
    func (v *Schema) Validate(l JSONLoader) (*Result, error)
type SchemaLoader
    func NewSchemaLoader() *SchemaLoader
    func (sl *SchemaLoader) AddSchema(url string, loader JSONLoader) error
    func (sl *SchemaLoader) AddSchemas(loaders ...JSONLoader) error
    func (sl *SchemaLoader) Compile(rootSchema JSONLoader) (*Schema, error)
type StringLengthGTEError
type StringLengthLTEError
type TimeFormatChecker
    func (f TimeFormatChecker) IsFormat(input interface{}) bool
type URIFormatChecker
    func (f URIFormatChecker) IsFormat(input interface{}) bool
type URIReferenceFormatChecker
    func (f URIReferenceFormatChecker) IsFormat(input interface{}) bool
type URITemplateFormatChecker
    func (f URITemplateFormatChecker) IsFormat(input interface{}) bool
type UUIDFormatChecker
    func (f UUIDFormatChecker) IsFormat(input interface{}) bool

Package files

draft.go errors.go format_checkers.go internalLog.go jsonContext.go jsonLoader.go locales.go result.go schema.go schemaLoader.go schemaPool.go schemaReferencePool.go schemaType.go subSchema.go types.go utils.go validation.go

Constants

constants

const (
    STRING_NUMBER                     = "number"
    STRING_ARRAY_OF_STRINGS           = "array of strings"
    STRING_ARRAY_OF_SCHEMAS           = "array of schemas"
    STRING_SCHEMA                     = "valid schema"
    STRING_SCHEMA_OR_ARRAY_OF_STRINGS = "schema or array of strings"
    STRING_PROPERTIES                 = "properties"
    STRING_DEPENDENCY                 = "dependency"
    STRING_PROPERTY                   = "property"
    STRING_UNDEFINED                  = "undefined"
    STRING_CONTEXT_ROOT               = "(root)"
    STRING_ROOT_SCHEMA_PROPERTY       = "(root)"
)

Constants

const (
    KEY_SCHEMA                = "$schema"
    KEY_ID                    = "id"
    KEY_ID_NEW                = "$id"
    KEY_REF                   = "$ref"
    KEY_TITLE                 = "title"
    KEY_DESCRIPTION           = "description"
    KEY_TYPE                  = "type"
    KEY_ITEMS                 = "items"
    KEY_ADDITIONAL_ITEMS      = "additionalItems"
    KEY_PROPERTIES            = "properties"
    KEY_PATTERN_PROPERTIES    = "patternProperties"
    KEY_ADDITIONAL_PROPERTIES = "additionalProperties"
    KEY_PROPERTY_NAMES        = "propertyNames"
    KEY_DEFINITIONS           = "definitions"
    KEY_MULTIPLE_OF           = "multipleOf"
    KEY_MINIMUM               = "minimum"
    KEY_MAXIMUM               = "maximum"
    KEY_EXCLUSIVE_MINIMUM     = "exclusiveMinimum"
    KEY_EXCLUSIVE_MAXIMUM     = "exclusiveMaximum"
    KEY_MIN_LENGTH            = "minLength"
    KEY_MAX_LENGTH            = "maxLength"
    KEY_PATTERN               = "pattern"
    KEY_FORMAT                = "format"
    KEY_MIN_PROPERTIES        = "minProperties"
    KEY_MAX_PROPERTIES        = "maxProperties"
    KEY_DEPENDENCIES          = "dependencies"
    KEY_REQUIRED              = "required"
    KEY_MIN_ITEMS             = "minItems"
    KEY_MAX_ITEMS             = "maxItems"
    KEY_UNIQUE_ITEMS          = "uniqueItems"
    KEY_CONTAINS              = "contains"
    KEY_CONST                 = "const"
    KEY_ENUM                  = "enum"
    KEY_ONE_OF                = "oneOf"
    KEY_ANY_OF                = "anyOf"
    KEY_ALL_OF                = "allOf"
    KEY_NOT                   = "not"
    KEY_IF                    = "if"
    KEY_THEN                  = "then"
    KEY_ELSE                  = "else"
)

Type constants

const (
    TYPE_ARRAY   = `array`
    TYPE_BOOLEAN = `boolean`
    TYPE_INTEGER = `integer`
    TYPE_NUMBER  = `number`
    TYPE_NULL    = `null`
    TYPE_OBJECT  = `object`
    TYPE_STRING  = `string`
)

Variables

var (
    // Locale is the default locale to use
    // Library users can overwrite with their own implementation
    Locale locale = DefaultLocale{}

    // ErrorTemplateFuncs allows you to define custom template funcs for use in localization.
    ErrorTemplateFuncs template.FuncMap
)
var (
    // FormatCheckers holds the valid formatters, and is a public variable
    // so library users can add custom formatters
    FormatCheckers = FormatCheckerChain{
        // contains filtered or unexported fields
    }
)

JSON_TYPES hosts the list of type that are supported in JSON

var JSON_TYPES []string

SCHEMA_TYPES hosts the list of type that are supported in schemas

var SCHEMA_TYPES []string

type AdditionalPropertyNotAllowedError

AdditionalPropertyNotAllowedError is produced if an object has additional properties, but not allowed ErrorDetails: property

type AdditionalPropertyNotAllowedError struct {
    ResultErrorFields
}

type ArrayContainsError

ArrayContainsError is produced if an array contains invalid items ErrorDetails:

type ArrayContainsError struct {
    ResultErrorFields
}

type ArrayMaxItemsError

ArrayMaxItemsError is produced if an array contains more items than the allowed maximum ErrorDetails: max

type ArrayMaxItemsError struct {
    ResultErrorFields
}

type ArrayMaxPropertiesError

ArrayMaxPropertiesError is produced if an object contains more properties than the allowed maximum ErrorDetails: max

type ArrayMaxPropertiesError struct {
    ResultErrorFields
}

type ArrayMinItemsError

ArrayMinItemsError is produced if an array contains less items than the allowed minimum ErrorDetails: min

type ArrayMinItemsError struct {
    ResultErrorFields
}

type ArrayMinPropertiesError

ArrayMinPropertiesError is produced if an object contains less properties than the allowed minimum ErrorDetails: min

type ArrayMinPropertiesError struct {
    ResultErrorFields
}

type ArrayNoAdditionalItemsError

ArrayNoAdditionalItemsError is produced if additional items were found, but not allowed ErrorDetails: -

type ArrayNoAdditionalItemsError struct {
    ResultErrorFields
}

type ConditionElseError

ConditionElseError is produced if a condition's "else" condition is invalid ErrorDetails: -

type ConditionElseError struct {
    ResultErrorFields
}

type ConditionThenError

ConditionThenError is produced if a condition's "then" validation is invalid ErrorDetails: -

type ConditionThenError struct {
    ResultErrorFields
}

type ConstError

ConstError indicates a const error ErrorDetails: allowed

type ConstError struct {
    ResultErrorFields
}

type DateFormatChecker

DateFormatChecker verifies date formats

Valid format:

	Full Date: YYYY-MM-DD

Where
	YYYY = 4DIGIT year
	MM = 2DIGIT month ; 01-12
	DD = 2DIGIT day-month ; 01-28, 01-29, 01-30, 01-31 based on month/year
type DateFormatChecker struct{}

func (DateFormatChecker) IsFormat

func (f DateFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted date (YYYY-MM-DD)

type DateTimeFormatChecker

DateTimeFormatChecker verifies date/time formats per RFC3339 5.6

Valid formats:

	Partial Time: HH:MM:SS
	Full Date: YYYY-MM-DD
	Full Time: HH:MM:SSZ-07:00
	Date Time: YYYY-MM-DDTHH:MM:SSZ-0700

Where
	YYYY = 4DIGIT year
	MM = 2DIGIT month ; 01-12
	DD = 2DIGIT day-month ; 01-28, 01-29, 01-30, 01-31 based on month/year
	HH = 2DIGIT hour ; 00-23
	MM = 2DIGIT ; 00-59
	SS = 2DIGIT ; 00-58, 00-60 based on leap second rules
	T = Literal
	Z = Literal

Note: Nanoseconds are also suported in all formats

http://tools.ietf.org/html/rfc3339#section-5.6

type DateTimeFormatChecker struct{}

func (DateTimeFormatChecker) IsFormat

func (f DateTimeFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted date/time per RFC3339 5.6

type DefaultJSONLoaderFactory

DefaultJSONLoaderFactory is the default JSON loader factory

type DefaultJSONLoaderFactory struct {
}

func (DefaultJSONLoaderFactory) New

func (d DefaultJSONLoaderFactory) New(source string) JSONLoader

New creates a new JSON loader for the given source

type DefaultLocale

DefaultLocale is the default locale for this package

type DefaultLocale struct{}

func (DefaultLocale) AdditionalPropertyNotAllowed

func (l DefaultLocale) AdditionalPropertyNotAllowed() string

AdditionalPropertyNotAllowed returns a format-string to format an AdditionalPropertyNotAllowedError

func (DefaultLocale) ArrayContains

func (l DefaultLocale) ArrayContains() string

ArrayContains returns a format-string to format an ArrayContainsError

func (DefaultLocale) ArrayMaxItems

func (l DefaultLocale) ArrayMaxItems() string

ArrayMaxItems returns a format-string to format an ArrayMaxItemsError

func (DefaultLocale) ArrayMaxProperties

func (l DefaultLocale) ArrayMaxProperties() string

ArrayMaxProperties returns a format-string to format an ArrayMaxPropertiesError

func (DefaultLocale) ArrayMinItems

func (l DefaultLocale) ArrayMinItems() string

ArrayMinItems returns a format-string to format an ArrayMinItemsError

func (DefaultLocale) ArrayMinProperties

func (l DefaultLocale) ArrayMinProperties() string

ArrayMinProperties returns a format-string to format an ArrayMinPropertiesError

func (DefaultLocale) ArrayNoAdditionalItems

func (l DefaultLocale) ArrayNoAdditionalItems() string

ArrayNoAdditionalItems returns a format-string to format an ArrayNoAdditionalItemsError

func (DefaultLocale) ArrayNotEnoughItems

func (l DefaultLocale) ArrayNotEnoughItems() string

ArrayNotEnoughItems returns a format-string to format an error for arrays having not enough items to match positional list of schema

func (DefaultLocale) CannotBeGT

func (l DefaultLocale) CannotBeGT() string

CannotBeGT returns a format-string to format an error where a value are greater than allowed

func (DefaultLocale) CannotBeUsedWithout

func (l DefaultLocale) CannotBeUsedWithout() string

CannotBeUsedWithout returns a format-string to format a "cannot be used without" error

func (DefaultLocale) ConditionElse

func (l DefaultLocale) ConditionElse() string

ConditionElse returns a format-string for ConditionElseError errors

func (DefaultLocale) ConditionThen

func (l DefaultLocale) ConditionThen() string

ConditionThen returns a format-string for ConditionThenError errors If/Else

func (DefaultLocale) Const

func (l DefaultLocale) Const() string

Const returns a format-string to format a ConstError

func (DefaultLocale) DoesNotMatchFormat

func (l DefaultLocale) DoesNotMatchFormat() string

DoesNotMatchFormat returns a format-string to format an DoesNotMatchFormatError

func (DefaultLocale) DoesNotMatchPattern

func (l DefaultLocale) DoesNotMatchPattern() string

DoesNotMatchPattern returns a format-string to format an DoesNotMatchPatternError

func (DefaultLocale) Duplicated

func (l DefaultLocale) Duplicated() string

Duplicated returns a format-string to format an error where types are duplicated

func (DefaultLocale) Enum

func (l DefaultLocale) Enum() string

Enum returns a format-string to format an EnumError

func (DefaultLocale) ErrorFormat

func (l DefaultLocale) ErrorFormat() string

ErrorFormat returns a format string for errors Replacement options: field, description, context, value

func (DefaultLocale) False

func (l DefaultLocale) False() string

False returns a format-string for "false" schema validation errors

func (DefaultLocale) GreaterThanZero

func (l DefaultLocale) GreaterThanZero() string

GreaterThanZero returns a format-string to format an error where a number must be greater than zero

func (DefaultLocale) HttpBadStatus

func (l DefaultLocale) HttpBadStatus() string

HttpBadStatus returns a format-string for errors when loading a schema using HTTP

func (DefaultLocale) Internal

func (l DefaultLocale) Internal() string

Internal returns a format-string for internal errors

func (DefaultLocale) InvalidPropertyName

func (l DefaultLocale) InvalidPropertyName() string

InvalidPropertyName returns a format-string to format an InvalidPropertyNameError

func (DefaultLocale) InvalidPropertyPattern

func (l DefaultLocale) InvalidPropertyPattern() string

InvalidPropertyPattern returns a format-string to format an InvalidPropertyPatternError

func (DefaultLocale) InvalidType

func (l DefaultLocale) InvalidType() string

InvalidType returns a format-string for "invalid type" schema validation errors

func (DefaultLocale) KeyCannotBeGreaterThan

func (l DefaultLocale) KeyCannotBeGreaterThan() string

KeyCannotBeGreaterThan returns a format-string to format an error where a value is greater than the maximum allowed

func (DefaultLocale) KeyItemsMustBeOfType

func (l DefaultLocale) KeyItemsMustBeOfType() string

KeyItemsMustBeOfType returns a format-string to format an error where a key is of the wrong type

func (DefaultLocale) KeyItemsMustBeUnique

func (l DefaultLocale) KeyItemsMustBeUnique() string

KeyItemsMustBeUnique returns a format-string to format an error where keys are not unique

func (DefaultLocale) MissingDependency

func (l DefaultLocale) MissingDependency() string

MissingDependency returns a format-string for "missing dependency" schema validation errors

func (DefaultLocale) MultipleOf

func (l DefaultLocale) MultipleOf() string

MultipleOf returns a format-string to format an MultipleOfError

func (DefaultLocale) MustBeGTEZero

func (l DefaultLocale) MustBeGTEZero() string

MustBeGTEZero returns a format-string to format an error where a value must be greater or equal than 0

func (DefaultLocale) MustBeOfA

func (l DefaultLocale) MustBeOfA() string

MustBeOfA returns a format-string to format an error where a value is of the wrong type

func (DefaultLocale) MustBeOfAn

func (l DefaultLocale) MustBeOfAn() string

MustBeOfAn returns a format-string to format an error where a value is of the wrong type

func (DefaultLocale) MustBeOfType

func (l DefaultLocale) MustBeOfType() string

MustBeOfType returns a format-string to format an error where a value does not match the required type

func (DefaultLocale) MustBeValidFormat

func (l DefaultLocale) MustBeValidFormat() string

MustBeValidFormat returns a format-string to format an error where a value does not match the expected format

func (DefaultLocale) MustBeValidRegex

func (l DefaultLocale) MustBeValidRegex() string

MustBeValidRegex returns a format-string to format an error where a regex is invalid

func (DefaultLocale) NotAValidType

func (l DefaultLocale) NotAValidType() string

NotAValidType returns a format-string to format an invalid type error

func (DefaultLocale) NumberAllOf

func (l DefaultLocale) NumberAllOf() string

NumberAllOf returns a format-string for "allOf" schema validation errors

func (DefaultLocale) NumberAnyOf

func (l DefaultLocale) NumberAnyOf() string

NumberAnyOf returns a format-string for "anyOf" schema validation errors

func (DefaultLocale) NumberGT

func (l DefaultLocale) NumberGT() string

NumberGT returns the format string to format a NumberGTError

func (DefaultLocale) NumberGTE

func (l DefaultLocale) NumberGTE() string

NumberGTE returns the format string to format a NumberGTEError

func (DefaultLocale) NumberLT

func (l DefaultLocale) NumberLT() string

NumberLT returns the format string to format a NumberLTError

func (DefaultLocale) NumberLTE

func (l DefaultLocale) NumberLTE() string

NumberLTE returns the format string to format a NumberLTEError

func (DefaultLocale) NumberNot

func (l DefaultLocale) NumberNot() string

NumberNot returns a format-string to format a NumberNotError

func (DefaultLocale) NumberOneOf

func (l DefaultLocale) NumberOneOf() string

NumberOneOf returns a format-string for "oneOf" schema validation errors

func (DefaultLocale) ParseError

func (l DefaultLocale) ParseError() string

ParseError returns a format-string for JSON parsing errors

func (DefaultLocale) ReferenceMustBeCanonical

func (l DefaultLocale) ReferenceMustBeCanonical() string

ReferenceMustBeCanonical returns a format-string to format a "reference must be canonical" error

func (DefaultLocale) RegexPattern

func (l DefaultLocale) RegexPattern() string

RegexPattern returns a format-string to format a regex-pattern error

func (DefaultLocale) Required

func (l DefaultLocale) Required() string

Required returns a format-string for "required" schema validation errors

func (DefaultLocale) StringGTE

func (l DefaultLocale) StringGTE() string

StringGTE returns a format-string to format an StringLengthGTEError

func (DefaultLocale) StringLTE

func (l DefaultLocale) StringLTE() string

StringLTE returns a format-string to format an StringLengthLTEError

func (DefaultLocale) Unique

func (l DefaultLocale) Unique() string

Unique returns a format-string to format an ItemsMustBeUniqueError

type DoesNotMatchFormatError

DoesNotMatchFormatError is produced if a string does not match the defined format ErrorDetails: format

type DoesNotMatchFormatError struct {
    ResultErrorFields
}

type DoesNotMatchPatternError

DoesNotMatchPatternError is produced if a string does not match the defined pattern ErrorDetails: pattern

type DoesNotMatchPatternError struct {
    ResultErrorFields
}

type Draft

Draft is a JSON-schema draft version

type Draft int

Supported Draft versions

const (
    Draft4 Draft = 4
    Draft6 Draft = 6
    Draft7 Draft = 7
    Hybrid Draft = math.MaxInt32
)

type EmailFormatChecker

EmailFormatChecker verifies email address formats

type EmailFormatChecker struct{}

func (EmailFormatChecker) IsFormat

func (f EmailFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted e-mail address

type EnumError

EnumError indicates an enum error ErrorDetails: allowed

type EnumError struct {
    ResultErrorFields
}

type ErrorDetails

ErrorDetails is a map of details specific to each error. While the values will vary, every error will contain a "field" value

type ErrorDetails map[string]interface{}

type FalseError

FalseError. ErrorDetails: -

type FalseError struct {
    ResultErrorFields
}

type FileSystemJSONLoaderFactory

FileSystemJSONLoaderFactory is a JSON loader factory that uses http.FileSystem

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

func (FileSystemJSONLoaderFactory) New

func (f FileSystemJSONLoaderFactory) New(source string) JSONLoader

New creates a new JSON loader for the given source

type FormatChecker

FormatChecker is the interface all formatters added to FormatCheckerChain must implement

type FormatChecker interface {
    // IsFormat checks if input has the correct format and type
    IsFormat(input interface{}) bool
}

type FormatCheckerChain

FormatCheckerChain holds the formatters

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

func (*FormatCheckerChain) Add

func (c *FormatCheckerChain) Add(name string, f FormatChecker) *FormatCheckerChain

Add adds a FormatChecker to the FormatCheckerChain The name used will be the value used for the format key in your json schema

func (*FormatCheckerChain) Has

func (c *FormatCheckerChain) Has(name string) bool

Has checks to see if the FormatCheckerChain holds a FormatChecker with the given name

func (*FormatCheckerChain) IsFormat

func (c *FormatCheckerChain) IsFormat(name string, input interface{}) bool

IsFormat will check an input against a FormatChecker with the given name to see if it is the correct format

func (*FormatCheckerChain) Remove

func (c *FormatCheckerChain) Remove(name string) *FormatCheckerChain

Remove deletes a FormatChecker from the FormatCheckerChain (if it exists)

type HostnameFormatChecker

HostnameFormatChecker validates a hostname is in the correct format

type HostnameFormatChecker struct{}

func (HostnameFormatChecker) IsFormat

func (f HostnameFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted hostname

type IPV4FormatChecker

IPV4FormatChecker verifies IP addresses in the IPv4 format

type IPV4FormatChecker struct{}

func (IPV4FormatChecker) IsFormat

func (f IPV4FormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted IPv4-address

type IPV6FormatChecker

IPV6FormatChecker verifies IP addresses in the IPv6 format

type IPV6FormatChecker struct{}

func (IPV6FormatChecker) IsFormat

func (f IPV6FormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted IPv6=address

type InternalError

InternalError indicates an internal error ErrorDetails: error

type InternalError struct {
    ResultErrorFields
}

type InvalidPropertyNameError

InvalidPropertyNameError is produced if an invalid-named property was found ErrorDetails: property

type InvalidPropertyNameError struct {
    ResultErrorFields
}

type InvalidPropertyPatternError

InvalidPropertyPatternError is produced if an pattern was found ErrorDetails: property, pattern

type InvalidPropertyPatternError struct {
    ResultErrorFields
}

type InvalidTypeError

InvalidTypeError indicates that a field has the incorrect type ErrorDetails: expected, given

type InvalidTypeError struct {
    ResultErrorFields
}

type ItemsMustBeUniqueError

ItemsMustBeUniqueError is produced if an array requires unique items, but contains non-unique items ErrorDetails: type, i, j

type ItemsMustBeUniqueError struct {
    ResultErrorFields
}

type JSONLoader

JSONLoader defines the JSON loader interface

type JSONLoader interface {
    JsonSource() interface{}
    LoadJSON() (interface{}, error)
    JsonReference() (gojsonreference.JsonReference, error)
    LoaderFactory() JSONLoaderFactory
}

func NewBytesLoader

func NewBytesLoader(source []byte) JSONLoader

NewBytesLoader creates a new JSONLoader, taking a `[]byte` as source

func NewGoLoader

func NewGoLoader(source interface{}) JSONLoader

NewGoLoader creates a new JSONLoader from a given Go struct

func NewRawLoader

func NewRawLoader(source interface{}) JSONLoader

NewRawLoader creates a new JSON raw loader for the given source

func NewReaderLoader

func NewReaderLoader(source io.Reader) (JSONLoader, io.Reader)

NewReaderLoader creates a new JSON loader using the provided io.Reader

func NewReferenceLoader

func NewReferenceLoader(source string) JSONLoader

NewReferenceLoader returns a JSON reference loader using the given source and the local OS file system.

func NewReferenceLoaderFileSystem

func NewReferenceLoaderFileSystem(source string, fs http.FileSystem) JSONLoader

NewReferenceLoaderFileSystem returns a JSON reference loader using the given source and file system.

func NewStringLoader

func NewStringLoader(source string) JSONLoader

NewStringLoader creates a new JSONLoader, taking a string as source

func NewWriterLoader

func NewWriterLoader(source io.Writer) (JSONLoader, io.Writer)

NewWriterLoader creates a new JSON loader using the provided io.Writer

type JSONLoaderFactory

JSONLoaderFactory defines the JSON loader factory interface

type JSONLoaderFactory interface {
    // New creates a new JSON loader for the given source
    New(source string) JSONLoader
}

type JSONPointerFormatChecker

JSONPointerFormatChecker validates a JSON Pointer per RFC6901

type JSONPointerFormatChecker struct{}

func (JSONPointerFormatChecker) IsFormat

func (f JSONPointerFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted JSON Pointer per RFC6901

type JsonContext

JsonContext implements a persistent linked-list of strings

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

func NewJsonContext

func NewJsonContext(head string, tail *JsonContext) *JsonContext

NewJsonContext creates a new JsonContext

func (*JsonContext) String

func (c *JsonContext) String(del ...string) string

String displays the context in reverse. This plays well with the data structure's persistent nature with Cons and a json document's tree structure.

type MissingDependencyError

MissingDependencyError is produced in case of a "missing dependency" problem ErrorDetails: dependency

type MissingDependencyError struct {
    ResultErrorFields
}

type MultipleOfError

MultipleOfError is produced if a number is not a multiple of the defined multipleOf ErrorDetails: multiple

type MultipleOfError struct {
    ResultErrorFields
}

type NumberAllOfError

NumberAllOfError is produced in case of a failing "allOf" validation ErrorDetails: -

type NumberAllOfError struct {
    ResultErrorFields
}

type NumberAnyOfError

NumberAnyOfError is produced in case of a failing "anyOf" validation ErrorDetails: -

type NumberAnyOfError struct {
    ResultErrorFields
}

type NumberGTEError

NumberGTEError is produced if a number is lower than the allowed minimum ErrorDetails: min

type NumberGTEError struct {
    ResultErrorFields
}

type NumberGTError

NumberGTError is produced if a number is lower than, or equal to the specified minimum, and exclusiveMinimum is set ErrorDetails: min

type NumberGTError struct {
    ResultErrorFields
}

type NumberLTEError

NumberLTEError is produced if a number is higher than the allowed maximum ErrorDetails: max

type NumberLTEError struct {
    ResultErrorFields
}

type NumberLTError

NumberLTError is produced if a number is higher than, or equal to the specified maximum, and exclusiveMaximum is set ErrorDetails: max

type NumberLTError struct {
    ResultErrorFields
}

type NumberNotError

NumberNotError is produced if a "not" validation failed ErrorDetails: -

type NumberNotError struct {
    ResultErrorFields
}

type NumberOneOfError

NumberOneOfError is produced in case of a failing "oneOf" validation ErrorDetails: -

type NumberOneOfError struct {
    ResultErrorFields
}

type RegexFormatChecker

RegexFormatChecker validates a regex is in the correct format

type RegexFormatChecker struct{}

func (RegexFormatChecker) IsFormat

func (f RegexFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted regular expression

type RelativeJSONPointerFormatChecker

RelativeJSONPointerFormatChecker validates a relative JSON Pointer is in the correct format

type RelativeJSONPointerFormatChecker struct{}

func (RelativeJSONPointerFormatChecker) IsFormat

func (f RelativeJSONPointerFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted relative JSON Pointer

type RequiredError

RequiredError indicates that a required field is missing ErrorDetails: property string

type RequiredError struct {
    ResultErrorFields
}

type Result

Result holds the result of a validation

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

func Validate

func Validate(ls JSONLoader, ld JSONLoader) (*Result, error)

Validate loads and validates a JSON schema

func (*Result) AddError

func (v *Result) AddError(err ResultError, details ErrorDetails)

AddError appends a fully filled error to the error set SetDescription() will be called with the result of the parsed err.DescriptionFormat()

func (*Result) Errors

func (v *Result) Errors() []ResultError

Errors returns the errors that were found

func (*Result) Valid

func (v *Result) Valid() bool

Valid indicates if no errors were found

type ResultError

ResultError is the interface that library errors must implement

type ResultError interface {
    // Field returns the field name without the root context
    // i.e. firstName or person.firstName instead of (root).firstName or (root).person.firstName
    Field() string
    // SetType sets the error-type
    SetType(string)
    // Type returns the error-type
    Type() string
    // SetContext sets the JSON-context for the error
    SetContext(*JsonContext)
    // Context returns the JSON-context of the error
    Context() *JsonContext
    // SetDescription sets a description for the error
    SetDescription(string)
    // Description returns the description of the error
    Description() string
    // SetDescriptionFormat sets the format for the description in the default text/template format
    SetDescriptionFormat(string)
    // DescriptionFormat returns the format for the description in the default text/template format
    DescriptionFormat() string
    // SetValue sets the value related to the error
    SetValue(interface{})
    // Value returns the value related to the error
    Value() interface{}
    // SetDetails sets the details specific to the error
    SetDetails(ErrorDetails)
    // Details returns details about the error
    Details() ErrorDetails
    // String returns a string representation of the error
    String() string
}

type ResultErrorFields

ResultErrorFields holds the fields for each ResultError implementation. ResultErrorFields implements the ResultError interface, so custom errors can be defined by just embedding this type

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

func (*ResultErrorFields) Context

func (v *ResultErrorFields) Context() *JsonContext

Context returns the JSON-context of the error

func (*ResultErrorFields) Description

func (v *ResultErrorFields) Description() string

Description returns the description of the error

func (*ResultErrorFields) DescriptionFormat

func (v *ResultErrorFields) DescriptionFormat() string

DescriptionFormat returns the format for the description in the default text/template format

func (*ResultErrorFields) Details

func (v *ResultErrorFields) Details() ErrorDetails

Details returns details about the error

func (*ResultErrorFields) Field

func (v *ResultErrorFields) Field() string

Field returns the field name without the root context i.e. firstName or person.firstName instead of (root).firstName or (root).person.firstName

func (*ResultErrorFields) SetContext

func (v *ResultErrorFields) SetContext(context *JsonContext)

SetContext sets the JSON-context for the error

func (*ResultErrorFields) SetDescription

func (v *ResultErrorFields) SetDescription(description string)

SetDescription sets a description for the error

func (*ResultErrorFields) SetDescriptionFormat

func (v *ResultErrorFields) SetDescriptionFormat(descriptionFormat string)

SetDescriptionFormat sets the format for the description in the default text/template format

func (*ResultErrorFields) SetDetails

func (v *ResultErrorFields) SetDetails(details ErrorDetails)

SetDetails sets the details specific to the error

func (*ResultErrorFields) SetType

func (v *ResultErrorFields) SetType(errorType string)

SetType sets the error-type

func (*ResultErrorFields) SetValue

func (v *ResultErrorFields) SetValue(value interface{})

SetValue sets the value related to the error

func (ResultErrorFields) String

func (v ResultErrorFields) String() string

String returns a string representation of the error

func (*ResultErrorFields) Type

func (v *ResultErrorFields) Type() string

Type returns the error-type

func (*ResultErrorFields) Value

func (v *ResultErrorFields) Value() interface{}

Value returns the value related to the error

type Schema

Schema holds a schema

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

func NewSchema

func NewSchema(l JSONLoader) (*Schema, error)

NewSchema instances a schema using the given JSONLoader

func (*Schema) SetRootSchemaName

func (d *Schema) SetRootSchemaName(name string)

SetRootSchemaName sets the root-schema name

func (*Schema) Validate

func (v *Schema) Validate(l JSONLoader) (*Result, error)

Validate loads and validates a JSON document

type SchemaLoader

SchemaLoader is used to load schemas

type SchemaLoader struct {
    AutoDetect bool
    Validate   bool
    Draft      Draft
    // contains filtered or unexported fields
}

func NewSchemaLoader

func NewSchemaLoader() *SchemaLoader

NewSchemaLoader creates a new NewSchemaLoader

func (*SchemaLoader) AddSchema

func (sl *SchemaLoader) AddSchema(url string, loader JSONLoader) error

AddSchema adds a schema under the provided URL to the schema cache

func (*SchemaLoader) AddSchemas

func (sl *SchemaLoader) AddSchemas(loaders ...JSONLoader) error

AddSchemas adds an arbritrary amount of schemas to the schema cache. As this function does not require an explicit URL, every schema should contain an $id, so that it can be referenced by the main schema

func (*SchemaLoader) Compile

func (sl *SchemaLoader) Compile(rootSchema JSONLoader) (*Schema, error)

Compile loads and compiles a schema

type StringLengthGTEError

StringLengthGTEError is produced if a string is shorter than the minimum required length ErrorDetails: min

type StringLengthGTEError struct {
    ResultErrorFields
}

type StringLengthLTEError

StringLengthLTEError is produced if a string is longer than the maximum allowed length ErrorDetails: max

type StringLengthLTEError struct {
    ResultErrorFields
}

type TimeFormatChecker

TimeFormatChecker verifies time formats

Valid formats:

	Partial Time: HH:MM:SS
	Full Time: HH:MM:SSZ-07:00

Where
	HH = 2DIGIT hour ; 00-23
	MM = 2DIGIT ; 00-59
	SS = 2DIGIT ; 00-58, 00-60 based on leap second rules
	T = Literal
	Z = Literal
type TimeFormatChecker struct{}

func (TimeFormatChecker) IsFormat

func (f TimeFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input correctly formatted time (HH:MM:SS or HH:MM:SSZ-07:00)

type URIFormatChecker

URIFormatChecker validates a URI with a valid Scheme per RFC3986

type URIFormatChecker struct{}

func (URIFormatChecker) IsFormat

func (f URIFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is correctly formatted URI with a valid Scheme per RFC3986

type URIReferenceFormatChecker

URIReferenceFormatChecker validates a URI or relative-reference per RFC3986

type URIReferenceFormatChecker struct{}

func (URIReferenceFormatChecker) IsFormat

func (f URIReferenceFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted URI or relative-reference per RFC3986

type URITemplateFormatChecker

URITemplateFormatChecker validates a URI template per RFC6570

type URITemplateFormatChecker struct{}

func (URITemplateFormatChecker) IsFormat

func (f URITemplateFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted URI template per RFC6570

type UUIDFormatChecker

UUIDFormatChecker validates a UUID is in the correct format

type UUIDFormatChecker struct{}

func (UUIDFormatChecker) IsFormat

func (f UUIDFormatChecker) IsFormat(input interface{}) bool

IsFormat checks if input is a correctly formatted UUID