jsonschema

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentSchemaVersion = "https://json-schema.org/draft/2020-12/schema"
	KeyExtension         = ".schema.json"
)

Variables

View Source
var (
	SchemaTypeNull    = SchemaType{Key: "null", Name: "Null", Icon: "cog"}
	SchemaTypeBoolean = SchemaType{Key: "boolean", Name: "Boolean", Icon: "cog"}
	SchemaTypeInteger = SchemaType{Key: "integer", Name: "Integer", Icon: "cog"}
	SchemaTypeNumber  = SchemaType{Key: "number", Name: "Number", Icon: "cog"}
	SchemaTypeString  = SchemaType{Key: "string", Name: "String", Icon: "cog"}
	SchemaTypeDate    = SchemaType{Key: "date", Name: "Date", Icon: "cog"}
	SchemaTypeObject  = SchemaType{Key: "object", Name: "Object", Icon: "cog"}
	SchemaTypeEnum    = SchemaType{Key: "enum", Name: "Enum", Icon: "cog"}
	SchemaTypeArray   = SchemaType{Key: "array", Name: "Array", Icon: "cog"}
	SchemaTypeRef     = SchemaType{Key: "ref", Name: "Ref", Icon: "cog"}
	SchemaTypeUnion   = SchemaType{Key: "union", Name: "Union", Icon: "cog"}
	SchemaTypeEmpty   = SchemaType{Key: "empty", Name: "Empty", Icon: "cog"}
	SchemaTypeNot     = SchemaType{Key: "not", Name: "Not", Icon: "cog"}
	SchemaTypeUnknown = SchemaType{Key: "unknown", Name: "Unknown", Icon: "cog"}

	AllSchemaTypes = SchemaTypes{SchemaTypeNull, SchemaTypeBoolean, SchemaTypeInteger, SchemaTypeNumber, SchemaTypeString, SchemaTypeDate, SchemaTypeObject, SchemaTypeEnum, SchemaTypeArray, SchemaTypeRef, SchemaTypeUnion, SchemaTypeEmpty, SchemaTypeNot, SchemaTypeUnknown}
)

Functions

This section is empty.

Types

type Collection

type Collection struct {
	SchemaMap map[string]*Schema `json:"schemas,omitempty"`
	Roots     []string           `json:"roots,omitempty"`
}

func NewCollection

func NewCollection() *Collection

func (*Collection) AddSchema

func (c *Collection) AddSchema(root bool, sch ...*Schema) error

func (*Collection) AddSchemaExpanded added in v1.9.7

func (c *Collection) AddSchemaExpanded(sch ...*Schema) error

func (*Collection) GetSchema

func (c *Collection) GetSchema(id string) *Schema

func (*Collection) Keys added in v1.9.7

func (c *Collection) Keys() []string

func (*Collection) NewSchema

func (c *Collection) NewSchema(id string) *Schema

func (*Collection) Schemas

func (c *Collection) Schemas() Schemas

type Data added in v1.9.7

type Data struct {
	DataCore
	DataAnnotations
	DataValidations
	DataString
	DataNumber
	DataArray
	DataObject
	DataApplicators
	Examples []any                     `json:"examples,omitempty"` // array of example values that validate against the schema
	Unknown  map[string]jsontext.Value `json:",unknown"`           // extra fields, usually metadata
}

func (Data) Clone added in v1.9.7

func (d Data) Clone() Data

func (Data) IsEmpty added in v1.9.7

func (d Data) IsEmpty() bool

func (Data) IsEmptyExceptNot added in v1.9.7

func (d Data) IsEmptyExceptNot() bool

type DataAnnotations added in v1.9.7

type DataAnnotations struct {
	Title       string `json:"title,omitzero"`       // a short description of the schema
	Description string `json:"description,omitzero"` // a more detailed explanation
	Default     any    `json:"default,omitzero"`     // default value for the instance
	Deprecated  any    `json:"deprecated,omitzero"`  // indicates the instance is deprecated (default: false)
	ReadOnly    bool   `json:"readOnly,omitzero"`    // indicates the instance should not be modified (default: false)
	WriteOnly   bool   `json:"writeOnly,omitzero"`   // indicates the instance may be set but should not be returned (default: false)
}

