Documentation ¶
Overview ¶
Package typed contains logic for operating on values with given schemas.
Index ¶
- type Comparison
- type ParseableType
- type Parser
- type TypedValue
- func (tv TypedValue) AsValue() *value.Value
- func (tv TypedValue) Compare(rhs *TypedValue) (c *Comparison, err error)
- func (tv TypedValue) Empty() *TypedValue
- func (tv TypedValue) Merge(pso *TypedValue) (*TypedValue, error)
- func (tv TypedValue) NormalizeUnions(new *TypedValue) (*TypedValue, error)
- func (tv TypedValue) NormalizeUnionsApply(new *TypedValue) (*TypedValue, error)
- func (tv TypedValue) RemoveItems(items *fieldpath.Set) *TypedValue
- func (tv TypedValue) ToFieldSet() (*fieldpath.Set, error)
- func (tv TypedValue) Validate() error
- type ValidationError
- type ValidationErrors
- type YAMLObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparison ¶
type Comparison struct { // Merged is the result of merging the two objects, as explained in the // comments on TypedValue.Merge(). Merged *TypedValue // Removed contains any fields removed by rhs (the right-hand-side // object in the comparison). Removed *fieldpath.Set // Modified contains fields present in both objects but different. Modified *fieldpath.Set // Added contains any fields added by rhs. Added *fieldpath.Set }
Comparison is the return value of a TypedValue.Compare() operation.
No field will appear in more than one of the three fieldsets. If all of the fieldsets are empty, then the objects must have been equal.
func (*Comparison) IsSame ¶
func (c *Comparison) IsSame() bool
IsSame returns true if the comparison returned no changes (the two compared objects are similar).
func (*Comparison) String ¶
func (c *Comparison) String() string
String returns a human readable version of the comparison.
type ParseableType ¶
ParseableType allows for easy production of typed objects.
var DeducedParseableType ParseableType = createOrDie(YAMLObject(`types:
- name: __untyped_atomic_
scalar: untyped
list:
elementType:
namedType: __untyped_atomic_
elementRelationship: atomic
map:
elementType:
namedType: __untyped_atomic_
elementRelationship: atomic
- name: __untyped_deduced_
scalar: untyped
list:
elementType:
namedType: __untyped_atomic_
elementRelationship: atomic
map:
elementType:
namedType: __untyped_deduced_
elementRelationship: separable
`)).Type("__untyped_deduced_")
DeducedParseableType is a ParseableType that deduces the type from the content of the object.
func (ParseableType) FromUnstructured ¶
func (p ParseableType) FromUnstructured(in interface{}) (*TypedValue, error)
FromUnstructured converts a go interface to a TypedValue. It will return an error if the resulting object fails schema validation.
func (ParseableType) FromYAML ¶
func (p ParseableType) FromYAML(object YAMLObject) (*TypedValue, error)
FromYAML parses a yaml string into an object with the current schema and the type "typename" or an error if validation fails.
func (ParseableType) IsValid ¶
func (p ParseableType) IsValid() bool
IsValid return true if p's schema and typename are valid.
type Parser ¶
Parser implements YAMLParser and allows introspecting the schema.
func NewParser ¶
func NewParser(schema YAMLObject) (*Parser, error)
NewParser will build a YAMLParser from a schema. The schema is validated.
func (*Parser) Type ¶
func (p *Parser) Type(name string) ParseableType
Type returns a helper which can produce objects of the given type. Any errors are deferred until a further function is called.
type TypedValue ¶
type TypedValue struct {
// contains filtered or unexported fields
}
TypedValue is a value of some specific type.
func AsTyped ¶
AsTyped accepts a value and a type and returns a TypedValue. 'v' must have type 'typeName' in the schema. An error is returned if the v doesn't conform to the schema.
func AsTypedUnvalidated ¶
AsTypeUnvalidated is just like AsTyped, but doesn't validate that the type conforms to the schema, for cases where that has already been checked or where you're going to call a method that validates as a side-effect (like ToFieldSet).
func (TypedValue) AsValue ¶
func (tv TypedValue) AsValue() *value.Value
AsValue removes the type from the TypedValue and only keeps the value.
func (TypedValue) Compare ¶
func (tv TypedValue) Compare(rhs *TypedValue) (c *Comparison, err error)
Compare compares the two objects. See the comments on the `Comparison` struct for details on the return value.
tv and rhs must both be of the same type (their Schema and TypeRef must match), or an error will be returned. Validation errors will be returned if the objects don't conform to the schema.
func (TypedValue) Empty ¶
func (tv TypedValue) Empty() *TypedValue
func (TypedValue) Merge ¶
func (tv TypedValue) Merge(pso *TypedValue) (*TypedValue, error)
Merge returns the result of merging tv and pso ("partially specified object") together. Of note:
- No fields can be removed by this operation.
- If both tv and pso specify a given leaf field, the result will keep pso's value.
- Container typed elements will have their items ordered:
- like tv, if pso doesn't change anything in the container
- like pso, if pso does change something in the container.
tv and pso must both be of the same type (their Schema and TypeRef must match), or an error will be returned. Validation errors will be returned if the objects don't conform to the schema.
func (TypedValue) NormalizeUnions ¶
func (tv TypedValue) NormalizeUnions(new *TypedValue) (*TypedValue, error)
NormalizeUnions takes the new object and normalizes the union: - If discriminator changed to non-nil, and a new field has been added that doesn't match, an error is returned, - If discriminator hasn't changed and two fields or more are set, an error is returned, - If discriminator changed to non-nil, all other fields but the discriminated one will be cleared, - Otherwise, If only one field is left, update discriminator to that value.
Please note: union behavior isn't finalized yet and this is still experimental.
func (TypedValue) NormalizeUnionsApply ¶
func (tv TypedValue) NormalizeUnionsApply(new *TypedValue) (*TypedValue, error)
NormalizeUnionsApply specifically normalize unions on apply. It validates that the applied union is correct (there should be no ambiguity there), and clear the fields according to the sent intent.
Please note: union behavior isn't finalized yet and this is still experimental.
func (TypedValue) RemoveItems ¶
func (tv TypedValue) RemoveItems(items *fieldpath.Set) *TypedValue
RemoveItems removes each provided list or map item from the value.
func (TypedValue) ToFieldSet ¶
func (tv TypedValue) ToFieldSet() (*fieldpath.Set, error)
ToFieldSet creates a set containing every leaf field and item mentioned, or validation errors, if any were encountered.
func (TypedValue) Validate ¶
func (tv TypedValue) Validate() error
Validate returns an error with a list of every spec violation.
type ValidationError ¶
ValidationError reports an error about a particular field
func (ValidationError) Error ¶
func (ve ValidationError) Error() string
Error returns a human readable error message.
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors accumulates multiple validation error messages.
func (ValidationErrors) Error ¶
func (errs ValidationErrors) Error() string
Error returns a human readable error message reporting each error in the list.