schema

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLookupCommentFunc

func DefaultLookupCommentFunc(commentMap map[string]string) func(t reflect.Type, f string) string

Types

type Generator

type Generator struct {
	Reflector         *jsonschema.Reflector
	LookupCommentFunc LookupCommentFunc

	Tests bool // Include test files.
	// contains filtered or unexported fields
}

Generator generates a JSON schema from a Go type using reflection. It looks up comments from the source code to provide documentation, one or more package paths are provided. Uses github.com/invopop/jsonschema.

func NewGenerator

func NewGenerator(reflectTarget any, packagePaths ...string) *Generator

NewGenerator creates a new Generator. The reflectTarget is the Go type to generate the schema for, and packagePaths are the fully qualified import paths of the packages to lookup comments from.

func (*Generator) Generate

func (g *Generator) Generate() ([]byte, error)

type LookupCommentFunc

type LookupCommentFunc func(commentMap map[string]string) func(t reflect.Type, f string) string

type ValidationError

type ValidationError struct {
	Path   *yaml.Path // YAML path to the validation error.
	Err    error      // Underlying error.
	Field  string     // Field name that failed validation.
	Detail string     // Detailed error message.
}

ValidationError represents a validation error from JSON schema validation. It wraps the original validation result and provides path information for yaml.Path.AnnotateSource.

func (ValidationError) Error

func (e ValidationError) Error() string

type Validator

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

Validator validates data against a JSON schema. Uses github.com/santhosh-tekuri/jsonschema/v6.

func NewValidator

func NewValidator(schemaData []byte) (*Validator, error)

NewValidator creates a new Validator with the provided JSON schema data.

func (*Validator) Validate

func (s *Validator) Validate(data any) error

ValidateWithSchema validates the given data against the schema. It returns a ValidationError that can be used with yaml.Path.AnnotateSource for precise error reporting.

Jump to

Keyboard shortcuts

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