validators

package
v1.0.0-beta15 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConstTerm = ls.NewTerm(ls.LS, "validation/const", false, false, ls.OverrideComposition, struct {
	EnumValidator
}{
	EnumValidator{},
})

ConstTerm is used for constant value validator

Const is declared as a string value:

{
   @id: attrId,
   @type: Value,
   validation/const: "a"
}

Const is syntactic sugar for enum with a single value

View Source
var EnumTerm = ls.NewTerm(ls.LS, "validation/enumeration", false, false, ls.OverrideComposition, struct {
	EnumValidator
}{
	EnumValidator{},
})

EnumTerm is used for enumeration validator

Enumeration is declared as a string slice:

{
   @id: attrId,
   @type: Value,
   validation/enumeration: ["a","b","c"]
}
View Source
var JsonFormatTerm = ls.NewTerm(ls.LS, "validation/json/format", false, false, ls.OverrideComposition, struct {
	JsonFormatValidator
}{
	JsonFormatValidator{},
})

JsonFormatTerm validates if the value matches one of the json format implementations

View Source
var PatternTerm = ls.NewTerm(ls.LS, "validation/pattern", false, false, ls.OverrideComposition, struct {
	PatternValidator
}{
	PatternValidator{},
})

PatternTerm validates against a regex

View Source
var RequiredTerm = ls.NewTerm(ls.LS, "validation/required", false, false, ls.OverrideComposition, struct {
	RequiredValidator
}{
	RequiredValidator{},
})

RequiredTerm validates if a required properties exist.

{
  @id: attrId
  validation/required: true
}

Functions

This section is empty.

Types

type EnumValidator

type EnumValidator struct{}

EnumValidator checks if a value is equal to one of the given options.

func (EnumValidator) ValidateNode

func (validator EnumValidator) ValidateNode(docNode, schemaNode graph.Node) error

ValidateNode validates the node value if it is non-nil

func (EnumValidator) ValidateValue

func (validator EnumValidator) ValidateValue(value *string, schemaNode graph.Node) error

type JsonFormatValidator

type JsonFormatValidator struct{}

JsonFormatValidator checks if the input value matches a given format

func (JsonFormatValidator) CompileTerm

func (validator JsonFormatValidator) CompileTerm(target ls.CompilablePropertyContainer, term string, value *ls.PropertyValue) error

func (JsonFormatValidator) ValidateNode

func (validator JsonFormatValidator) ValidateNode(docNode, schemaNode graph.Node) error

ValidateNode validates the node value if it is non-nil

func (JsonFormatValidator) ValidateValue

func (validator JsonFormatValidator) ValidateValue(value *string, schemaNode graph.Node) error

ValidateValue checks if the value matches the format

type PatternValidator

type PatternValidator struct{}

PatternValidator validates a string value against a regex

func (PatternValidator) CompileTerm

func (validator PatternValidator) CompileTerm(target ls.CompilablePropertyContainer, term string, value *ls.PropertyValue) error

Compile the pattern

func (PatternValidator) ValidateNode

func (validator PatternValidator) ValidateNode(docNode, schemaNode graph.Node) error

Validate validates the node value if it is non-nil

func (PatternValidator) ValidateValue

func (validator PatternValidator) ValidateValue(value *string, schemaNode graph.Node) error

ValidateValue validates the value

type RequiredValidator

type RequiredValidator struct{}

RequiredValidator validates if a required value exists

func (RequiredValidator) CompileTerm

func (validator RequiredValidator) CompileTerm(target ls.CompilablePropertyContainer, term string, value *ls.PropertyValue) error

CompileTerm compiles the required properties array

func (RequiredValidator) Validate

func (validator RequiredValidator) Validate(docNode, schemaNode graph.Node) error

Validate checks if value is nil. If value is nil and it is required, returns an error

func (RequiredValidator) ValidateNode

func (validator RequiredValidator) ValidateNode(docNode, schemaNode graph.Node) error

ValidateNode checks if value is nil. If value is nil and it is required, returns an error

func (RequiredValidator) ValidateValue

func (validator RequiredValidator) ValidateValue(value *string, schemaNode graph.Node) error

ValidateValue checks if value is nil. If value is nil and it is required, returns an error

Jump to

Keyboard shortcuts

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