Documentation
¶
Index ¶
- func IsValidType(s string) bool
- type ASTNode
- type ASTNodes
- func (m *ASTNodes) Delete(k string)
- func (m *ASTNodes) Each(fn eachASTNodesFunc) error
- func (m *ASTNodes) EachSafe(fn eachSafeASTNodesFunc)
- func (m *ASTNodes) Filter(fn filterASTNodesFunc)
- func (m *ASTNodes) Find(fn findASTNodesFunc) (ASTNodesItem, bool)
- func (m *ASTNodes) Get(k string) (ASTNode, bool)
- func (m *ASTNodes) GetValue(k string) ASTNode
- func (m *ASTNodes) Has(k string) bool
- func (m *ASTNodes) Len() int
- func (m *ASTNodes) Map(fn mapASTNodesFunc) error
- func (m *ASTNodes) MarshalJSON() ([]byte, error)
- func (m *ASTNodes) Set(k string, v ASTNode)
- func (m *ASTNodes) Update(k string, fn func(v ASTNode) ASTNode)
- type ASTNodesItem
- type Document
- type Rule
- type RuleASTNode
- type RuleASTNodeSource
- type RuleASTNodes
- func (m *RuleASTNodes) Delete(k string)
- func (m *RuleASTNodes) Each(fn eachRuleASTNodesFunc) error
- func (m *RuleASTNodes) EachSafe(fn eachSafeRuleASTNodesFunc)
- func (m *RuleASTNodes) Filter(fn filterRuleASTNodesFunc)
- func (m *RuleASTNodes) Find(fn findRuleASTNodesFunc) (RuleASTNodesItem, bool)
- func (m *RuleASTNodes) Get(k string) (RuleASTNode, bool)
- func (m *RuleASTNodes) GetValue(k string) RuleASTNode
- func (m *RuleASTNodes) Has(k string) bool
- func (m *RuleASTNodes) Len() int
- func (m *RuleASTNodes) Map(fn mapRuleASTNodesFunc) error
- func (m *RuleASTNodes) MarshalJSON() ([]byte, error)
- func (m *RuleASTNodes) Set(k string, v RuleASTNode)
- func (m *RuleASTNodes) Update(k string, fn func(v RuleASTNode) RuleASTNode)
- type RuleASTNodesItem
- type Schema
- type SchemaType
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidType ¶
Types ¶
type ASTNode ¶
type ASTNode struct {
// TokenType corresponding JSON type for this AST node's value.
TokenType TokenType
// SchemaType corresponding schema type for this AST node's value.
SchemaType string
// Key a node key (if this is the property of the object).
Key string
// Value a node value.
// Make sense only for scalars and shortcuts.
Value string
// Comment a ast node comment.
Comment string
// Rules a map of attached rules.
Rules *RuleASTNodes
// Children contains all array items and object properties.
// Make sense only for arrays and object.
Children []ASTNode
// IsKeyShortcut will be true if this property key is shortcut.
// Make sense only for AST nodes which are represents object property.
IsKeyShortcut bool
// InheritedFrom a user type from which this property is inherited.
InheritedFrom string
}
ASTNode an AST node.
func (*ASTNode) ObjectProperty ¶
type ASTNodes ¶
type ASTNodes struct {
// contains filtered or unexported fields
}
ASTNodes an ordered map of AST nodes. gen:OrderedMap
func (*ASTNodes) Filter ¶
func (m *ASTNodes) Filter(fn filterASTNodesFunc)
Filter iterates and changes values in the map.
func (*ASTNodes) Find ¶
func (m *ASTNodes) Find(fn findASTNodesFunc) (ASTNodesItem, bool)
Find finds first matched item from the map.
func (*ASTNodes) MarshalJSON ¶
type ASTNodesItem ¶
ASTNodesItem represent single data from the ASTNodes.
type Document ¶
type Document interface {
// NextLexeme returns next lexeme from this document.
// Might return ParsingError if document isn't valid.
// Will return io.EOF when no more lexemes are available.
NextLexeme() (lexeme.LexEvent, error)
// Len returns length of document in bytes.
// Might return ParsingError if document isn't valid.
Len() (uint, error)
// Check checks that this document is valid.
// Can return ParsingError if document isn't valid.
Check() error
// Content returns the entire contents of the document
Content() bytes.Bytes
}
Document represents a document. It's a concrete data. Data maybe a scalar type or complex type.
Not a thead safe!
Example of the valid documents: - "foo" - [1, 2, 3] - {"foo": "bar"}
type Rule ¶
type Rule interface {
// Len returns length of this rule in bytes.
// Might return ParsingError if rule isn't valid.
Len() (uint, error)
// Check checks this rule is valid.
// Can return ParsingError if rule isn't valid.
Check() error
// GetAST returns a root AST node for this schema.
GetAST() (ASTNode, error)
}
Rule represents a custom user-defined rule.
type RuleASTNode ¶
type RuleASTNode struct {
// TokenType corresponding JSON type for this AST node's value.
TokenType TokenType
// Value a node value.
// Make sense only for scalars and shortcuts.
Value string
// Comment a ast node comment.
Comment string
// Properties contains all object properties.
// Make sense only for objects.
Properties *RuleASTNodes
// Items contains all array items.
// Make sense only for arrays.
Items []RuleASTNode
// Source a source of this rule.
Source RuleASTNodeSource
}
type RuleASTNodeSource ¶
type RuleASTNodeSource int
const ( RuleASTNodeSourceUnknown RuleASTNodeSource = iota // RuleASTNodeSourceManual indicates rule added manually by the user. RuleASTNodeSourceManual // RuleASTNodeSourceGenerated indicates rule generated inside the code. RuleASTNodeSourceGenerated )
type RuleASTNodes ¶
type RuleASTNodes struct {
// contains filtered or unexported fields
}
RuleASTNodes an ordered map of rule AST nodes. gen:OrderedMap
func MakeRuleASTNodes ¶
func MakeRuleASTNodes(capacity int) *RuleASTNodes
func NewRuleASTNodes ¶
func NewRuleASTNodes(data map[string]RuleASTNode, order []string) *RuleASTNodes
func (*RuleASTNodes) Delete ¶
func (m *RuleASTNodes) Delete(k string)
func (*RuleASTNodes) Each ¶
func (m *RuleASTNodes) Each(fn eachRuleASTNodesFunc) error
func (*RuleASTNodes) EachSafe ¶
func (m *RuleASTNodes) EachSafe(fn eachSafeRuleASTNodesFunc)
func (*RuleASTNodes) Filter ¶
func (m *RuleASTNodes) Filter(fn filterRuleASTNodesFunc)
Filter iterates and changes values in the map.
func (*RuleASTNodes) Find ¶
func (m *RuleASTNodes) Find(fn findRuleASTNodesFunc) (RuleASTNodesItem, bool)
Find finds first matched item from the map.
func (*RuleASTNodes) Get ¶
func (m *RuleASTNodes) Get(k string) (RuleASTNode, bool)
Get gets a value by key.
func (*RuleASTNodes) GetValue ¶
func (m *RuleASTNodes) GetValue(k string) RuleASTNode
GetValue gets a value by key.
func (*RuleASTNodes) Has ¶
func (m *RuleASTNodes) Has(k string) bool
Has checks that specified key is set.
func (*RuleASTNodes) Map ¶
func (m *RuleASTNodes) Map(fn mapRuleASTNodesFunc) error
Map iterates and changes values in the map.
func (*RuleASTNodes) MarshalJSON ¶
func (m *RuleASTNodes) MarshalJSON() ([]byte, error)
func (*RuleASTNodes) Set ¶
func (m *RuleASTNodes) Set(k string, v RuleASTNode)
Set sets a value with specified key.
func (*RuleASTNodes) Update ¶
func (m *RuleASTNodes) Update(k string, fn func(v RuleASTNode) RuleASTNode)
Update updates a value with specified key.
type RuleASTNodesItem ¶
type RuleASTNodesItem struct {
Key string
Value RuleASTNode
}
RuleASTNodesItem represent single data from the RuleASTNodes.
type Schema ¶
type Schema interface {
// Len returns length of this schema in bytes.
// Might return ParsingError if schema isn't valid.
Len() (uint, error)
// Example returns an example for this schema.
// Might return ParsingError if schema isn't valid.
Example() ([]byte, error)
// AddType adds a new type to this schema.
// Might return a ParsingError if add type isn't valid.
AddType(name string, schema Schema) error
// AddRule adds a new type to this schema.
// Might return a ParsingError if add type isn't valid.
AddRule(name string, schema Rule) error
// Check checks that this schema is valid.
// Can return ParsingError if schema isn't valid.
Check() error
// GetAST returns a root AST node for this schema.
GetAST() (ASTNode, error)
// UsedUserTypes return all used user types.
UsedUserTypes() ([]string, error)
}
Schema represents a schema. Schema is a some description of expected structure of payload.
type SchemaType ¶
type SchemaType string
const ( SchemaTypeUndefined SchemaType = "" SchemaTypeString SchemaType = "string" SchemaTypeInteger SchemaType = "integer" SchemaTypeFloat SchemaType = "float" SchemaTypeDecimal SchemaType = "decimal" SchemaTypeBoolean SchemaType = "boolean" SchemaTypeObject SchemaType = "object" SchemaTypeArray SchemaType = "array" SchemaTypeNull SchemaType = "null" SchemaTypeEmail SchemaType = "email" SchemaTypeURI SchemaType = "uri" SchemaTypeUUID SchemaType = "uuid" SchemaTypeDate SchemaType = "date" SchemaTypeDateTime SchemaType = "datetime" SchemaTypeEnum SchemaType = "enum" SchemaTypeMixed SchemaType = "mixed" SchemaTypeAny SchemaType = "any" SchemaTypeComment SchemaType = "comment" )
func GuessSchemaType ¶
func GuessSchemaType(b []byte) (SchemaType, error)
func (SchemaType) IsEqualSoft ¶
func (t SchemaType) IsEqualSoft(x SchemaType) bool
IsEqualSoft compare two types with next assumptions% - Decimal is the same as float; - Email, URI, UUID, Date, and DateTime are the same as string; - Enum, Mixed and Any are the same as any other type.
func (SchemaType) IsOneOf ¶
func (t SchemaType) IsOneOf(tt ...SchemaType) bool
IsOneOf return true if current schema is one of specified.
func (SchemaType) IsScalar ¶
func (t SchemaType) IsScalar() bool
func (SchemaType) ToTokenType ¶
func (t SchemaType) ToTokenType() string