ischema

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: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNullableNode added in v0.2.0

func IsNullableNode(n Node) bool

IsNullableNode returns true is node is nullable.

func IsOptionalNode

func IsOptionalNode(n Node) bool

IsOptionalNode returns true is node is optional.

Types

type ArrayNode

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

func (*ArrayNode) ASTNode

func (n *ArrayNode) ASTNode() (schema.ASTNode, error)

func (*ArrayNode) AddConstraint

func (n *ArrayNode) AddConstraint(c constraint.Constraint)

AddConstraint adds new constraint to this node. Won't add if c is nil.

func (ArrayNode) BasisLexEventOfSchemaForNode

func (n ArrayNode) BasisLexEventOfSchemaForNode() lexeme.LexEvent

func (ArrayNode) Child

func (n ArrayNode) Child(i uint) Node

func (ArrayNode) Children

func (n ArrayNode) Children() []Node

func (*ArrayNode) Comment

func (n *ArrayNode) Comment() string

func (ArrayNode) Constraint

func (n ArrayNode) Constraint(t constraint.Type) constraint.Constraint

Constraint returns requested Constraint if found.

func (ArrayNode) ConstraintMap

func (n ArrayNode) ConstraintMap() *Constraints

ConstraintMap returns all constraints.

func (*ArrayNode) Copy

func (n *ArrayNode) Copy() Node

func (*ArrayNode) DeleteConstraint

func (n *ArrayNode) DeleteConstraint(t constraint.Type)

func (*ArrayNode) Grow

func (n *ArrayNode) Grow(lex lexeme.LexEvent) (Node, bool)

func (*ArrayNode) InheritedFrom

func (n *ArrayNode) InheritedFrom() string

func (ArrayNode) Len

func (n ArrayNode) Len() int

func (ArrayNode) NumberOfConstraints

func (n ArrayNode) NumberOfConstraints() int

func (ArrayNode) Parent

func (n ArrayNode) Parent() Node

func (*ArrayNode) RealType

func (n *ArrayNode) RealType() string

func (ArrayNode) SchemaType

func (n ArrayNode) SchemaType() schema.SchemaType

func (*ArrayNode) SetComment

func (n *ArrayNode) SetComment(s string)

func (*ArrayNode) SetInheritedFrom

func (n *ArrayNode) SetInheritedFrom(s string)

func (*ArrayNode) SetParent

func (n *ArrayNode) SetParent(parent Node)

func (*ArrayNode) SetRealType

func (n *ArrayNode) SetRealType(s string) bool

func (ArrayNode) Type

func (n ArrayNode) Type() json.Type

func (ArrayNode) Value

func (n ArrayNode) Value() bytes.Bytes

type BranchNode

type BranchNode interface {
	Children() []Node
	Len() int
}

BranchNode that can contain child elements (an array or an object).

type Constraints

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

Constraints an ordered map of node constraints. gen:OrderedMap

func (*Constraints) Delete

func (m *Constraints) Delete(k constraint.Type)

func (*Constraints) Each

func (m *Constraints) Each(fn eachConstraintsFunc) error

func (*Constraints) EachSafe

func (m *Constraints) EachSafe(fn eachSafeConstraintsFunc)

func (*Constraints) Filter

func (m *Constraints) Filter(fn filterConstraintsFunc)

Filter iterates and changes values in the map.

func (*Constraints) Find

func (m *Constraints) Find(fn findConstraintsFunc) (ConstraintsItem, bool)

Find finds first matched item from the map.

func (*Constraints) Get

Get gets a value by key.

func (*Constraints) GetValue

GetValue gets a value by key.

func (*Constraints) Has

func (m *Constraints) Has(k constraint.Type) bool

Has checks that specified key is set.

func (*Constraints) Len

func (m *Constraints) Len() int

Len returns count of values.

func (*Constraints) Map

func (m *Constraints) Map(fn mapConstraintsFunc) error

Map iterates and changes values in the map.

func (*Constraints) MarshalJSON

func (m *Constraints) MarshalJSON() ([]byte, error)

func (*Constraints) Set

Set sets a value with specified key.

func (*Constraints) Update

Update updates a value with specified key.

type ConstraintsItem

type ConstraintsItem struct {
	Key   constraint.Type
	Value constraint.Constraint
}

ConstraintsItem represent single data from the Constraints.

type ISchema

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

func New

func New() ISchema

func (*ISchema) AddNamedType

func (s *ISchema) AddNamedType(name string, typ *ISchema, rootFile *fs.File, begin bytes.Index)

func (*ISchema) AddType

func (s *ISchema) AddType(n string, t Type)

func (*ISchema) AddUnnamedType

