constraint

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBytes

func ParseBytes(b []byte) error

Types

type AdditionalProperties

type AdditionalProperties struct {
	// contains filtered or unexported fields
}

func NewAdditionalProperties

func NewAdditionalProperties(ruleValue bytes.Bytes) *AdditionalProperties

NewAdditionalProperties create an additional properties constraint. Depends on `ruleValue` value, might return nil. Might panic if got unknown JSON type.

Handle next cases:

{additionalProperties: "any"}
{additionalProperties: true}
{additionalProperties: false} - in that case this function will return nil.
{additionalProperties: "@Foo"}
{additionalProperties: "string"}

func (AdditionalProperties) ASTNode

func (AdditionalProperties) IsEqual

func (AdditionalProperties) IsJsonTypeCompatible

func (AdditionalProperties) IsJsonTypeCompatible(t json.Type) bool

func (AdditionalProperties) Mode

func (AdditionalProperties) SchemaType

func (c AdditionalProperties) SchemaType() jschema.SchemaType

func (AdditionalProperties) String

func (c AdditionalProperties) String() string

func (AdditionalProperties) Type

func (AdditionalProperties) Type() Type

func (AdditionalProperties) TypeName

func (c AdditionalProperties) TypeName() bytes.Bytes

type AdditionalPropertiesMode

type AdditionalPropertiesMode int
const (
	AdditionalPropertiesCanBeAny AdditionalPropertiesMode = iota
	AdditionalPropertiesMustBeSchemaType
	AdditionalPropertiesMustBeType
	AdditionalPropertiesNotAllowed
)

type AllOf

type AllOf struct {
	// contains filtered or unexported fields
}

func NewAllOf

func NewAllOf() *AllOf

func (AllOf) ASTNode

func (c AllOf) ASTNode() jschema.RuleASTNode

func (*AllOf) Append

func (c *AllOf) Append(scalar bytes.Bytes)

func (AllOf) IsJsonTypeCompatible

func (AllOf) IsJsonTypeCompatible(t json.Type) bool

func (AllOf) SchemaNames

func (c AllOf) SchemaNames() []string

func (AllOf) String

func (c AllOf) String() string

func (AllOf) Type

func (AllOf) Type() Type

type AnyConstraint

type AnyConstraint struct{}

func NewAny

func NewAny() *AnyConstraint

func (AnyConstraint) ASTNode

func (AnyConstraint) ASTNode() jschema.RuleASTNode

func (AnyConstraint) IsJsonTypeCompatible

func (AnyConstraint) IsJsonTypeCompatible(json.Type) bool

func (AnyConstraint) String

func (AnyConstraint) String() string

func (AnyConstraint) Type

func (AnyConstraint) Type() Type

type ArrayValidator

type ArrayValidator interface {
	ValidateTheArray(numberOfChildren uint)
	Value() *json.Number
}

type BoolKeeper

type BoolKeeper interface {
	Bool() bool
}

type BytesKeeper

type BytesKeeper interface {
	Bytes() bytes.Bytes
}

type Const

type Const struct {
	// contains filtered or unexported fields
}

func NewConst

func NewConst(value, nodeValue bytes.Bytes) *Const

func (Const) ASTNode

func (c Const) ASTNode() jschema.RuleASTNode

func (Const) Bool

func (c Const) Bool() bool

func (Const) IsJsonTypeCompatible

func (Const) IsJsonTypeCompatible(t json.Type) bool

func (Const) String

func (c Const) String() string

func (Const) Type

func (Const) Type() Type

func (Const) Validate

func (c Const) Validate(v bytes.Bytes)

type Constraint

type Constraint interface {
	// Type returns the type of constraint.
	Type() Type

	// IsJsonTypeCompatible checks the compatibility of the constraint and json
	// types.
	IsJsonTypeCompatible(json.Type) bool

	// String returns a textual description of the constraint.
	String() string

	// ASTNode returns an AST node for this constraint.
	ASTNode() jschema.RuleASTNode
}

func NewConstraintFromRule

func NewConstraintFromRule(
	ruleNameLex lexeme.LexEvent,
	ruleValue bytes.Bytes,
	nodeValue bytes.Bytes,
) Constraint

NewConstraintFromRule creates a Constraint from the rule. Might return nil.

type Date

type Date struct {
}

func NewDate

func NewDate() *Date

func (Date) ASTNode

func (Date) ASTNode() jschema.RuleASTNode

func (Date) IsJsonTypeCompatible

func (Date) IsJsonTypeCompatible(t json.Type) bool

func (Date) String

func (Date) String() string

func (Date) Type

func (Date) Type() Type

func (Date) Validate

func (Date) Validate(value bytes.Bytes)

type DateTime

type DateTime struct{}

func NewDateTime

