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 ¶
- func ComposeInventory(values helmvalues.Schema, note string) (map[string]any, error)
- func Decode(b []byte) (any, error)
- func FileName(kind Kind) (string, error)
- func Kinds() []string
- func Load(kind Kind) (map[string]any, error)
- func Raw(kind Kind) ([]byte, error)
- type Kind
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeInventory ¶
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 ¶
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 ¶
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.
Types ¶
type Kind ¶
type Kind string
Kind names one of the file formats cargoship generates a schema for.
func DetectKind ¶
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 ¶
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 ¶
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 ¶
NewValidatorFor compiles the generated schema for a kind, for callers with nothing to compose.