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 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) CopyWithoutNative() *TypeNode
- func (t *TypeNode) GetName(dialect string) string
- func (t *TypeNode) GetNativeType(dialect string) *NativeType
- func (t *TypeNode) IsBasicType() bool
- func (t *TypeNode) IsExported() bool
- func (t *TypeNode) MapKey() string
- func (t *TypeNode) NativeDefault() *NativeType
- func (t *TypeNode) NewChild(name 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.
const ( ROOT_NAME = "Root" TYPEREF_NAME = "TypeRef" )
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 Schema ¶
type Schema struct { // Root is the node ID of the root of types in the order found. Root *TypeNode // TypeRef is the node ID that holds a map of named types by name. TypeRef *TypeNode }
Schema is the result of parsing types.
func (*Schema) CopyWithoutNative ¶ added in v0.0.10
CopyWithoutNative removes all native dialects for the minimal schema.
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 { // 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. 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 `json:",omitempty"` // 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 *TypeNode `json:"-"` Children []*TypeNode `json:",omitempty"` }
TypeNode holds type information about an element. - TypeNode should be cross-platform and only use basic types.
func NewRootNode ¶ added in v0.0.10
NewRootNode creates a new type element that is a root of a tree.
func NewTypeNode ¶ added in v0.0.10
NewTypeNode returns a new TypeNode in the current NodePool.
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) CopyWithoutNative ¶ added in v0.0.10
CopyWithoutNative makes a copy of a TypeNode and its Children without Native types. - 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) MapKey ¶ added in v0.0.7
MapKey returns a key for a TypeNode as the first, non-empty value of: - Name - MetaKey - ID
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) 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.