schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schema provides tag-driven defaults and validation for config structs.

Index

Constants

View Source
const ReservedContextKey = "mcpsmithy"

ReservedContextKey is the template context key injected by the engine. It is the canonical definition shared across all config versions.

Variables

View Source
var ParamTypeSource string

ParamTypeSource is the raw Go source of paramtype.go, embedded at compile time. Callers include this alongside version-specific type sources when calling ParseTypeDocs so that ParamType docs are available.

Functions

func Process

func Process(v any) []error

Process applies tag-driven defaults and validates v in a single traversal.

Both operations share walkLeafFields: for each leaf field it first applies any default= value (via the set callback, which handles map write-back internally), then runs all field-level validators on the (now-defaulted) value. OneOf groups require struct-scope visibility so they run in a second pass via walkStructNodes.

All validation errors are returned (required fields, enum, min, ref, oneof, notreserved, template syntax, typed-as).

func ZeroForParamType

func ZeroForParamType(pt ParamType) any

ZeroForParamType returns a type-appropriate zero value for template validation dry-runs.

Types

type DocProvider

type DocProvider struct {
	Types  map[string]string            // type name → doc
	Fields map[string]map[string]string // type name → Go field name → doc
	Values map[string]map[string]string // type name → enum value → doc
}

DocProvider supplies documentation extracted from Go source comments. Populated by the AST walker in v1/docs.go and passed to Describe.

func ParseTypeDocs

func ParseTypeDocs(srcs ...string) DocProvider

ParseTypeDocs parses Go source files and extracts doc comments for types, struct fields, and typed string const values into a DocProvider. Accepts multiple source strings; results are merged with later sources overwriting earlier ones on collision.

type EnumDoc

type EnumDoc struct {
	Name   string
	Doc    string
	Values []EnumValueDoc
}

EnumDoc describes a named string type with const values.

type EnumValueDoc

type EnumValueDoc struct {
	Label string
	Doc   string
}

EnumValueDoc is a single enum value with its label and doc.

type FieldDoc

type FieldDoc struct {
	YAMLName    string
	Type        string // plain type string (e.g. "Tool", "string[]", "map[string]Convention")
	TypeRef     string // non-empty when the leaf type is a known schema type (e.g. "Convention")
	Required    string // "yes", "no", or "oneof"
	Default     string // "—" or the default value
	Description string
	Min         string // "" or the minimum value as a string
	NotReserved bool
	Refs        []string
	OneOfGroups []OneOfGroup // mutual-exclusivity groups this field belongs to
}

FieldDoc describes a single struct field.

type OneOfGroup

type OneOfGroup struct {
	Group    string   // group name (internal identifier from the tag)
	Optional bool     // true = at-most-one (oneof?=); false = exactly-one (oneof=)
	Peers    []string // yaml names of the other fields in this group
}

OneOfGroup describes a mutual-exclusivity group membership for a field.

type ParamType

type ParamType string

ParamType names the valid parameter types for tool definitions. Use one of these as the type: value in a tool parameter.

The classification methods (IsNumeric, IsStringLike, IsBoolean) and Compatible implement TypeClassifier, enabling the schema engine to validate typed-as constraints without per-version logic.

const (
	// JSON Schema string.
	ParamTypeString ParamType = "string"
	// JSON Schema number (float64).
	ParamTypeNumber ParamType = "number"
	// JSON Schema boolean.
	ParamTypeBool ParamType = "bool"
	// JSON Schema array.
	ParamTypeArray ParamType = "array"
	// String validated as a file path inside the project sandbox.
	ParamTypeProjectFilePath ParamType = "project_file_path"
)

func (ParamType) Compatible

func (p ParamType) Compatible(v any) error

Compatible reports whether the given Go value is compatible with this param type. YAML unmarshals integers as int, floats as float64, strings as string, and booleans as bool. A mismatch means the config author wrote the wrong literal type. Implements TypeClassifier.

func (ParamType) IsBoolean

func (p ParamType) IsBoolean() bool

IsBoolean reports whether this param type expects bool Go values. Implements TypeClassifier.

func (ParamType) IsNumeric

func (p ParamType) IsNumeric() bool

IsNumeric reports whether this param type accepts numeric constraints (min/max). Implements TypeClassifier.

func (ParamType) IsStringLike

func (p ParamType) IsStringLike() bool

IsStringLike reports whether this param type expects string Go values. Implements TypeClassifier.

func (ParamType) Values

func (ParamType) Values() []string

Values returns the set of valid ParamType values. Implements Valuer for automatic enum validation.

type SchemaDoc

type SchemaDoc struct {
	Version string
	Structs []StructDoc
	Enums   []EnumDoc
	Types   []TypeDoc // named non-struct, non-enum types (e.g. TemplateString)
}

SchemaDoc holds the fully described schema for a config version.

func Describe

func Describe(v any, version string, docs DocProvider) SchemaDoc

Describe walks the type tree rooted at v (typically a zero-value config struct like v1.Config{}) and produces a SchemaDoc using reflection and struct tags. Documentation strings come from docs (populated from Go source comments via go/ast).

func FilterTypes

func FilterTypes(doc SchemaDoc, names map[string]bool) SchemaDoc

FilterTypes returns a new SchemaDoc containing only the structs and enums whose names appear in the names set. Used by setup to extract the types relevant to a specific config section.

func (SchemaDoc) KnownTypes

func (d SchemaDoc) KnownTypes() map[string]bool

KnownTypes builds the set of type names present in a SchemaDoc. Callers can use this for cross-linking when rendering.

type StructDoc

type StructDoc struct {
	Name   string
	Doc    string
	Fields []FieldDoc
}

StructDoc describes a config struct type.

type TypeDoc

type TypeDoc struct {
	Name string
	Doc  string
}

TypeDoc describes a named non-struct type (e.g. a named string).

Jump to

Keyboard shortcuts

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