schema

package
v0.0.0-...-2132f45 Latest Latest
Warning

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

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

Documentation

Overview

Package schema defines a data model for structured merges and diffs.

Index

Constants

View Source
const (
	Numeric = Scalar("numeric")
	String  = Scalar("string")
	Boolean = Scalar("boolean")
)
View Source
const (
	Associative = ListElementRelationship("associative")
	Atomic      = ListElementRelationship("atomic")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Atom

type Atom struct {
	// Exactly one of the below must be set.
	*Scalar  `yaml:"scalar,omitempty"`
	*Struct  `yaml:"struct,omitempty"`
	*List    `yaml:"list,omitempty"`
	*Map     `yaml:"map,omitempty"`
	*Untyped `yaml:"untyped,omitempty"`
}

Atom represents the smallest possible pieces of the type system.

type List

type List struct {
	ElementType TypeRef `yaml:"elementType,omitempty"`

	// ElementRelationship states the relationship between the list's elements
	// and must have one of these values:
	// * Atomic: the list is treated as a single entity, like a scalar.
	// * Associative:
	//   - If the list element is a scalar, the list is treated as a set.
	//   - If the list element is a struct, the list is treated as a map.
	//   - The list element must not be a map or a list itself.
	ElementRelationship ListElementRelationship `yaml:"elementRelationship,omitempty"`

	// Iff ElementRelationship is Associative, and the element type is
	// struct, then Keys must have non-zero length, and it lists the fields
	// of the element's struct type which are to be used as the keys of the
	// list.
	//
	// Each key must refer to a single field name (no nesting, not JSONPath).
	Keys []string `yaml:"keys,omitempty"`
}

List has zero or more elements of some type.

type ListElementRelationship

type ListElementRelationship string

ListElementRelationship is an enum of the different possible relationships between list elements.

type Map

type Map struct {
	ElementType TypeRef `yaml:"elementType,omitempty"`

	// Atomic maps must not have individual items merged.
	Atomic bool `yaml:"atomic,omitempty"`
}

Map is a key-value pair. Its semantics are the same as an associative list, but:

  • It is serialized differently: map: {"k": {"value": "v"}} list: [{"key": "k", "value": "v"}]
  • Keys must be string typed.
  • Keys can't have multiple components.

type Scalar

type Scalar string

Scalar (AKA "primitive") has a single value which is either numeric, string, or boolean.

type Schema

type Schema struct {
	Types []TypeDef `yaml:"types,omitempty"`
}

Schema is a list of types.

func (Schema) FindNamedType

func (s Schema) FindNamedType(name string) (TypeDef, bool)

FindNamedType returns the referenced TypeDef, if it exists, or (nil, false) if it doesn't.

func (Schema) Resolve

func (s Schema) Resolve(tr TypeRef) (Atom, bool)

Resolve returns the atom referenced, whether it is inline or named. Returns Atom{}, false if the type can't be resolved. Allows callers to not care about the difference between a (possibly inlined) reference and a definition.

type Struct

type Struct struct {
	// Each struct field appears exactly once in this list. The order in
	// this list defines the canonical field ordering.
	Fields []StructField `yaml:"fields,omitempty"`
}

Struct is a list of fields. Each field has a name and a type. Some fields may be grouped into unions.

type StructField

type StructField struct {
	// Name is the field name.
	Name string `yaml:"name,omitempty"`
	// Type is the field type.
	Type TypeRef `yaml:"type,omitempty"`
}

StructField pairs a field name with a field type.

type TypeDef

type TypeDef struct {
	// Top level types should be named. Every type must have a unique name.
	Name string `yaml:"name,omitempty"`

	Atom `yaml:"atom,omitempty,inline"`
}

TypeDef represents a node in a schema.

type TypeRef

type TypeRef struct {
	// Either the name or one member of Atom should be set.
	NamedType *string `yaml:"namedType,omitempty"`
	Inlined   Atom    `yaml:"inlined,inline,omitempty"`
}

TypeRef either refers to a named type or declares an inlined type.

type TypeSpecifier

type TypeSpecifier struct {
	Type   TypeRef `yaml:"type,omitempty"`
	Schema Schema  `yaml:"schema,omitempty"`
}

A TypeSpecifier references a particular type in a schema.

type Untyped

type Untyped struct{}

Untyped is used for fields that allow arbitrary content. (Think: plugin objects.)

Jump to

Keyboard shortcuts

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