jsonschema

package module
v0.0.0-...-24fde6b Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Apache-2.0 Imports: 15 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatError

func FormatError(e *jsonschema.ValidationError) (string, string)

func FormatValidationErrorForCLI

func FormatValidationErrorForCLI(w io.Writer, conf []byte, err error)

func JSONPointerToDotNotation

func JSONPointerToDotNotation(pointer string) (string, error)

JSONPointerToDotNotation converts JSON Pointer "#/foo/bar" to dot-notation "foo.bar".

Types

type Error

type Error struct {
	// Type is the error type.
	Type ErrorType

	// DocumentPointer is the JSON Pointer in the document.
	DocumentPointer string

	// SchemaPointer is the JSON Pointer in the schema.
	SchemaPointer string

	// DocumentFieldName is a pointer to the document in dot-notation: fo.bar.baz
	DocumentFieldName string
}

Error represents a schema error.

func NewFromSanthoshError

func NewFromSanthoshError(validationError jsonschema.ValidationError) *Error

NewFromSanthoshError converts github.com/santhosh-tekuri/jsonschema.ValidationError to Error.

type ErrorType

type ErrorType int

ErrorType is the schema error type.

const (
	// ErrorTypeMissing represents a validation that failed because a value is missing.
	ErrorTypeMissing ErrorType = iota + 1
)

type Path

type Path struct {
	// Name is the JSON path name.
	Name string

	// Default is the default value of that path.
	Default interface{}

	// Type is a prototype (e.g. float64(0)) of the path type.
	Type interface{}

	TypeHint

	// Format is the format of the path if defined
	Format string

	// Pattern is the pattern of the path if defined
	Pattern *regexp.Regexp

	// Enum are the allowed enum values
	Enum []interface{}

	// first element in slice is constant value. note: slice is used to capture nil constant.
	Constant []interface{}

	// ReadOnly is whether the value is readonly
	ReadOnly bool

	// -1 if not specified
	MinLength int
	MaxLength int

	Minimum *big.Float
	Maximum *big.Float

	MultipleOf *big.Float

	CustomProperties map[string]interface{}
}

Path represents a JSON Schema Path.

func ListPaths

func ListPaths(ref string, compiler *jsonschema.Compiler) ([]Path, error)

ListPaths lists all paths of a JSON Schema. Will return an error if circular references are found.

func ListPathsBytes

func ListPathsBytes(raw json.RawMessage, maxRecursion int16) ([]Path, error)

ListPathsBytes works like ListPathsWithRecursion but prepares the JSON Schema itself.

func ListPathsWithRecursion

func ListPathsWithRecursion(ref string, compiler *jsonschema.Compiler, maxRecursion uint8) ([]Path, error)

ListPathsWithRecursion will follow circular references until maxRecursion is reached, without returning an error.

type PathEnhancer

type PathEnhancer interface {
	EnhancePath(Path) map[string]interface{}
}

type TypeHint

type TypeHint int
const (
	String TypeHint = iota + 1
	Float
	Int
	Bool
	JSON
	Nil

	BoolSlice
	StringSlice
	IntSlice
	FloatSlice
)

Jump to

Keyboard shortcuts

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