func (s *ISchema) AddUnnamedType(typ *ISchema, rootFile *fs.File, begin bytes.Index) string

AddUnnamedType Adds an unnamed TYPE to the SCHEMA. Returns a unique name for the added TYPE.

func (ISchema) MustType

func (s ISchema) MustType(name string) *ISchema

MustType returns *ISchema or panic if not found.

func (ISchema) RootNode

func (s ISchema) RootNode() Node

func (*ISchema) SetRootNode

func (s *ISchema) SetRootNode(node Node)

func (ISchema) Type

func (s ISchema) Type(name string) (*ISchema, *errs.Err)

Type returns specified type's schema.

func (ISchema) TypesList

func (s ISchema) TypesList() map[string]Type

type LiteralNode

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

func (*LiteralNode) ASTNode

func (n *LiteralNode) ASTNode() (schema.ASTNode, error)

func (*LiteralNode) AddConstraint

func (n *LiteralNode) AddConstraint(c constraint.Constraint)

AddConstraint adds new constraint to this node. Won't add if c is nil.

func (LiteralNode) BasisLexEventOfSchemaForNode

func (n LiteralNode) BasisLexEventOfSchemaForNode() lexeme.LexEvent

func (*LiteralNode) Comment

func (n *LiteralNode) Comment() string

func (LiteralNode) Constraint

func (n LiteralNode) Constraint(t constraint.Type) constraint.Constraint

Constraint returns requested Constraint if found.

func (LiteralNode) ConstraintMap

func (n LiteralNode) ConstraintMap() *Constraints

ConstraintMap returns all constraints.

func (*LiteralNode) Copy

func (n *LiteralNode) Copy() Node

func (*LiteralNode) DeleteConstraint

func (n *LiteralNode) DeleteConstraint(t constraint.Type)

func (*LiteralNode) Grow

func (n *LiteralNode) Grow(lex lexeme.LexEvent) (Node, bool)

func (*LiteralNode) InheritedFrom

func (n *LiteralNode) InheritedFrom() string

func (LiteralNode) NumberOfConstraints

func (n LiteralNode) NumberOfConstraints() int

func (LiteralNode) Parent

func (n LiteralNode) Parent() Node

func (*LiteralNode) RealType

func (n *LiteralNode) RealType() string

func (LiteralNode) SchemaType

func (n LiteralNode) SchemaType() schema.SchemaType

func (*LiteralNode) SetComment

func (n *LiteralNode) SetComment(s string)

func (*LiteralNode) SetInheritedFrom

func (n *LiteralNode) SetInheritedFrom(s string)

func (*LiteralNode) SetParent

func (n *LiteralNode) SetParent(parent Node)

func (*LiteralNode) SetRealType

func (n *LiteralNode) SetRealType(s string) bool

func (LiteralNode) Type

func (n LiteralNode) Type() json.Type

func (LiteralNode) Value

func (n LiteralNode) Value() bytes.Bytes

type MixedNode

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

func NewMixedNode

func NewMixedNode(lex lexeme.LexEvent) *MixedNode

func (MixedNode) ASTNode

func (n MixedNode) ASTNode() (schema.ASTNode, error)

func (*MixedNode) AddConstraint

func (n *MixedNode) AddConstraint(c constraint.Constraint)

AddConstraint adds new constraint to this node. Won't add if c is nil.

func (MixedNode) BasisLexEventOfSchemaForNode

func (n MixedNode) BasisLexEventOfSchemaForNode() lexeme.LexEvent

func (*MixedNode) Comment

func (n *MixedNode) Comment() string

func (MixedNode) Constraint

func (n MixedNode) Constraint(t constraint.Type) constraint.Constraint

Constraint returns requested Constraint if found.

func (MixedNode) ConstraintMap

func (n MixedNode) ConstraintMap() *Constraints

ConstraintMap returns all constraints.

func (*MixedNode) Copy

func (n *MixedNode) Copy() Node

func (*MixedNode) DeleteConstraint

func (n *MixedNode) DeleteConstraint(t constraint.Type)

func (*MixedNode) Grow

func (*MixedNode) Grow(lexeme.LexEvent) (Node, bool)

func (*MixedNode) InheritedFrom

func (n *MixedNode) InheritedFrom() string

func (MixedNode) NumberOfConstraints

func (n MixedNode) NumberOfConstraints() int

func (MixedNode) Parent

func (n MixedNode) Parent() Node

func (*MixedNode) RealType

func (n *MixedNode) RealType() string

func (MixedNode) SchemaType

func (n MixedNode) SchemaType() schema.SchemaType

func (*MixedNode) SetComment

func (n *MixedNode) SetComment(s string)

func (*MixedNode) SetInheritedFrom

func (n *MixedNode) SetInheritedFrom(s string)