func (DataAnnotations) Clone added in v1.9.7

func (d DataAnnotations) Clone() DataAnnotations

func (DataAnnotations) IsEmpty added in v1.9.7

func (d DataAnnotations) IsEmpty() bool

type DataApplicators added in v1.9.7

type DataApplicators struct {
	// conditional
	If   *Schema `json:"if,omitzero"`   // if this schema validates, `then` must also validate
	Then *Schema `json:"then,omitzero"` // schema applied if `if` validates
	Else *Schema `json:"else,omitzero"` // schema applied if `if` does not validate

	// boolean logic
	AllOf Schemas `json:"allOf,omitempty"` // instance must validate against all of these schemas
	AnyOf Schemas `json:"anyOf,omitempty"` // instance must validate against at least one of these schemas
	OneOf Schemas `json:"oneOf,omitempty"` // instance must validate against exactly one of these schemas
	Not   *Schema `json:"not,omitempty"`   // instance must not validate against this schema
}

func (DataApplicators) Clone added in v1.9.7

func (d DataApplicators) Clone() DataApplicators

func (DataApplicators) IsEmpty added in v1.9.7

func (d DataApplicators) IsEmpty() bool

func (DataApplicators) IsEmptyExceptNot added in v1.9.7

func (d DataApplicators) IsEmptyExceptNot() bool

type DataArray added in v1.9.7

type DataArray struct {
	Items            *Schema `json:"items,omitzero"`            // schema for array items (schema or boolean false). applied *after* prefixItems
	PrefixItems      Schemas `json:"prefixItems,omitzero"`      // array of schemas for tuple validation (items at specific indices)
	UnevaluatedItems *Schema `json:"unevaluatedItems,omitzero"` // validation for items not covered by `items` or `prefixItems` (schema or boolean)
	MaxItems         *uint64 `json:"maxItems,omitzero"`         // maximum number of items (non-negative integer)
	MinItems         *uint64 `json:"minItems,omitzero"`         // minimum number of items (non-negative integer, default 0)
	UniqueItems      *bool   `json:"uniqueItems,omitzero"`      // whether all items must be unique (default: false)
	Contains         *Schema `json:"contains,omitzero"`         // schema that at least one item must match
	MaxContains      *uint64 `json:"maxContains,omitzero"`      // maximum number of items matching `contains` (non-negative integer)
	MinContains      *uint64 `json:"minContains,omitzero"`      // minimum number of items matching `contains` (non-negative integer, default 1)
}

func (DataArray) Clone added in v1.9.7

func (d DataArray) Clone() DataArray

func (DataArray) IsEmpty added in v1.9.7

func (d DataArray) IsEmpty() bool

type DataCore added in v1.9.7

type DataCore struct {
	Schema        string                    `json:"$schema,omitzero"`        // uri identifying the dialect ("https://json-schema.org/draft/2020-12/schema")
	MetaID        string                    `json:"$id,omitzero"`            // base uri for the schema
	ExplicitID    string                    `json:"id,omitzero"`             // older [id] key
	Anchor        string                    `json:"$anchor,omitzero"`        // an identifier for this subschema
	Ref           string                    `json:"$ref,omitzero"`           // reference to another schema (uri or json pointer)
	DynamicRef    string                    `json:"$dynamicRef,omitzero"`    // reference that resolves dynamically (requires $dynamicAnchor)
	DynamicAnchor string                    `json:"$dynamicAnchor,omitzero"` // anchor for dynamic resolution
	Vocabulary    *util.OrderedMap[bool]    `json:"$vocabulary,omitzero"`    // declares vocabularies used (keys are uris, values must be true)
	Comment       string                    `json:"$comment,omitzero"`       // a comment string, ignored by validators
	Defs          *util.OrderedMap[*Schema] `json:"$defs,omitzero"`          // definitions for reusable subschemas
	ExplicitDefs  *util.OrderedMap[*Schema] `json:"definitions,omitzero"`    // older [definition] key
}

JSON fields that represent core vocabulary & metadata

func (DataCore) Clone added in v1.9.7

func (d DataCore) Clone() DataCore

