schema

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

nolint

nolint

nolint:gochecknoglobals

nolint

Index

Constants

This section is empty.

Variables

View Source
var (
	TrueSchema  = &Schema{boolean: &[]bool{true}[0]}
	FalseSchema = &Schema{boolean: &[]bool{false}[0]}
)
View Source
var CustomGenerators = &customSchema{
	mapSchema: make(map[string]CustomGenerator),
}

nolint:gochecknoglobals

View Source
var Version = "v1"

Functions

func ExtractGoComments

func ExtractGoComments(base string, rootPath string, commentMap map[string]string) error

ExtractGoComments reads all Go files in a given path and its subdirectories, extracting doc comments for exported types and their fields. `base` is the import path prefix to match the final FQNs.

func GetFieldName

func GetFieldName(fieldType reflect.StructField) (string, bool)

func GetNameAndRequiredFlag

func GetNameAndRequiredFlag(field reflect.StructField) (string, bool)

func NewProperties

func NewProperties() *orderedmap.OrderedMap[string, *Schema]

func SetProperties

func SetProperties(field reflect.StructField, s *Schema)

Types

type CustomGenerator

type CustomGenerator func(field reflect.StructField, s *Schema)

type Definitions

type Definitions map[string]*Schema

type Generator

type Generator struct {
	Reflector *Reflector
}

func NewGenerator

func NewGenerator() *Generator

func (*Generator) Generate

func (g *Generator) Generate(obj any) *Schema

type Id

type Id string
const EmptyId Id = ""

func (Id) Add

func (id Id) Add(path string) Id

func (Id) Anchor

func (id Id) Anchor(name string) Id

func (Id) Base

func (id Id) Base() Id

func (Id) Def

func (id Id) Def(name string) Id

func (Id) String

func (id Id) String() string

func (Id) Validate

func (id Id) Validate() error

nolint:err113

type Reflector

type Reflector struct {
	BaseSchemaId              Id
	Anonymous                 bool
	AssignAnchor              bool
	AllowAdditionalProperties bool
	RequiredFromSchemaTags    bool
	DoNotReference            bool
	ExpandedStruct            bool
	FieldNameReflector        func(f reflect.StructField) (string, bool)
	FieldReflector            func(f reflect.StructField, s *Schema)
	FieldNameTag              string
	IgnoredTypes              []any
	Lookup                    func(reflect.Type) Id
	Mapper                    func(reflect.Type) *Schema
	Namer                     func(reflect.Type) string
	KeyNamer                  func(string) string
	AdditionalFields          func(reflect.Type) []reflect.StructField
	CommentMap                map[string]string
}

func (*Reflector) AddGoComments

func (r *Reflector) AddGoComments(base, path string) error

func (*Reflector) Reflect

func (r *Reflector) Reflect(v any) *Schema

func (*Reflector) ReflectFromType

func (r *Reflector) ReflectFromType(t reflect.Type) *Schema

func (*Reflector) SetBaseSchemaId

func (r *Reflector) SetBaseSchemaId(id string)

type Schema

type Schema struct {
	Version              string                                  `json:"$schema,omitempty"`
	Id                   Id                                      `json:"$id,omitempty"`
	Anchor               string                                  `json:"$anchor,omitempty"`
	Ref                  string                                  `json:"$ref,omitempty"`
	DynamicRef           string                                  `json:"$dynamicRef,omitempty"`
	Definitions          Definitions                             `json:"$defs,omitempty"`
	Comments             string                                  `json:"$comment,omitempty"`
	AllOf                []*Schema                               `json:"allOf,omitempty"`
	AnyOf                []*Schema                               `json:"anyOf,omitempty"`
	OneOf                []*Schema                               `json:"oneOf,omitempty"`
	Not                  *Schema                                 `json:"not,omitempty"`
	If                   *Schema                                 `json:"if,omitempty"`
	Then                 *Schema                                 `json:"then,omitempty"`
	Else                 *Schema                                 `json:"else,omitempty"`
	DependentSchemas     map[string]*Schema                      `json:"dependentSchemas,omitempty"`
	PrefixItems          []*Schema                               `json:"prefixItems,omitempty"`
	Items                *Schema                                 `json:"items,omitempty"`
	Contains             *Schema                                 `json:"contains,omitempty"`
	Properties           *orderedmap.OrderedMap[string, *Schema] `json:"properties,omitempty"`
	PatternProperties    map[string]*Schema                      `json:"patternProperties,omitempty"`
	AdditionalProperties *Schema                                 `json:"additionalProperties,omitempty"`
	PropertyNames        *Schema                                 `json:"propertyNames,omitempty"`
	Type                 string                                  `json:"type,omitempty"`
	Enum                 []any                                   `json:"enum,omitempty"`
	Const                any                                     `json:"const,omitempty"`
	MultipleOf           *int64                                  `json:"multipleOf,omitempty"`
	Maximum              *int64                                  `json:"maximum,omitempty"`
	ExclusiveMaximum     *int64                                  `json:"exclusiveMaximum,omitempty"`
	Minimum              *int64                                  `json:"minimum,omitempty"`
	ExclusiveMinimum     *int64                                  `json:"exclusiveMinimum,omitempty"`
	MaxLength            *uint64                                 `json:"maxLength,omitempty"`
	MinLength            *uint64                                 `json:"minLength,omitempty"`
	Pattern              string                                  `json:"pattern,omitempty"`
	MaxItems             *uint64                                 `json:"maxItems,omitempty"`
	MinItems             *uint64                                 `json:"minItems,omitempty"`
	UniqueItems          bool                                    `json:"uniqueItems,omitempty"`
	MaxContains          *uint64                                 `json:"maxContains,omitempty"`
	MinContains          *uint64                                 `json:"minContains,omitempty"`
	MaxProperties        *uint64                                 `json:"maxProperties,omitempty"`
	MinProperties        *uint64                                 `json:"minProperties,omitempty"`
	Secrets              []string                                `json:"secrets,omitempty"`
	Required             []string                                `json:"required,omitempty"`
	DependentRequired    map[string][]string                     `json:"dependentRequired,omitempty"`
	Format               string                                  `json:"format,omitempty"`
	ContentEncoding      string                                  `json:"contentEncoding,omitempty"`
	ContentMediaType     string                                  `json:"contentMediaType,omitempty"`
	ContentSchema        *Schema                                 `json:"contentSchema,omitempty"`
	Title                string                                  `json:"title,omitempty"`
	Description          string                                  `json:"description,omitempty"`
	Default              any                                     `json:"default,omitempty"`
	Deprecated           bool                                    `json:"deprecated,omitempty"`
	ReadOnly             bool                                    `json:"readOnly,omitempty"`
	WriteOnly            bool                                    `json:"writeOnly,omitempty"`
	Examples             []any                                   `json:"examples,omitempty"`

	Extras map[string]any `json:"-"`
	// contains filtered or unexported fields
}

func Reflect

func Reflect(v any) *Schema

func ReflectFromType

func ReflectFromType(t reflect.Type) *Schema

func (*Schema) MarshalJson added in v1.7.0

func (t *Schema) MarshalJson() ([]byte, error)

func (*Schema) UnmarshalJson added in v1.7.0

func (t *Schema) UnmarshalJson(data []byte) error

Jump to

Keyboard shortcuts

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