configschema

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package configschema derives the published JSON Schema (schema/apic-config.schema.json) from the generator's config model, and validates JSON/YAML configs against it. It is build-time tooling: tests and tools/configschema.go call it; nothing at runtime does.

Index

Constants

View Source
const (
	// SchemaPath is where the committed schema lives, relative to ModuleRoot.
	SchemaPath = "schema/apic-config.schema.json"
	// SchemaID is the schema's $id.
	SchemaID = "https://devnw.dev/apic/schema/apic-config.schema.json"
	// Draft is the JSON Schema dialect the generated schema declares.
	Draft = "https://json-schema.org/draft/2020-12/schema"
)
View Source
const (
	// ConfigsDir is the fixture corpus root, relative to ModuleRoot.
	ConfigsDir = "configs"
	// YAMLDir contains the deterministic YAML representations.
	YAMLDir = "configs/yaml"
)

Variables

View Source
var ErrBuild = errors.New("configschema: build")

ErrBuild wraps schema construction failures.

View Source
var ErrSchemaViolation = errors.New("configschema: config violates schema")

ErrSchemaViolation wraps a config that does not conform to the schema (or cannot be parsed as JSON at all).

View Source
var ErrTwin = errors.New("configschema: yaml twin")

ErrTwin wraps YAML-twin path and conversion failures.

Functions

func Build

func Build() (doc map[string]any, err error)

Build returns the JSON Schema (draft 2020-12) for the apic config as a generic document. Reflection over generator.Config supplies the structure (json tags, embedded-struct promotion with outer-shadows-embedded precedence, pointer nullability, additionalProperties:false everywhere to mirror the generator's RejectUnknownMembers decode); Go doc comments supply descriptions; overlay.go supplies enums and required members.

func BuildJSON

func BuildJSON() (out []byte, err error)

BuildJSON renders Build() deterministically: sorted keys, two-space indent, trailing newline — the exact bytes committed at SchemaPath.

func BuildJSONWithSourceRoot added in v0.19.0

func BuildJSONWithSourceRoot(sourceRoot string) (out []byte, err error)

BuildJSONWithSourceRoot builds the deterministic schema using only the explicitly supplied metadata source checkout. The source root is distinct from any config corpus or output root and is opened exactly once.

func Check

func Check(root string) (inspected []string, err error)

Check inspects the schema then sorted source/twin paths using actual on-disk fragments. It never repairs or mutates on success or failure and aggregates drift, ownership, strict-reader, representation and real resolution errors.

func CheckWithSourceRoot added in v0.19.0

func CheckWithSourceRoot(root, sourceRoot string) (inspected []string, err error)

CheckWithSourceRoot performs the read-only Check using an explicit metadata source checkout, kept separate from the config corpus root.

func CorpusFiles

func CorpusFiles(root string) (jsonFiles, yamlFiles []string, err error)

CorpusFiles returns all JSON and YAML config documents below ConfigsDir. It retains the current public inventory surface independently of the stricter canonical-source/owned-twin enumeration used by artifact planning.

func ModuleRoot

func ModuleRoot() string

ModuleRoot returns the apic checkout root derived only from this source file's compiled absolute location. An unavailable or trimpath-relative location returns ""; callers that build schema metadata must then use an explicit source-root API. It never falls back to the working directory.

func SourcePath

func SourcePath(yamlRel string) (string, error)

SourcePath is the byte-exact inverse of TwinPath within the dedicated tree.

func ToYAMLTwin

func ToYAMLTwin(jsonData []byte) ([]byte, error)

ToYAMLTwin returns deterministic YAML body bytes, retaining exact JSON scalar tokens and presence. Only direct root.schemas.<name>.$ref file imports change.

func TwinPath

func TwinPath(jsonRel string) (string, error)

TwinPath maps an exact portable canonical JSON path to its owned YAML path. Invalid spellings are refused, never cleaned into an accepted source name.

func Write

func Write(root string) (changed []string, err error)

Write fully validates the canonical corpus, planned twins and ownership before any mutation. It returns sorted actually updated or removed artifact paths, including completed operations if an operational failure interrupts apply.

func WriteWithSourceRoot added in v0.19.0

func WriteWithSourceRoot(root, sourceRoot string) (changed []string, err error)

WriteWithSourceRoot performs Write using an explicit metadata source checkout, kept separate from the config corpus/output root.

Types

type Validator

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

Validator validates config documents against one compiled schema.

func Compile

func Compile(schemaJSON []byte) (*Validator, error)

Compile compiles a draft 2020-12 schema document.

func LoadValidator

func LoadValidator(root string) (*Validator, error)

LoadValidator compiles the committed schema (SchemaPath) under root.

func (*Validator) Validate

func (v *Validator) Validate(cfgJSON []byte) error

Validate checks one JSON config document (bytes as returned by configfile.ReadFile / ToJSON) against the schema.

func (*Validator) ValidateFile

func (v *Validator) ValidateFile(path string) error

ValidateFile reads a JSON or YAML config and validates it. Cross-file "$ref" stubs are validated as written (the schema permits them); resolution is not needed for shape checking.

Jump to

Keyboard shortcuts

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