Help us shape the future of Go! Take the 2026 Go Developer Survey

schema

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, rootType reflect.Type) ([]byte, error)

Types

type Builder

type Builder interface {
	Context() context.Context
	Describe(valueType reflect.Type) (*Node, error)
	FlattenStruct(node *Node, structType reflect.Type) error
	Define(name string, build func() (*Node, error)) (*Node, error)
}

type Describer

type Describer interface {
	DescribeSchema(builder Builder) (*Node, error)
}

type Node

type Node struct {
	SchemaURI             string                           `json:"$schema,omitempty"`
	ID                    string                           `json:"$id,omitempty"`
	Ref                   string                           `json:"$ref,omitempty"`
	Type                  any                              `json:"type,omitempty"`
	Const                 any                              `json:"const,omitempty"`
	Enum                  []any                            `json:"enum,omitempty"`
	Pattern               string                           `json:"pattern,omitempty"`
	Minimum               *int64                           `json:"minimum,omitempty"`
	Maximum               *uint64                          `json:"maximum,omitempty"`
	Items                 *Node                            `json:"items,omitempty"`
	Properties            *badjson.TypedMap[string, *Node] `json:"properties,omitempty"`
	Required              []string                         `json:"required,omitempty"`
	PropertyNames         *Node                            `json:"propertyNames,omitempty"`
	AdditionalProperties  any                              `json:"additionalProperties,omitempty"`
	UnevaluatedProperties any                              `json:"unevaluatedProperties,omitempty"`
	AllOf                 []*Node                          `json:"allOf,omitempty"`
	AnyOf                 []*Node                          `json:"anyOf,omitempty"`
	OneOf                 []*Node                          `json:"oneOf,omitempty"`
	Deprecated            bool                             `json:"deprecated,omitempty"`
	Examples              []any                            `json:"examples,omitempty"`
	TagReference          string                           `json:"x-tag-reference,omitempty"`
	Defs                  *badjson.TypedMap[string, *Node] `json:"$defs,omitempty"`
}

func AnyOf

func AnyOf(nodes ...*Node) *Node

func BooleanNode

func BooleanNode() *Node

func DiscriminatedUnion

func DiscriminatedUnion(builder Builder, discriminatorKey string, discriminatorRequired bool, variants []UnionVariant, buildBase func(variant *Node) error) (*Node, error)

func DurationNode

func DurationNode() *Node

func IntegerNode

func IntegerNode() *Node

func ListableOf

func ListableOf(element *Node) *Node

func LooseObject

func LooseObject() *Node

func OneOf

func OneOf(nodes ...*Node) *Node

func RefNode

func RefNode(name string) *Node

func StrictObject

func StrictObject() *Node

func StringConst

func StringConst(value string) *Node

func StringEnum

func StringEnum(values ...string) *Node

func StringNode

func StringNode() *Node

func TagReferenceNode

func TagReferenceNode(kind string) *Node

func UnsignedNode

func UnsignedNode(bits int) *Node

type UnionVariant

type UnionVariant struct {
	Value        any
	StructType   reflect.Type
	TypeOptional bool
}

Jump to

Keyboard shortcuts

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