schema

package
v0.29.0 Latest Latest
Warning

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

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

Documentation

Overview

Package schema serves the JSON Schema documents cargoship generates for its own file formats, out of the binary rather than over the network. The documents under embedded/ are byte-identical copies of the repository's schema/ directory, written by the same `mage generate:schema` target; go:embed cannot reach outside its own package directory, which is why the copy exists at all.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeInventory

func ComposeInventory(values helmvalues.Schema, note string) (map[string]any, error)

ComposeInventory returns the inventory schema with a package's values schema grafted onto spec.config.values, so an editor can complete and check the one block of an inventory whose vocabulary belongs to the package rather than to cargoship.

note is appended to the grafted node's description - the package name and version, so a generated file left lying around says which package it came from.

The result describes the override subtree on its own, while cargoship validates the package's values merged with the overrides. It therefore catches the mistakes that are wrong in either reading - an unknown key, a wrong type, a name outside an enum or pattern - and does not attempt to reproduce install-time validation.

func Decode

func Decode(b []byte) (any, error)

Decode reads a YAML document into the shape a JSON Schema validator expects.

The round trip through JSON is not redundant. YAML carries types JSON Schema has no words for -- a timestamp, an integer key, a value larger than a float64 -- and a validator handed one of them reports a type error that has nothing to do with the file. Encoding to JSON and back settles every value into the six types the schema is written against, which is the same normalization the document would undergo on its way to any other JSON Schema tool.

func FileName

func FileName(kind Kind) (string, error)

FileName returns the name the document carries in the repository, so a caller writing it to disk can use the name an editor's $schema reference already expects.

func Kinds

func Kinds() []string

Kinds returns every kind that can be served, sorted, for flag validation and shell completion.

func Load

func Load(kind Kind) (map[string]any, error)

Load returns the generated document for a kind, decoded, for callers that need to compose it rather than hand it straight to an editor.

func Raw

func Raw(kind Kind) ([]byte, error)

Raw returns the generated document for a kind, exactly as it sits in the repository, trailing newline included.

Types

type Kind

type Kind string

Kind names one of the file formats cargoship generates a schema for.

const (
	// KindInventory is the cluster inventory a `--config` flag points at.
	KindInventory Kind = "inventory"
	// KindPackage is a package definition, a distro.yaml.
	KindPackage Kind = "package"
	// KindConfig is a cargoship CLI configuration file.
	KindConfig Kind = "config"
)

func DetectKind

func DetectKind(doc any) (Kind, error)

DetectKind reads the schema kind out of a decoded document's own kind field, so that a file says what it is rather than the operator having to.

type ValidationError

type ValidationError struct {
	Source   string
	Kind     Kind
	Problems []string
}

ValidationError reports every way one document failed its schema.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type Validator

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

Validator checks documents against one schema. The schema is compiled once and reused, which is what makes checking a directory of packages worth doing in a single process.

func NewValidator

func NewValidator(kind Kind, doc map[string]any) (*Validator, error)

NewValidator compiles a schema document for repeated use. Pass the document rather than the kind, so that a composed inventory schema is checked exactly as an editor would check it.

func NewValidatorFor

func NewValidatorFor(kind Kind) (*Validator, error)

NewValidatorFor compiles the generated schema for a kind, for callers with nothing to compose.

func (*Validator) Kind

func (v *Validator) Kind() Kind

Kind returns the schema this validator checks against.

func (*Validator) Validate

func (v *Validator) Validate(source string, doc any) error

Validate checks a decoded document and returns a ValidationError listing every problem, not just the first: a file with four mistakes in it should take one run to fix, not four.

Jump to

Keyboard shortcuts

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