Documentation
¶
Overview ¶
Package schema parses JSON Schema files from content/schemas/ and exposes FieldSpec models used by the content-editing UI and validation engine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KnownFiles ¶
func KnownFiles() []string
KnownFiles returns the set of YAML filenames that have an associated schema.
func SchemaForFile ¶
SchemaForFile returns the schema base-name for a given YAML filename, and whether one exists.
Types ¶
type Condition ¶
type Condition struct {
// IfConst is the constant value the trigger field must equal.
TriggerField string
TriggerConst string
// ThenFields lists fields that become required when the condition is met.
ThenRequired []string
// ThenEnum constrains enumerated values for a specific field when met.
ThenField string
ThenEnum []string
}
Condition holds an if/then conditional parsed from the schema.
type FieldSpec ¶
type FieldSpec struct {
Key string
Title string
Type string // "string","integer","boolean","array","object","map"
Required bool
Enum []string
Format string
Pattern string
MapValueType string // for Type=="map": the additionalProperties type
Children []FieldSpec
Condition *Condition
MinItems int
MaxItems int // 0 means no limit
ItemType string
ItemEnum []string
}
FieldSpec describes a single field extracted from a JSON Schema property.
type ObjectSpec ¶
ObjectSpec is the top-level specification for an object schema.
type Schema ¶
type Schema struct {
Name string
Title string
TopType string // "array" or "object"
ItemSpec *ObjectSpec // non-nil when TopType=="array"
ObjectSpec *ObjectSpec // non-nil when TopType=="object"
}
Schema is the parsed representation of one JSON Schema file.
type ValidationError ¶
type ValidationError struct {
Path string // JSON-pointer-style path, e.g. "[0].url"
Field string // field key
Message string // human-readable message
Severity Severity // "error" or "warning"
}
ValidationError describes a single validation finding.
func Validate ¶
func Validate(s *Schema, data any) []ValidationError
Validate dispatches to array or object validation based on the schema type. data should be the unmarshalled YAML/JSON value ([]any or map[string]any).
func (ValidationError) String ¶
func (e ValidationError) String() string
String returns a formatted representation of the error.