func (*MixedNode) SetJsonType

func (n *MixedNode) SetJsonType(t json.Type)

SetJsonType for mixed node n.baseNode.jsonType is an EXAMPLE type

func (*MixedNode) SetParent

func (n *MixedNode) SetParent(parent Node)

func (*MixedNode) SetRealType

func (*MixedNode) SetRealType(string) bool

func (MixedNode) Type

func (n MixedNode) Type() json.Type

func (MixedNode) Value

func (n MixedNode) Value() bytes.Bytes

type MixedValueNode

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

func NewMixedValueNode

func NewMixedValueNode(lex lexeme.LexEvent) *MixedValueNode

func (*MixedValueNode) ASTNode

func (n *MixedValueNode) ASTNode() (schema.ASTNode, error)

func (*MixedValueNode) AddConstraint

func (n *MixedValueNode) AddConstraint(c constraint.Constraint)

func (MixedValueNode) BasisLexEventOfSchemaForNode

func (n MixedValueNode) BasisLexEventOfSchemaForNode() lexeme.LexEvent

func (*MixedValueNode) Comment

func (n *MixedValueNode) Comment() string

func (MixedValueNode) Constraint

func (n MixedValueNode) Constraint(t constraint.Type) constraint.Constraint

Constraint returns requested Constraint if found.

func (MixedValueNode) ConstraintMap

func (n MixedValueNode) ConstraintMap() *Constraints

ConstraintMap returns all constraints.

func (*MixedValueNode) Copy

func (n *MixedValueNode) Copy() Node

func (*MixedValueNode) DeleteConstraint

func (n *MixedValueNode) DeleteConstraint(t constraint.Type)

func (*MixedValueNode) GetTypes

func (n *MixedValueNode) GetTypes() []string

func (*MixedValueNode) Grow

func (n *MixedValueNode) Grow(lex lexeme.LexEvent) (Node, bool)

func (*MixedValueNode) InheritedFrom

func (n *MixedValueNode) InheritedFrom() string

func (MixedValueNode) NumberOfConstraints

func (n MixedValueNode) NumberOfConstraints() int

func (MixedValueNode) Parent

func (n MixedValueNode) Parent() Node

func (*MixedValueNode) RealType

func (n *MixedValueNode) RealType() string

func (MixedValueNode) SchemaType

func (n MixedValueNode) SchemaType() schema.SchemaType

func (*MixedValueNode) SetComment

func (n *MixedValueNode) SetComment(s string)

func (*MixedValueNode) SetInheritedFrom

func (n *MixedValueNode) SetInheritedFrom(s string)

func (*MixedValueNode) SetParent

func (n *MixedValueNode) SetParent(parent Node)

func (*MixedValueNode) SetRealType

func (*MixedValueNode) SetRealType(string) bool

func (MixedValueNode) Type

func (n MixedValueNode) Type() json.Type

func (MixedValueNode) Value

func (n MixedValueNode) Value() bytes.Bytes

type Node

type Node interface {
	// Type returns type of this node.
	Type() json.Type
	SchemaType() schema.SchemaType

	SetRealType(string) bool
	RealType() string

	// Parent returns a parent of this node.
	Parent() Node

	// SetParent sets a parent for this node.
	SetParent(Node)

	// BasisLexEventOfSchemaForNode returns a LexEvent from the scheme on the
	// basis of which the node is created. It is used to check on the schemes for
	// compliance with the example and the list of constraints. Also used to display
	// an error.
	BasisLexEventOfSchemaForNode() lexeme.LexEvent

	// Grow this method receives the input lexical event from the scanner, fill
	// yourself with data from them. If necessary, creates children. Returns the
	// node to which you want to pass the next lexeme (yourself, child, or parent).
	Grow(lexeme.LexEvent) (Node, bool)

	// Constraint returns a constraint by its type.
	Constraint(constraint.Type) constraint.Constraint

	// AddConstraint adds a constraint to this node.
	AddConstraint(constraint.Constraint)

	// DeleteConstraint removes a constraint from this node.
	DeleteConstraint(constraint.Type)

	// ConstraintMap returns a list of constraints or nil (if empty).
	ConstraintMap() *Constraints

	// NumberOfConstraints returns the number of constraints.
	NumberOfConstraints() int

	// Value returns this node's value.
	Value() bytes.Bytes

	// ASTNode returns proper ASTNode for this node.
	ASTNode() (schema.ASTNode, error)

	// SetComment sets a comment for this node.
	SetComment(string)

	// Comment returns this node comment.
	Comment() string

	SetInheritedFrom(string)
	InheritedFrom() string
	Copy() Node
}

