Documentation
¶
Index ¶
- Constants
- type AncestorTypeRef
- type NativeOption
- func (n NativeOption) AddBool(key string, val bool)
- func (n NativeOption) AddKeyVal(key, val string)
- func (n NativeOption) AddThreeFlag(key string, val threeflag.ThreeFlag)
- func (n NativeOption) AddVal(val string)
- func (n NativeOption) AsList() []string
- func (n NativeOption) Copy() NativeOption
- func (n NativeOption) Delete(key string)
- func (n NativeOption) Equals(other NativeOption) bool
- func (n NativeOption) UpdateFrom(other NativeOption)
- type NativeType
- type NodePool
- type PathList
- type Schema
- type StructFieldTag
- type Tags
- type TypeList
- type TypeNode
- func (t *TypeNode) AddChild(childElem *TypeNode)
- func (t *TypeNode) Ancestors() []*TypeNode
- func (t *TypeNode) ChildByName(name string, m map[string]*TypeNode) *TypeNode
- func (t *TypeNode) ChildKeys(m map[string]*TypeNode) []string
- func (t *TypeNode) ChildMap() map[string]*TypeNode
- func (t *TypeNode) ContainsChild(name string, m map[string]*TypeNode) bool
- func (t *TypeNode) Copy() *TypeNode
- func (t *TypeNode) GetName(lang string) string
- func (t *TypeNode) GetNativeType(dialect string) *NativeType
- func (t *TypeNode) IsBasicType() bool
- func (t *TypeNode) IsExported() bool
- func (t *TypeNode) NativeDefault() *NativeType
- func (t *TypeNode) NewChild(name string) *TypeNode
- func (t *TypeNode) Node(id string) *TypeNode
- func (t *TypeNode) RemoveAllChildren()
- func (t *TypeNode) RemoveChild(childElem *TypeNode)
- func (t *TypeNode) RemoveParent()
- func (t *TypeNode) SetName(dialect, alias string)
- func (t *TypeNode) SetParent(p *TypeNode)
Constants ¶
const ( InvalidKindErr = "kind not supported" RootKindErr = "root type must be a struct" CyclicalReferenceErr = "cyclical reference" NilInterfaceErr = "interface element is nil" EmptyStructErr = "empty struct not supported" EmptyMapErr = "empty map not supported" NoExportedFieldsErr = "struct has no exported fields" MapKeyTypeErr = "map key type must be string" SliceMultiTypeErr = "slice contains multiple kinds" DuplicateMapKeyErr = "duplicate map key" )
Errors for type reflection.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AncestorTypeRef ¶
AncestorTypeRef keeps track of type references that are ancestors of the current element. - Stores a count of references found. - If count > 1, a cyclical reference exists.
func NewAncestorTypeRef ¶
func NewAncestorTypeRef() AncestorTypeRef
NewAncestorTypeRef initializes a new ancestor list.
func (AncestorTypeRef) Add ¶
func (a AncestorTypeRef) Add(key string) int
Add adds a reference count to the ancestor list.
func (AncestorTypeRef) Contains ¶
func (a AncestorTypeRef) Contains(key string) bool
Contains returns true if the key exists in ancestor list.
func (AncestorTypeRef) Copy ¶
func (a AncestorTypeRef) Copy() AncestorTypeRef
Copy makes a copy of the ancestor list.
type NativeOption ¶
NativeOption stores options as key-value pairs but returns a list of strings. - Value-only entries are unique by value. - Values with keys are unique by key.
func NewNativeOption ¶
func NewNativeOption() NativeOption
func (NativeOption) AddBool ¶
func (n NativeOption) AddBool(key string, val bool)
AddBool adds a boolean as an option string. - key is required
- if key is empty, nothing is added
- val is boolean value
func (NativeOption) AddKeyVal ¶
func (n NativeOption) AddKeyVal(key, val string)
AddKeyVal adds an option string key=val
func (NativeOption) AddThreeFlag ¶
func (n NativeOption) AddThreeFlag(key string, val threeflag.ThreeFlag)
AddThreeFlag adds a ThreeFlag value as a string. - key is required
- if key is empty, nothing is added
- val is ThreeFlag value
func (NativeOption) AddVal ¶
func (n NativeOption) AddVal(val string)
AddVal adds an option value string.
func (NativeOption) AsList ¶
func (n NativeOption) AsList() []string
AsList returns options as a slice of strings.
func (NativeOption) Copy ¶
func (n NativeOption) Copy() NativeOption
Copy makes a copy of the NativeOption.
func (NativeOption) Delete ¶
func (n NativeOption) Delete(key string)
Delete removes an entry from the option map. - key will match either key-value pairs or value-only settings.
func (NativeOption) Equals ¶
func (n NativeOption) Equals(other NativeOption) bool
Equals returns true if both NativeOption struct have the same values.
func (NativeOption) UpdateFrom ¶
func (n NativeOption) UpdateFrom(other NativeOption)
UpdateFrom updates with values from another NativeOption.
type NativeType ¶
type NativeType struct { // Name of language of dialect represented by NativeType. Dialect string // Name of element if different from generic Name. Name string `json:",omitempty"` // Native type of element if different from the generic Type. Type string `json:",omitempty"` // TypeRef holds the native name of a type if different from the generic TypeRef. TypeRef string `json:",omitempty"` // Include indicates whether an element should be included in output for a dialect. // Include has three value values: // - "" (empty string) means value is not set // - "yes" = include element in output // - "no" = exclude element from output Include threeflag.ThreeFlag // Options contains a list of strings representing dialect-specific options. // - Format is one of: // - "value" // - "key=value" Options NativeOption // Capture error if element cannot reflect. Error string `json:",omitempty"` }
NativeType holds key-value attributes specific to one dialect. - A dialect is the name of a language (e.g. golang) or implementation (e.g. json-schema)
func NewNativeType ¶
func NewNativeType(dialect string) *NativeType
NewNativeType initializes a new NativeType with default settings.
func (*NativeType) AsMap ¶
func (n *NativeType) AsMap() map[string]string
AsMap returns a map[string]string representation of the NativeType struct.
func (*NativeType) Copy ¶
func (n *NativeType) Copy() *NativeType
Copy makes a copy of a NativeType.
func (*NativeType) UpdateFromTag ¶
func (n *NativeType) UpdateFromTag(t *StructFieldTag)
UpdateFromTag sets NativeType fields from a StructFieldTag.
type NodePool ¶ added in v0.0.6
type NodePool struct { // Nodes is a map of all TypeNodes by ID. Nodes map[string]*TypeNode // LastID holds the last assigned ID number. IDs are assigned sequentially. LastID int }
NodePool creates and holds all TypeNodes.
func NewNodePool ¶ added in v0.0.6
func NewNodePool() *NodePool
NewNodePool initializes a new NodePool.
func (*NodePool) NewRootNode ¶ added in v0.0.6
NewRootNode creates a new type element that is a root of a tree.
func (*NodePool) NewTypeNode ¶ added in v0.0.6
NewTypeNode returns a new TypeNode in the current NodePool.
type PathList ¶
type PathList struct {
// contains filtered or unexported fields
}
PathList keeps a list of path string elements that form a unique identifier for a TypeNode. - PathList behaves like a stack with Push/Pop operators.
func NewPathList ¶
func NewPathList() *PathList
type Schema ¶
type Schema struct { // RootID is the node ID of the root of types in the order found. RootID string // TypeRefID is the node ID that holds a map of named types by name. TypeRefID string // NodePool is the pool of all TypeNodes. NodePool *NodePool }
Schema is the result of parsing types.
func (*Schema) TypeRefNode ¶ added in v0.0.6
type StructFieldTag ¶
type StructFieldTag struct { Ignore bool Alias string Options NativeOption }
StructFieldTag stores attributes of a struct field tag.
Tags are parsed as follows: - tag="-" --> ignored field, Ignore=true - tag="someString" --> alias only, Alias = "someString" - tag="someString,options" --> alias with options, Alias="someString", Options=remainder after the first comma - If tag = "-", Ignore is true -->
func NewStructFieldTag ¶
func NewStructFieldTag(tag string) *StructFieldTag
NewStructFieldTag parses the contents of tag string to initialize a StructFieldTag. - Reference for common tags: https://zchee.github.io/golang-wiki/Well-known-struct-tags/
Tags always follow the pattern: <alias>,<comma-delimited options> - if tag string is "-", field is ignored - either <alias> or <options> can be omitted - if <options> is empty, the comma may be omitted
func (*StructFieldTag) Equals ¶
func (s *StructFieldTag) Equals(other *StructFieldTag) bool
Equals returns true if two StructFieldTag structs have the same values.
type TypeList ¶
type TypeList struct {
// contains filtered or unexported fields
}
TypeList holds a slice of TypeElements. - Behavior is similar to a stack with Push/Pop methods to add/remove elements from the end
func NewTypeList ¶
func NewTypeList() *TypeList
func (*TypeList) Copy ¶
Copy makes a copy of the current TypeList. - Parent is set if parentElem is not nil.
type TypeNode ¶ added in v0.0.6
type TypeNode struct { // Unique identifier for an element. ID string // Optional Name and Description of element. // - Name applies to struct/map types with string keys. Name string `json:",omitempty"` Description string `json:",omitempty"` // Nullable indicates that a field should accept null in addition to values. Nullable bool `json:",omitempty"` // Generic type of element. TypeCategory string Type string // TypeRef holds the name of a type (e.g. struct) TypeRef string `json:",omitempty"` // NativeDialect is the name of the dialect that was the source for the schema. NativeDialect string `json:",omitempty"` // Native type features by dialect name. Native map[string]*NativeType // Capture error if element cannot reflect. Error string `json:",omitempty"` // MetaKey is a tag attached to a top-level node during schema derivation. // This can be used to attach additional metadata during rendering. MetaKey string `json:",omitempty"` // Pointers to Parent and Child ID strings. Parent string `json:",omitempty"` Children []string `json:",omitempty"` // contains filtered or unexported fields }
TypeNode holds type information about an element. - TypeNode should be cross-platform and only use basic types.
func (*TypeNode) AddChild ¶ added in v0.0.6
AddChild adds a child element to the current element. - Sets Parent on the child element.
func (*TypeNode) Ancestors ¶ added in v0.0.6
Ancestors returns a slice of all ancestors of the given TypeNode.
func (*TypeNode) ChildByName ¶ added in v0.0.6
ChildByName gets the child with the given element name. - Returns nil if child does not exist.
func (*TypeNode) ChildMap ¶ added in v0.0.6
ChildMap returns a map of Children name --> *TypeNode - Output map can be passed to ChildKeys, ContainsChild, ChildByName for reuse.
func (*TypeNode) ContainsChild ¶ added in v0.0.6
ContainsChild returns true if a child with the given name exist.
func (*TypeNode) Copy ¶ added in v0.0.6
Copy makes a copy of a TypeNode and its Children. - The copied element has no Parent.
func (*TypeNode) GetNativeType ¶ added in v0.0.6
func (t *TypeNode) GetNativeType(dialect string) *NativeType
GetNativeType returns a new NativeType with Name,Type,TypeRef,Include set.
func (*TypeNode) IsBasicType ¶ added in v0.0.6
IsBasicType returns true if the element is a basic type.
func (*TypeNode) IsExported ¶ added in v0.0.6
IsExported returns true if the element Name starts with an uppercase letter.
func (*TypeNode) NativeDefault ¶ added in v0.0.6
func (t *TypeNode) NativeDefault() *NativeType
NativeDefault returns the native element for the NativeDialect.
func (*TypeNode) NewChild ¶ added in v0.0.6
NewChild creates a new type element that is a child of the current one.
func (*TypeNode) Node ¶ added in v0.0.6
Node is a utility wrapper that returns the TypeNode associated with the given ID.
func (*TypeNode) RemoveAllChildren ¶ added in v0.0.6
func (t *TypeNode) RemoveAllChildren()
RemoveAllChildren removes all children from the current element.
func (*TypeNode) RemoveChild ¶ added in v0.0.6
RemoveChild removes the given child from the Children list. - Uses ID for matching. - Sets Parent on child to nil.
func (*TypeNode) RemoveParent ¶ added in v0.0.6
func (t *TypeNode) RemoveParent()
RemoveParent removes the Parent.