jsonschema

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Description string `json:"description,omitempty"`
	MinItems    int    `json:"minItems,omitempty"`
	MaxItems    int    `json:"maxItems,omitempty"`
	Items       Schema `json:"items"`
}

Array is a JSON schema array.

func (Array) MarshalJSON

func (s Array) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Array) Validate

func (s Array) Validate(v json.RawMessage) error

Validate validates the array against the JSON schema.

type Boolean

type Boolean struct {
	Description string `json:"description,omitempty"`
}

Boolean is a JSON schema boolean.

func (Boolean) MarshalJSON

func (s Boolean) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Boolean) Validate

func (s Boolean) Validate(v json.RawMessage) error

Validate validates the boolean against the JSON schema.

type Const

type Const struct {
	Description string `json:"description,omitempty"`
	Value       any    `json:"const"`
}

Const is a JSON schema const.

func (Const) MarshalJSON

func (s Const) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Const) Validate

func (s Const) Validate(v json.RawMessage) error

Validate validates the const against the JSON schema.

type Integer

type Integer struct {
	Description      string `json:"description,omitempty"`
	Minimum          *int64 `json:"minimum,omitempty,omitzero"`
	Maximum          *int64 `json:"maximum,omitempty,omitzero"`
	ExclusiveMinimum *int64 `json:"exclusiveMinimum,omitempty,omitzero"`
	ExclusiveMaximum *int64 `json:"exclusiveMaximum,omitempty,omitzero"`
}

Integer is a JSON schema for an integer.

func (Integer) MarshalJSON

func (s Integer) MarshalJSON() ([]byte, error)

func (Integer) Validate

func (s Integer) Validate(v json.RawMessage) error

type Map

type Map struct {
	Description          string `json:"description,omitempty"`
	AdditionalProperties Schema `json:"additionalProperties"`
}

Map is a JSON schema object that maps keys to values.

The additionalProperties field is a JSON schema that will be used to validate the values of the map.

func (Map) MarshalJSON

func (s Map) MarshalJSON() ([]byte, error)

func (Map) Validate

func (s Map) Validate(v json.RawMessage) error

type Null

type Null struct {
	Description string `json:"description,omitempty"`
}

Null is a JSON schema null.

func (Null) MarshalJSON

func (s Null) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Null) Validate

func (s Null) Validate(v json.RawMessage) error

Validate validates the null against the JSON schema.

type Number

type Number struct {
	Description      string   `json:"description,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty,omitzero"`
	Maximum          *float64 `json:"maximum,omitempty,omitzero"`
	ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty,omitzero"`
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty,omitzero"`
}

Number is a JSON schema for a number.

func (Number) MarshalJSON

func (s Number) MarshalJSON() ([]byte, error)

func (Number) Validate

func (s Number) Validate(v json.RawMessage) error

type Object

type Object struct {
	Description string            `json:"description,omitempty"`
	Properties  map[string]Schema `json:"properties"`
	Required    []string          `json:"required,omitempty,omitzero"`
}

Object is a JSON schema object.

func FromStruct

func FromStruct(v any) (Object, error)

FromStruct generates a JSON schema Object from a struct type

func FromStructType added in v0.0.6

func FromStructType[T any]() (Object, error)

func (Object) MarshalJSON

func (o Object) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Object) Validate

func (o Object) Validate(v json.RawMessage) error

Validate validates the object against the JSON schema.

type Schema

type Schema interface {
	SchemaValidator
	json.Marshaler
}

type SchemaTag

type SchemaTag struct {
	Description string
	Required    bool
}

SchemaTag represents the struct tag for JSON schema configuration

func ParseSchemaTag

func ParseSchemaTag(tag reflect.StructTag) SchemaTag

ParseSchemaTag parses the jsonschema tag and returns SchemaTag

type SchemaValidator

type SchemaValidator interface {
	Validate(v json.RawMessage) error
	// contains filtered or unexported methods
}

type String

type String struct {
	Description string `json:"description,omitempty"`
	MinLength   int    `json:"minLength,omitempty"`
	MaxLength   int    `json:"maxLength,omitempty"`
}

String is a JSON schema string.

func (String) MarshalJSON

func (s String) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (String) Validate

func (s String) Validate(v json.RawMessage) error

Validate validates the string against the JSON schema.

Jump to

Keyboard shortcuts

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