The Node of the internal representation of the scheme. Roughly corresponds to the JSON element in the EXAMPLE of schema. Contains information about the constraints imposed on the node.

func NewNode

func NewNode(lex lexeme.LexEvent) Node

func VirtualNodeForAny added in v0.2.0

func VirtualNodeForAny() Node

type ObjectNode

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

func NewObjectNode

func NewObjectNode(lex lexeme.LexEvent) *ObjectNode

func (*ObjectNode) ASTNode

func (n *ObjectNode) ASTNode() (schema.ASTNode, error)

func (*ObjectNode) AddChild

func (n *ObjectNode) AddChild(key ObjectNodeKey, child Node)

func (*ObjectNode) AddConstraint

func (n *ObjectNode) AddConstraint(c constraint.Constraint)

AddConstraint adds new constraint to this node. Won't add if c is nil.

func (*ObjectNode) AddKey

func (n *ObjectNode) AddKey(key string, isShortcut bool, lex lexeme.LexEvent)

func (ObjectNode) BasisLexEventOfSchemaForNode

func (n ObjectNode) BasisLexEventOfSchemaForNode() lexeme.LexEvent

func (*ObjectNode) Child

func (n *ObjectNode) Child(key string, isShortcut bool) (Node, bool)

Child returns child bye specified key.

func (*ObjectNode) ChildByRawKey

func (n *ObjectNode) ChildByRawKey(rawKey bytes.Bytes) (Node, bool)

ChildByRawKey returns child by raw key as is present in schema. For instance: "foo" or @foo (shortcut).

func (*ObjectNode) Children

func (n *ObjectNode) Children() []Node

func (*ObjectNode) Comment

func (n *ObjectNode) Comment() string

func (ObjectNode) Constraint

func (n ObjectNode) Constraint(t constraint.Type) constraint.Constraint

Constraint returns requested Constraint if found.

func (ObjectNode) ConstraintMap

func (n ObjectNode) ConstraintMap() *Constraints

ConstraintMap returns all constraints.

func (*ObjectNode) Copy

func (n *ObjectNode) Copy() Node

func (*ObjectNode) CopyAndLowercaseKeys added in v0.2.0

func (n *ObjectNode) CopyAndLowercaseKeys() *ObjectNode

func (*ObjectNode) DeleteConstraint

func (n *ObjectNode) DeleteConstraint(t constraint.Type)

func (*ObjectNode) EnsureAdditionalProperties added in v0.2.0

func (n *ObjectNode) EnsureAdditionalProperties()

func (*ObjectNode) Grow

func (n *ObjectNode) Grow(lex lexeme.LexEvent) (Node, bool)

func (*ObjectNode) InheritedFrom

func (n *ObjectNode) InheritedFrom() string

func (*ObjectNode) Key

func (n *ObjectNode) Key(index int) ObjectNodeKey

func (*ObjectNode) Keys

func (n *ObjectNode) Keys() *ObjectNodeKeys

func (*ObjectNode) Len

func (n *ObjectNode) Len() int

func (ObjectNode) NumberOfConstraints

func (n ObjectNode) NumberOfConstraints() int

func (ObjectNode) Parent

func (n ObjectNode) Parent() Node

func (*ObjectNode) RealType

func (n *ObjectNode) RealType() string

func (ObjectNode) SchemaType

func (n ObjectNode) SchemaType() schema.SchemaType

func (*ObjectNode) SetComment

func (n *ObjectNode) SetComment(s string)

func (*ObjectNode) SetInheritedFrom

func (n *ObjectNode) SetInheritedFrom(s string)

func (*ObjectNode) SetParent

func (n *ObjectNode) SetParent(parent Node)

func (*ObjectNode) SetRealType

func (n *ObjectNode) SetRealType(s string) bool

func (*ObjectNode) Type

func (*ObjectNode) Type() json.Type

func (ObjectNode) Value

func (n ObjectNode) Value() bytes.Bytes

type ObjectNodeKey

type ObjectNodeKey struct {
	Key        string
	Lex        lexeme.LexEvent
	Index      int
	IsShortcut bool
}

type ObjectNodeKeys

type ObjectNodeKeys struct {
	Data []ObjectNodeKey
	// contains filtered or unexported fields
}

func (ObjectNodeKeys) Find

func (k ObjectNodeKeys) Find(i int) (ObjectNodeKey, bool)

func (ObjectNodeKeys) Get

func (k ObjectNodeKeys) Get(key string, isShortcut bool) (ObjectNodeKey, bool)

func (*ObjectNodeKeys) Set

func (k *ObjectNodeKeys) Set(v ObjectNodeKey)

type Type

type Type struct {
	Schema   *ISchema
	RootFile *fs.File
	Begin    bytes.Index
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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