func (DataCore) IsEmpty added in v1.9.7

func (d DataCore) IsEmpty() bool

type DataNumber added in v1.9.7

type DataNumber struct {
	MultipleOf       *float64 `json:"multipleOf,omitzero"`       // instance must be divisible by this number (strictly positive)
	Maximum          *float64 `json:"maximum,omitzero"`          // maximum inclusive value
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitzero"` // maximum exclusive value
	Minimum          *float64 `json:"minimum,omitzero"`          // minimum inclusive value
	ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitzero"` // minimum exclusive value
}

func (DataNumber) Clone added in v1.9.7

func (d DataNumber) Clone() DataNumber

func (DataNumber) IsEmpty added in v1.9.7

func (d DataNumber) IsEmpty() bool

type DataObject added in v1.9.7

type DataObject struct {
	Properties            *util.OrderedMap[*Schema]  `json:"properties,omitzero"`            // schemas for named properties
	PatternProperties     *util.OrderedMap[*Schema]  `json:"patternProperties,omitzero"`     // schemas for properties matching regex patterns
	AdditionalProperties  *Schema                    `json:"additionalProperties,omitzero"`  // schema or boolean
	AllowTrailingCommas   bool                       `json:"allowTrailingCommas,omitzero"`   // indicates that trailing commas are allowed
	UnevaluatedProperties any                        `json:"unevaluatedProperties,omitzero"` // validation for properties not covered by `properties`
	Required              []string                   `json:"required,omitempty"`             // array of required property names
	PropertyNames         *Schema                    `json:"propertyNames,omitzero"`         // schema for property names
	MaxProperties         *uint64                    `json:"maxProperties,omitzero"`         // maximum number of properties (non-negative integer)
	MinProperties         *uint64                    `json:"minProperties,omitzero"`         // minimum number of properties (non-negative integer, default 0)
	DependentRequired     *util.OrderedMap[[]string] `json:"dependentRequired,omitzero"`     // properties required based on the presence of other properties
	DependentSchemas      *util.OrderedMap[*Schema]  `json:"dependentSchemas,omitzero"`      // schemas applied based on the presence of other properties
}

func (DataObject) Clone added in v1.9.7

func (d DataObject) Clone() DataObject

func (DataObject) IsEmpty added in v1.9.7

func (d DataObject) IsEmpty() bool

type DataString added in v1.9.7

type DataString struct {
	MaxLength        *uint64 `json:"maxLength,omitzero"`        // maximum length (non-negative integer)
	MinLength        *uint64 `json:"minLength,omitzero"`        // minimum length (non-negative integer, default 0)
	Pattern          string  `json:"pattern,omitzero"`          // ecma 262 regular expression
	Format           string  `json:"format,omitzero"`           // predefined format (e.g., "date-time", "email", "ipv4")
	ContentEncoding  string  `json:"contentEncoding,omitzero"`  // encoding of the string content (e.g., "base64")
	ContentMediaType string  `json:"contentMediaType,omitzero"` // media type of the string content (e.g., "application/json")
	ContentSchema    *Schema `json:"contentSchema,omitzero"`    // schema for the decoded content if contentEncoding/contentMediaType are present
}

func (DataString) Clone added in v1.9.7

func (d DataString) Clone() DataString

func (DataString) IsEmpty added in v1.9.7

func (d DataString) IsEmpty() bool

type DataValidations added in v1.9.7

type DataValidations struct {
	// generic
	Type  any   `json:"type,omitzero"`  // expected data type(s) (string or array of "string", "number", "integer", "object", "array", "boolean", "null")
	Enum  []any `json:"enum,omitempty"` // array of allowed values
	Const any   `json:"const,omitzero"` // exact required value
}

func (DataValidations) Clone added in v1.9.7

func (d DataValidations) Clone() DataValidations

func (DataValidations) IsEmpty added in v1.9.7

func (d DataValidations) IsEmpty() bool

type Schema

type Schema struct {
	Key string `json:"-"`
	Data
	// contains filtered or unexported fields
}

func NewFalseSchema added in v1.9.7

func NewFalseSchema() *Schema

func NewRefSchema added in v1.9.7