func NewDateTime() *DateTime

func (DateTime) ASTNode

func (DateTime) ASTNode() jschema.RuleASTNode

func (DateTime) IsJsonTypeCompatible

func (DateTime) IsJsonTypeCompatible(t json.Type) bool

func (DateTime) String

func (DateTime) String() string

func (DateTime) Type

func (DateTime) Type() Type

func (DateTime) Validate

func (DateTime) Validate(value bytes.Bytes)

type Email

type Email struct{}

func NewEmail

func NewEmail() *Email

func (Email) ASTNode

func (Email) ASTNode() jschema.RuleASTNode

func (Email) IsJsonTypeCompatible

func (Email) IsJsonTypeCompatible(t json.Type) bool

func (Email) String

func (Email) String() string

func (Email) Type

func (Email) Type() Type

func (Email) Validate

func (Email) Validate(email bytes.Bytes)

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

func NewEnum

func NewEnum() *Enum

func (Enum) ASTNode

func (c Enum) ASTNode() jschema.RuleASTNode

func (*Enum) Append

func (c *Enum) Append(b jbytes.Bytes) int

func (Enum) IsJsonTypeCompatible

func (Enum) IsJsonTypeCompatible(t json.Type) bool

func (*Enum) SetComment

func (c *Enum) SetComment(idx int, comment string)

func (Enum) String

func (c Enum) String() string

func (Enum) Type

func (Enum) Type() Type

func (Enum) Validate

func (c Enum) Validate(a jbytes.Bytes)

type ExclusiveMaximum

type ExclusiveMaximum struct {
	// contains filtered or unexported fields
}

func NewExclusiveMaximum

func NewExclusiveMaximum(ruleValue bytes.Bytes) *ExclusiveMaximum

func (ExclusiveMaximum) ASTNode

func (c ExclusiveMaximum) ASTNode() jschema.RuleASTNode

func (ExclusiveMaximum) IsExclusive

func (c ExclusiveMaximum) IsExclusive() bool

func (ExclusiveMaximum) IsJsonTypeCompatible

func (ExclusiveMaximum) IsJsonTypeCompatible(t json.Type) bool

func (ExclusiveMaximum) String

func (c ExclusiveMaximum) String() string

func (ExclusiveMaximum) Type

func (ExclusiveMaximum) Type() Type

type ExclusiveMinimum

type ExclusiveMinimum struct {
	// contains filtered or unexported fields
}

func NewExclusiveMinimum

func NewExclusiveMinimum(ruleValue bytes.Bytes) *ExclusiveMinimum

func (ExclusiveMinimum) ASTNode

func (c ExclusiveMinimum) ASTNode() jschema.RuleASTNode

func (ExclusiveMinimum) IsExclusive

func (c ExclusiveMinimum) IsExclusive() bool

func (ExclusiveMinimum) IsJsonTypeCompatible

func (ExclusiveMinimum) IsJsonTypeCompatible(t json.Type) bool

func (ExclusiveMinimum) String

func (c ExclusiveMinimum) String() string

func (ExclusiveMinimum) Type

func (ExclusiveMinimum) Type() Type

type LiteralValidator

type LiteralValidator interface {
	Validate(bytes.Bytes) // Checks the parameter value against the constraint. Panic on an error.
}

type Max

type Max struct {
	// contains filtered or unexported fields
}

func NewMax

func NewMax(ruleValue bytes.Bytes) *Max

func (Max) ASTNode

func (c Max) ASTNode() jschema.RuleASTNode

func (Max) IsJsonTypeCompatible

func (Max) IsJsonTypeCompatible(t json.Type) bool

func (*Max) SetExclusive

func (c *Max) SetExclusive(exclusive bool)

func (Max) String

func (c Max) String() string

func (Max) Type

func (Max) Type() Type

func (Max) Validate

func (c Max) Validate(value bytes.Bytes)

type MaxItems

type MaxItems struct {
	// contains filtered or unexported fields
}

func NewMaxItems

func NewMaxItems(ruleValue bytes.Bytes) *MaxItems

func (MaxItems) ASTNode

func (c MaxItems) ASTNode() jschema.RuleASTNode

func (MaxItems) IsJsonTypeCompatible

func (MaxItems) IsJsonTypeCompatible(t json.Type) bool

func (MaxItems) String

func (c MaxItems) String() string

func (MaxItems) Type

func (MaxItems) Type() Type

func (MaxItems) ValidateTheArray

func (c MaxItems) ValidateTheArray(numberOfChildren uint)

func (MaxItems) Value

func (c MaxItems) Value() *json.Number

type MaxLength

type MaxLength struct {
	// contains filtered or unexported fields
}

func NewMaxLength

func NewMaxLength(ruleValue bytes.Bytes) *MaxLength

