schema

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BuiltinSchemaName names the builtin schema for Load()/Set().
	BuiltinSchemaName = "builtin"
	// NoneSchemaName names the NOP-schema for Load()/Set().
	NoneSchemaName = "none"
)

Variables

This section is empty.

Functions

func ReadAndValidate

func ReadAndValidate(r io.Reader) ([]byte, error)

ReadAndValidate all data from the given reader, using the active schema for validation.

func Set

func Set(s *Schema)

Set sets the default validating JSON schema.

func Validate

func Validate(r io.Reader) error

Validate validates the data read from an io.Reader against the active schema.

func ValidateData

func ValidateData(data []byte) error

ValidateData validates the given JSON document against the active schema.

func ValidateFile

func ValidateFile(path string) error

ValidateFile validates the given JSON file against the active schema.

func ValidateType

func ValidateType(obj interface{}) error

ValidateType validates a go object against the schema.

Types

type Error

type Error struct {
	Result *schema.Result
}

Error wraps a JSON validation result.

func (*Error) Error

func (e *Error) Error() string

Error returns the given Result's errors as a single error string.

type Schema

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

Schema is a JSON validation schema.

func BuiltinSchema

func BuiltinSchema() *Schema

BuiltinSchema returns the builtin schema if we have a valid one. Otherwise it falls back to NopSchema().

func Get

func Get() *Schema

Get returns the active validating JSON schema.

func Load

func Load(source string) (*Schema, error)

Load the given JSON Schema.

func NopSchema

func NopSchema() *Schema

NopSchema returns an validating JSON Schema that does no real validation.

func (*Schema) ReadAndValidate

func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error)

ReadAndValidate all data from the given reader, using the schema for validation.

func (*Schema) Validate

func (s *Schema) Validate(r io.Reader) error

Validate validates the data read from an io.Reader against the schema.

func (*Schema) ValidateData

func (s *Schema) ValidateData(data []byte) error

ValidateData validates the given JSON data against the schema.

func (*Schema) ValidateFile

func (s *Schema) ValidateFile(path string) error

ValidateFile validates the given JSON file against the schema.

func (*Schema) ValidateType

func (s *Schema) ValidateType(obj interface{}) error

ValidateType validates a go object against the schema.

Jump to

Keyboard shortcuts

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