schema

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

func SchemaForFile(yamlFile string) (string, bool)

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

type ObjectSpec struct {
	Fields       []FieldSpec
	Required     []string
	Conditionals []Condition
}

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.

func Load

func Load(schemasDir, name string) (*Schema, error)

Load reads and parses the named schema from schemasDir. name is the base-name without ".schema.json", e.g. "resources".

type Severity

type Severity string

Severity indicates how serious a validation finding is.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

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.

Jump to

Keyboard shortcuts

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