jsonschemaext

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enum

type Enum = jsonschema.Enum

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 Format

type Format = jsonschema.Format

type Path

type Path struct {
	// Title of the path.
	Title string

	// Description of the path.
	Description string

	// Examples of the path.
	Examples []interface{}

	// Name is the JSON path name.
	Name string

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

	TypeHint

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

	// Pattern is the pattern of the path if defined
	Pattern Regexp

	// Enum are the allowed enum values
	Enum *Enum

	// 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

	// Required if set indicates this field is required.
	Required bool

	Minimum *big.Rat
	Maximum *big.Rat

	MultipleOf *big.Rat

	CustomProperties map[string]interface{}
}

Path represents a JSON Schema Path.

func ListPaths

func ListPaths(ctx context.Context, 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(ctx context.Context, raw json.RawMessage, maxRecursion int16) ([]Path, error)

ListPathsBytes works like ListPathsWithRecursion but prepares the JSON Schema itself.

func ListPathsWithArraysIncluded

func ListPathsWithArraysIncluded(ctx context.Context, ref string, compiler *jsonschema.Compiler) ([]Path, error)

ListPathsWithArraysIncluded lists all paths of a JSON Schema. Will return an error if circular references are found. Includes arrays with `#`.

func ListPathsWithInitializedSchema

func ListPathsWithInitializedSchema(schema *jsonschema.Schema) ([]Path, error)

ListPathsWithInitializedSchema loads the paths from the schema without compiling it.

func ListPathsWithInitializedSchemaAndArraysIncluded

func ListPathsWithInitializedSchemaAndArraysIncluded(schema *jsonschema.Schema) ([]Path, error)

ListPathsWithInitializedSchemaAndArraysIncluded loads the paths from the schema without compiling it.

func ListPathsWithRecursion

func ListPathsWithRecursion(ctx context.Context, 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 Regexp

type Regexp = jsonschema.Regexp

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