func (MaxLength) ASTNode

func (c MaxLength) ASTNode() jschema.RuleASTNode

func (MaxLength) IsJsonTypeCompatible

func (MaxLength) IsJsonTypeCompatible(t json.Type) bool

func (MaxLength) String

func (c MaxLength) String() string

func (MaxLength) Type

func (MaxLength) Type() Type

func (MaxLength) Validate

func (c MaxLength) Validate(value bytes.Bytes)

type Min

type Min struct {
	// contains filtered or unexported fields
}

func NewMin

func NewMin(ruleValue bytes.Bytes) *Min

func (Min) ASTNode

func (c Min) ASTNode() jschema.RuleASTNode

func (Min) IsJsonTypeCompatible

func (Min) IsJsonTypeCompatible(t json.Type) bool

func (*Min) SetExclusive

func (c *Min) SetExclusive(exclusive bool)

func (Min) String

func (c Min) String() string

func (Min) Type

func (Min) Type() Type

func (Min) Validate

func (c Min) Validate(value bytes.Bytes)

type MinItems

type MinItems struct {
	// contains filtered or unexported fields
}

func NewMinItems

func NewMinItems(ruleValue bytes.Bytes) *MinItems

func (MinItems) ASTNode

func (c MinItems) ASTNode() jschema.RuleASTNode

func (MinItems) IsJsonTypeCompatible

func (MinItems) IsJsonTypeCompatible(t json.Type) bool

func (MinItems) String

func (c MinItems) String() string

func (MinItems) Type

func (MinItems) Type() Type

func (MinItems) ValidateTheArray

func (c MinItems) ValidateTheArray(numberOfChildren uint)

func (MinItems) Value

func (c MinItems) Value() *json.Number

type MinLength

type MinLength struct {
	// contains filtered or unexported fields
}

func NewMinLength

func NewMinLength(ruleValue bytes.Bytes) *MinLength

func (MinLength) ASTNode

func (c MinLength) ASTNode() jschema.RuleASTNode

func (MinLength) IsJsonTypeCompatible

func (MinLength) IsJsonTypeCompatible(t json.Type) bool

func (MinLength) String

func (c MinLength) String() string

func (MinLength) Type

func (MinLength) Type() Type

func (MinLength) Validate

func (c MinLength) Validate(value bytes.Bytes)

type Nullable

type Nullable struct {
	// contains filtered or unexported fields
}

func NewNullable

func NewNullable(ruleValue bytes.Bytes) *Nullable

func (Nullable) ASTNode

func (c Nullable) ASTNode() jschema.RuleASTNode

func (Nullable) Bool

func (c Nullable) Bool() bool

func (Nullable) IsJsonTypeCompatible

func (Nullable) IsJsonTypeCompatible(json.Type) bool

func (Nullable) String

func (c Nullable) String() string

func (Nullable) Type

func (Nullable) Type() Type

type Optional

type Optional struct {
	// contains filtered or unexported fields
}

func NewOptional

func NewOptional(ruleValue bytes.Bytes) *Optional

func (Optional) ASTNode

func (c Optional) ASTNode() jschema.RuleASTNode

func (Optional) Bool

func (c Optional) Bool() bool

func (Optional) IsJsonTypeCompatible

func (Optional) IsJsonTypeCompatible(json.Type) bool

func (Optional) String

func (c Optional) String() string

func (Optional) Type

func (Optional) Type() Type

type Or

type Or struct {
	// contains filtered or unexported fields
}

func NewOr

func NewOr(s jschema.RuleASTNodeSource) *Or

func (Or) ASTNode

func (Or) ASTNode() jschema.RuleASTNode

func (Or) IsGenerated

func (c Or) IsGenerated() bool

func (Or) IsJsonTypeCompatible

func (Or) IsJsonTypeCompatible(json.Type) bool

func (Or) String

func (Or) String() string

func (Or) Type

func (Or) Type() Type

type Precision

type Precision struct {
	// contains filtered or unexported fields
}

func NewPrecision

func NewPrecision(ruleValue bytes.Bytes) *Precision

func (Precision) ASTNode

func (c Precision) ASTNode() jschema.RuleASTNode

func (Precision) IsJsonTypeCompatible

func (Precision) IsJsonTypeCompatible(t json.Type) bool

func (Precision) String

func (c Precision) String() string

func (Precision) Type

func (Precision) Type() Type

func (Precision) Validate

func (c Precision) Validate(value bytes.Bytes)

type Regex

type Regex struct {
	// contains filtered or unexported fields
}

func NewRegex

func NewRegex(value bytes.Bytes) *Regex

func (Regex) ASTNode

func (c Regex) ASTNode() jschema.RuleASTNode

func (Regex) IsJsonTypeCompatible

