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 ¶
const ( AnnotationAssertValidate template.AnnotationName = "assert/validate" KwargWhen string = "when" KwargWhenNullSkip string = "when_null_skip" 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 ¶ added in v0.42.0
type Check struct {
Violations []error
}
Check holds the resulting violations from executing Validations on a node.
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) Error ¶ added in v0.42.0
Error generates the error message composed of the total set of Check.Violations.
func (*Check) HasViolations ¶ added in v0.42.0
HasViolations indicates whether this Check contains any violations.
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 ¶ added in v0.42.0
func NewValidationFromAnn(annotation template.NodeAnnotation) (*NodeValidation, error)
NewValidationFromAnn creates a NodeValidation from the values provided in a validationRun-style annotation.
func (*NodeValidation) DefaultNullSkipTrue ¶
func (v *NodeValidation) DefaultNullSkipTrue()
DefaultNullSkipTrue sets the kwarg when_null_skip to true if not set explicitly.