jsonschema

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package jsonschema has functionality related to json schema support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStringToType added in v0.17.1

func ConvertStringToType(s string, t Type) (any, error)

ConvertStringToType converts a string value to jsonschema type.

func EnsureType added in v0.17.1

func EnsureType(t Type, v any) (any, error)

EnsureType checks if the given value v respects json schema type t. Returns a type default value if v is nil. Error is returned on type mismatch or type not implemented.

func Validate added in v0.17.1

func Validate(s Schema, input map[string]any) error

Validate checks if input complies with given schema.

Types

type ErrSchemaValidation added in v0.17.1

type ErrSchemaValidation struct {
	// Path is a key path to the property.
	Path []string
	// Msg is an error message.
	Msg string
	// contains filtered or unexported fields
}

ErrSchemaValidation is a validation error.

func NewErrSchemaValidation added in v0.17.1

func NewErrSchemaValidation(path []string, msg string) ErrSchemaValidation

NewErrSchemaValidation creates a new error.

func (ErrSchemaValidation) Error added in v0.17.1

func (err ErrSchemaValidation) Error() string

Error implements error interface.

type ErrSchemaValidationArray added in v0.17.1

type ErrSchemaValidationArray []ErrSchemaValidation

ErrSchemaValidationArray is an array of validation errors.

func (ErrSchemaValidationArray) Error added in v0.17.1

func (err ErrSchemaValidationArray) Error() string

Error implements error interface.

type ErrTypeMismatch added in v0.17.2

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

ErrTypeMismatch is an error when expected jsonschema type and given values mismatch.

func NewErrTypeMismatch added in v0.17.2

func NewErrTypeMismatch(act, exp any) ErrTypeMismatch

NewErrTypeMismatch constructs new ErrTypeMismatch.

func (ErrTypeMismatch) Error added in v0.17.2

func (err ErrTypeMismatch) Error() string

Error implements error interface.

type Schema added in v0.1.2

type Schema struct {
	ID          string   `json:"$id,omitempty"`
	Schema      string   `json:"$schema,omitempty"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Type        Type     `json:"type"`
	Required    []string `json:"required"`
	// @todo make a recursive type of properties.
	Properties map[string]any `json:"properties"`
}

Schema is a json schema definition. It doesn't implement all and may not comply fully. See https://json-schema.org/specification.html

type Type

type Type string

Type is a json schema type.

const (
	String      Type = "string"
	Number      Type = "number"
	Integer     Type = "integer"
	Boolean     Type = "boolean"
	Null        Type = "null"
	Object      Type = "object"
	Array       Type = "array"
	Unsupported Type = "UNSUPPORTED"
)

Json schema types.

func TypeFromString added in v0.1.2

func TypeFromString(t string) Type

TypeFromString creates a Type with enum validation.

func (*Type) UnmarshalYAML

func (t *Type) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse Json Schema type.

Jump to

Keyboard shortcuts

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