func (Regex) IsJsonTypeCompatible(t internalJSON.Type) bool

func (Regex) String

func (c Regex) String() string

func (Regex) Type

func (Regex) Type() Type

func (Regex) Validate

func (c Regex) Validate(value bytes.Bytes)

type RequiredKeys

type RequiredKeys struct {
	// contains filtered or unexported fields
}

func NewRequiredKeys

func NewRequiredKeys() *RequiredKeys

func (RequiredKeys) ASTNode

func (c RequiredKeys) ASTNode() jschema.RuleASTNode

func (*RequiredKeys) AddKey

func (c *RequiredKeys) AddKey(key string)

func (RequiredKeys) IsJsonTypeCompatible

func (RequiredKeys) IsJsonTypeCompatible(t json.Type) bool

func (RequiredKeys) Keys

func (c RequiredKeys) Keys() []string

func (RequiredKeys) String

func (c RequiredKeys) String() string

func (RequiredKeys) Type

func (RequiredKeys) Type() Type

type Type

type Type int
const (
	MinLengthConstraintType Type = iota
	MaxLengthConstraintType
	MinConstraintType
	MaxConstraintType
	ExclusiveMinimumConstraintType
	ExclusiveMaximumConstraintType
	PrecisionConstraintType
	TypeConstraintType
	TypesListConstraintType
	OptionalConstraintType
	OrConstraintType
	RequiredKeysConstraintType
	EmailConstraintType
	MinItemsConstraintType
	MaxItemsConstraintType
	EnumConstraintType
	AdditionalPropertiesConstraintType
	AllOfConstraintType
	AnyConstraintType
	NullableConstraintType
	RegexConstraintType
	UriConstraintType
	DateConstraintType
	DateTimeConstraintType
	UuidConstraintType
	ConstType
)

func (Type) String

func (t Type) String() string

type TypeConstraint

type TypeConstraint struct {
	// contains filtered or unexported fields
}

func NewType

func NewType(ruleValue bytes.Bytes, source jschema.RuleASTNodeSource) *TypeConstraint

func (TypeConstraint) ASTNode

func (c TypeConstraint) ASTNode() jschema.RuleASTNode

func (TypeConstraint) Bytes

func (c TypeConstraint) Bytes() bytes.Bytes

func (TypeConstraint) IsGenerated

func (c TypeConstraint) IsGenerated() bool

func (TypeConstraint) IsJsonTypeCompatible

func (TypeConstraint) IsJsonTypeCompatible(json.Type) bool

func (TypeConstraint) Source

func (TypeConstraint) String

func (c TypeConstraint) String() string

func (TypeConstraint) Type

func (TypeConstraint) Type() Type

type TypesList

type TypesList struct {
	// contains filtered or unexported fields
}

func NewTypesList

func NewTypesList(s jschema.RuleASTNodeSource) *TypesList

func (TypesList) ASTNode

func (c TypesList) ASTNode() jschema.RuleASTNode

func (*TypesList) AddName

func (c *TypesList) AddName(name, typ string, s jschema.RuleASTNodeSource)

func (*TypesList) AddNameWithASTNode

func (c *TypesList) AddNameWithASTNode(name, typ string, an jschema.RuleASTNode)

func (TypesList) HasUserTypes

func (c TypesList) HasUserTypes() bool

func (TypesList) IsJsonTypeCompatible

func (TypesList) IsJsonTypeCompatible(json.Type) bool

func (TypesList) Len

func (c TypesList) Len() int

func (TypesList) Names

func (c TypesList) Names() []string

func (TypesList) Source

func (c TypesList) Source() jschema.RuleASTNodeSource

func (TypesList) String

func (c TypesList) String() string

func (TypesList) Type

func (TypesList) Type() Type

type Uri

type Uri struct{}

func NewUri

func NewUri() *Uri

func (Uri) ASTNode

func (Uri) ASTNode() jschema.RuleASTNode

func (Uri) IsJsonTypeCompatible

func (Uri) IsJsonTypeCompatible(t json.Type) bool

func (Uri) String

func (Uri) String() string

func (Uri) Type

func (Uri) Type() Type

func (Uri) Validate

func (Uri) Validate(value bytes.Bytes)

type Uuid

type Uuid struct{}

func NewUuid

func NewUuid() *Uuid

func (Uuid) ASTNode

func (Uuid) ASTNode() jschema.RuleASTNode

func (Uuid) IsJsonTypeCompatible

func (Uuid) IsJsonTypeCompatible(t json.Type) bool

func (Uuid) String

func (Uuid) String() string

func (Uuid) Type

func (Uuid) Type() Type

func (Uuid) Validate

func (Uuid) Validate(value jbytes.Bytes)

Jump to

Keyboard shortcuts

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