func NewRefSchema(s string) *Schema

func NewSchema added in v1.9.7

func NewSchema(data ...any) *Schema

func NewTrueSchema added in v1.9.7

func NewTrueSchema() *Schema

func (*Schema) AddMetadata added in v1.7.7

func (s *Schema) AddMetadata(k string, v any)

func (*Schema) Clone added in v1.9.7

func (s *Schema) Clone() *Schema

func (*Schema) Definitions added in v1.9.7

func (s *Schema) Definitions() *util.OrderedMap[*Schema]

func (*Schema) DetectSchemaType added in v1.9.7

func (s *Schema) DetectSchemaType() SchemaType

func (*Schema) GetMetadata added in v1.9.7

func (s *Schema) GetMetadata() util.ValueMap

func (*Schema) HasProperties added in v1.9.7

func (s *Schema) HasProperties() bool

func (*Schema) Hash added in v1.9.7

func (s *Schema) Hash() uuid.UUID

func (*Schema) ID

func (s *Schema) ID() string

func (*Schema) IsDeprecated added in v1.9.7

func (s *Schema) IsDeprecated() (bool, string)

func (*Schema) IsEmpty added in v1.9.7

func (s *Schema) IsEmpty() bool

func (*Schema) IsEmptyExceptNot added in v1.9.7

func (s *Schema) IsEmptyExceptNot() bool

func (*Schema) MarshalJSON added in v1.9.7

func (s *Schema) MarshalJSON() ([]byte, error)

func (*Schema) OriginalBytes added in v1.9.7

func (s *Schema) OriginalBytes() []byte

func (*Schema) String added in v1.7.5

func (s *Schema) String() string

func (*Schema) Summary added in v1.9.7

func (s *Schema) Summary() string

func (*Schema) ToFieldDescs added in v1.7.7

func (s *Schema) ToFieldDescs() (util.FieldDescs, error)

func (*Schema) UnmarshalJSON added in v1.9.7

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

type SchemaType added in v1.9.7

type SchemaType struct {
	Key         string
	Name        string
	Description string
	Icon        string
}

func (SchemaType) MarshalJSON added in v1.9.7

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

func (SchemaType) MarshalXML added in v1.9.7

func (s SchemaType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error

func (SchemaType) Matches added in v1.9.7

func (s SchemaType) Matches(xx SchemaType) bool

func (SchemaType) NameSafe added in v1.9.7

func (s SchemaType) NameSafe() string

func (*SchemaType) Scan added in v1.9.7

func (s *SchemaType) Scan(value any) error

func (SchemaType) String added in v1.9.7

func (s SchemaType) String() string

func (*SchemaType) UnmarshalJSON added in v1.9.7

func (s *SchemaType) UnmarshalJSON(data []byte) error

func (*SchemaType) UnmarshalXML added in v1.9.7

func (s *SchemaType) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

func (SchemaType) Value added in v1.9.7

func (s SchemaType) Value() (driver.Value, error)

type SchemaTypes added in v1.9.7

type SchemaTypes []SchemaType

func SchemaTypeParse added in v1.9.7

func SchemaTypeParse(logger util.Logger, keys ...string) SchemaTypes

func (SchemaTypes) Get added in v1.9.7

func (s SchemaTypes) Get(key string, logger util.Logger) SchemaType

func (SchemaTypes) GetByName added in v1.9.7

func (s SchemaTypes) GetByName(name string, logger util.Logger) SchemaType

func (SchemaTypes) Help added in v1.9.7

func (s SchemaTypes) Help() string

func (SchemaTypes) Keys added in v1.9.7

func (s SchemaTypes) Keys() []string

func (SchemaTypes) NamesSafe added in v1.9.7

func (s SchemaTypes) NamesSafe() []string

func (SchemaTypes) Random added in v1.9.7

func (s SchemaTypes) Random() SchemaType

func (SchemaTypes) Strings added in v1.9.7

func (s SchemaTypes) Strings() []string

type Schemas

type Schemas []*Schema

func (Schemas) Clone added in v1.9.7

func (s Schemas) Clone() Schemas

func (Schemas) IDs

func (s Schemas) IDs() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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