constraint

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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() schema.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
	AdditionalPropertiesMustBeUserType
	AdditionalPropertiesNotAllowed
)

type AllOf

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

func NewAllOf

func NewAllOf() *AllOf

func (AllOf) ASTNode

func (c AllOf) ASTNode() schema.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() schema.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() uint
}

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() schema.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() schema.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() schema.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() schema.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() schema.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() schema.RuleASTNode

func (*Enum) Append

func (c *Enum) Append(i EnumItem) int

func (Enum) IsJsonTypeCompatible

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

func (*Enum) RuleName

func (c *Enum) RuleName() string

func (*Enum) SetComment

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

func (*Enum) SetRuleName

func (c *Enum) SetRuleName(s string)

func (Enum) String

func (c Enum) String() string

func (Enum) Type

func (Enum) Type() Type

func (Enum) Validate

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

type EnumItem

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

func NewEnumItem

func NewEnumItem(b bytes.Bytes, c string) EnumItem

func (EnumItem) String

func (v EnumItem) String() string

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() schema.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() schema.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() schema.RuleASTNode

func (*Max) Exclusive

func (c *Max) Exclusive() bool

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)

func (*Max) Value

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

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() schema.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() uint

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() schema.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)

func (MaxLength) Value

func (c MaxLength) Value() uint

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() schema.RuleASTNode

func (*Min) Exclusive

func (c *Min) Exclusive() bool

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)

func (*Min) Value

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

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() schema.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() uint

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() schema.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)

func (MinLength) Value

func (c MinLength) Value() uint

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() schema.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() schema.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
}

Or constraint. Used for compile-time checking.

func NewOr

func NewOr(s schema.RuleASTNodeSource) *Or

func (Or) ASTNode

func (Or) ASTNode() schema.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() schema.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() schema.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
}

RequiredKeys constraint is specific constraint. It cannot be created directly by jSchema language rule. It is indirectly influenced by rule "optional" in object's children. All the children keys, that are not marked as "optional"=true, are treated as required and go to the RequiredKeys constraint of the parent object.

func NewRequiredKeys

func NewRequiredKeys() *RequiredKeys

func (RequiredKeys) ASTNode

func (c RequiredKeys) ASTNode() schema.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

Type available constraint types. gen:Stringer t Unknown constraint type

const (
	MinLengthConstraintType            Type = iota // minLength
	MaxLengthConstraintType                        // maxLength
	MinConstraintType                              // min
	MaxConstraintType                              // max
	ExclusiveMinimumConstraintType                 // exclusiveMinimum
	ExclusiveMaximumConstraintType                 // exclusiveMaximum
	PrecisionConstraintType                        // precision
	TypeConstraintType                             // type
	TypesListConstraintType                        // types
	OptionalConstraintType                         // optional
	OrConstraintType                               // or
	RequiredKeysConstraintType                     // required-keys
	EmailConstraintType                            // email
	MinItemsConstraintType                         // minItems
	MaxItemsConstraintType                         // maxItems
	EnumConstraintType                             // enum
	AdditionalPropertiesConstraintType             // additionalProperties
	AllOfConstraintType                            // allOf
	AnyConstraintType                              // any
	NullableConstraintType                         // nullable
	RegexConstraintType                            // regex
	UriConstraintType                              // uri
	DateConstraintType                             // date
	DateTimeConstraintType                         // datetime
	UuidConstraintType                             // uuid
	ConstConstraintType                            // const
	KeysCaseInsensitiveConstraintType
)

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 schema.RuleASTNodeSource) *TypeConstraint

func (TypeConstraint) ASTNode

func (c TypeConstraint) ASTNode() schema.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 schema.RuleASTNodeSource) *TypesList

func (TypesList) ASTNode

func (c TypesList) ASTNode() schema.RuleASTNode

func (*TypesList) AddName

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

func (*TypesList) AddNameWithASTNode

func (c *TypesList) AddNameWithASTNode(name, typ string, an schema.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() schema.RuleASTNodeSource

func (TypesList) String

func (c TypesList) String() string

func (TypesList) Type

func (TypesList) Type() Type

type UUID

type UUID struct{}

func NewUuid

func NewUuid() *UUID

func (UUID) ASTNode

func (UUID) ASTNode() schema.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 bytes.Bytes)

type Uri

type Uri struct{}

func NewUri

func NewUri() *Uri

func (Uri) ASTNode

func (Uri) ASTNode() schema.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)

Jump to

Keyboard shortcuts

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