validator

package
v0.0.0-...-e2f5efa Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SchemaDefinitions is the location of the repository
	// of schema definitions on the filepath
	SchemaDefinitions = "./artifacts/json-schema"

	// DefinitionFile is the schema definition file, or the root
	// file from which a definition beings
	DefinitionFile = "schema.json"

	// CurrentVersion represents the default
	CurrentVersion = "1.0.0"
)

Variables

View Source
var (
	// ErrSchemaVersionUndefined is returned if a validator is requested
	// and no corresponding schema definition that matches the version is present
	// in the SchemaDefinitions artifact repository
	ErrSchemaVersionUndefined = errors.New("schema version undefined")

	// ErrValidationFailed is returned by Validate if the supplied document
	// does not pass validation
	ErrValidationFailed = errors.New("validation failed")
)

Functions

This section is empty.

Types

type Validator

type Validator struct {
	Version        string
	Valid          bool
	DefinitionFile string
	// contains filtered or unexported fields
}

Validator is a validator for JSON documents

func NewValidator

func NewValidator() (*Validator, error)

NewValidator will return a new validator configured to use the CurrentVersion of the schema definition

func NewValidatorByVersion

func NewValidatorByVersion(version string) (*Validator, error)

NewValidatorByVersion will return a new validator with the definition for the supplied version number loaded, as defined in the SchemaDefinitions repository and ready for a document to be validated against

func (*Validator) Errors

func (v *Validator) Errors() []schema.ResultError

Errors returns any error objects from a failed validation

func (*Validator) Validate

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

Validate will perform validation of the supplied document against the validators supplied defintion, returning the error ErrValidationFailed in the case of a failed validation

Jump to

Keyboard shortcuts

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