Documentation ¶
Overview ¶
Package validations enriches YAML structures by attaching user-defined constraints (that is, validationRun rules) onto individual yamlmeta.Node's.
Validations on Data Values ¶
While "@data/values" can technically be annotated with "@assert/validate" annotations, it is expected that authors will use "@schema/validationRun" in "@data/values-schema" documents instead.
Index ¶
- Constants
- func Add(node yamlmeta.Node, validations []NodeValidation)
- func ProcessAssertValidateAnns(rootNode yamlmeta.Node) error
- func Set(node yamlmeta.Node, meta []NodeValidation)
- type Check
- type Invalidation
- type NodeValidation
- func (v NodeValidation) HasSimpleMax() (interface{}, bool)
- func (v NodeValidation) HasSimpleMaxLength() (int64, bool)
- func (v NodeValidation) HasSimpleMin() (interface{}, bool)
- func (v NodeValidation) HasSimpleMinLength() (int64, bool)
- func (v NodeValidation) HasSimpleOneOf() ([]interface{}, bool)
- func (v NodeValidation) Validate(node yamlmeta.Node, parent yamlmeta.Node, root yamlmeta.Node, path string, ...) (Invalidation, error)
- type Violation
Constants ¶
const ( AnnotationAssertValidate template.AnnotationName = "assert/validate" KwargWhen string = "when" KwargMinLength string = "min_len" KwargMaxLength string = "max_len" KwargMin string = "min" KwargMax string = "max" KwargNotNull string = "not_null" KwargOneNotNull string = "one_not_null" KwargOneOf string = "one_of" )
Declare @assert/... annotation and keyword argument names
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(node yamlmeta.Node, validations []NodeValidation)
Add appends validations to node's validations metadata, later retrieved via Get().
func ProcessAssertValidateAnns ¶
ProcessAssertValidateAnns checks Assert annotations on data values and stores them on a Node as Validations. Returns an error if any Assert annotations are malformed.
func Set ¶
func Set(node yamlmeta.Node, meta []NodeValidation)
Set attaches validations to node's metadata, later retrieved via Get().
Types ¶
type Check ¶
type Check struct {
Invalidations []Invalidation
}
Check holds the complete set of Invalidations (if any) resulting from checking all validation rules.
func Run ¶
Run takes a root Node, and threadName, and validates each Node in the tree.
When a Node's value is invalid, the errors are collected and returned in a Check. Otherwise, returns empty Check and nil error.
func (Check) HasInvalidations ¶
HasInvalidations indicates whether this Check contains any violations.
func (Check) ResultsAsString ¶
ResultsAsString generates the error message composed of the total set of Check.Invalidations.
type Invalidation ¶
Invalidation describes a value that was invalidated, and how.
type NodeValidation ¶
type NodeValidation struct {
// contains filtered or unexported fields
}
NodeValidation represents a validationRun attached to a Node via an annotation.
func Get ¶
func Get(node yamlmeta.Node) []NodeValidation
Get retrieves validations from node metadata, set previously via Set().
func NewValidationFromAnn ¶
func NewValidationFromAnn(annotation template.NodeAnnotation) (*NodeValidation, error)
NewValidationFromAnn creates a NodeValidation from the values provided in a validationRun-style annotation.
func (NodeValidation) HasSimpleMax ¶ added in v0.49.0
func (v NodeValidation) HasSimpleMax() (interface{}, bool)
HasSimpleMax indicates presence of max validation and its associated value. Returns false if validation is conditional (via when=).
func (NodeValidation) HasSimpleMaxLength ¶ added in v0.49.0
func (v NodeValidation) HasSimpleMaxLength() (int64, bool)
HasSimpleMaxLength indicates presence of max length validation and its associated value. Returns false if validation is conditional (via when=).
func (NodeValidation) HasSimpleMin ¶ added in v0.49.0
func (v NodeValidation) HasSimpleMin() (interface{}, bool)
HasSimpleMin indicates presence of min validation and its associated value. Returns false if validation is conditional (via when=).
func (NodeValidation) HasSimpleMinLength ¶ added in v0.49.0
func (v NodeValidation) HasSimpleMinLength() (int64, bool)
HasSimpleMinLength indicates presence of min length validation and its associated value. Returns false if validation is conditional (via when=).
func (NodeValidation) HasSimpleOneOf ¶ added in v0.49.0
func (v NodeValidation) HasSimpleOneOf() ([]interface{}, bool)
HasSimpleOneOf indicates presence of one-of validation and its allowed values. Returns false if validation is conditional (via when=).
func (NodeValidation) Validate ¶
func (v NodeValidation) Validate(node yamlmeta.Node, parent yamlmeta.Node, root yamlmeta.Node, path string, thread *starlark.Thread) (Invalidation, error)
Validate runs the assertions in the rules with the node's value as arguments IF the ValidationKwargs conditional options pass.
Returns an error if the assertion returns False (not-None), or assert.fail()s. Otherwise, returns nil.