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 PathList
- type Schema
- type StructFieldTag
- type Tags
- type TypeElement
- func (t *TypeElement) AddChild(childElem *TypeElement)
- func (t *TypeElement) Ancestors() []*TypeElement
- func (t *TypeElement) ChildByName(name string, m map[string]*TypeElement) *TypeElement
- func (t *TypeElement) ChildKeys(m map[string]*TypeElement) []string
- func (t *TypeElement) ChildMap() map[string]*TypeElement
- func (t *TypeElement) ContainsChild(name string, m map[string]*TypeElement) bool
- func (t *TypeElement) Copy() *TypeElement
- func (t *TypeElement) GetName(lang string) string
- func (t *TypeElement) GetNativeType(dialect string) *NativeType
- func (t *TypeElement) IsBasicType() bool
- func (t *TypeElement) IsExported() bool
- func (t *TypeElement) NativeDefault() *NativeType
- func (t *TypeElement) NewChild(name string) *TypeElement
- func (t *TypeElement) ParentID() int
- func (t *TypeElement) RemoveAllChildren()
- func (t *TypeElement) RemoveChild(childElem *TypeElement)
- func (t *TypeElement) SetName(dialect, alias string)
- type TypeList
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 // Native type of element if different from the generic Type. Type string // TypeRef holds the native name of a type if different from the generic TypeRef. TypeRef string // 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 }
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 PathList ¶
type PathList struct {
// contains filtered or unexported fields
}
PathList keeps a list of path string elements that form a unique identifier for a TypeElement. - PathList behaves like a stack with Push/Pop operators.
func NewPathList ¶
func NewPathList() *PathList
type Schema ¶
type Schema struct { // Root is a list of types in the order found. Root *TypeElement // TypeRefs holds a map of named types by name. TypeRefs *TypeElement }
Schema is the result of parsing types.
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 alwyas 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 TypeElement ¶
type TypeElement struct { // Unique identifier for an element. ID int `json:"-"` // 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 `json:"-"` Type string `json:",omitempty"` // 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:"-"` // Native type features by dialect name. Native map[string]*NativeType `json:"-"` // Capture error if element cannot reflect. Error string `json:",omitempty"` // Pointers to Parent and Children. Parent *TypeElement `json:"-"` Children []*TypeElement `json:",omitempty"` }
TypeElement holds type information about an element. - TypeElement should be cross-platform and only use basic types.
func NewRootElement ¶
func NewRootElement(name, dialect string) *TypeElement
NewRootElement creates a new type element that is a root of a tree. - Root elements do not have parents and do not produce output.
func NewTypeElement ¶
func NewTypeElement(name, dialect string) *TypeElement
NewTypeElement creates a new type element without a Parent or Children.
func (*TypeElement) AddChild ¶
func (t *TypeElement) AddChild(childElem *TypeElement)
AddChild adds a child element to the current element. - Sets Parent on the child element.
func (*TypeElement) Ancestors ¶
func (t *TypeElement) Ancestors() []*TypeElement
Ancestors returns a slice of all ancestors of the given TypeElement.
func (*TypeElement) ChildByName ¶
func (t *TypeElement) ChildByName(name string, m map[string]*TypeElement) *TypeElement
ChildByName gets the child with the given element name. - Returns nil if child does not exist.
func (*TypeElement) ChildKeys ¶
func (t *TypeElement) ChildKeys(m map[string]*TypeElement) []string
ChildKeys returns a sorted list of child names.
func (*TypeElement) ChildMap ¶
func (t *TypeElement) ChildMap() map[string]*TypeElement
ChildMap returns a map of Children name --> *TypeElement - Output map can be passed to ChildKeys, ContainsChild, ChildByName for reuse.
func (*TypeElement) ContainsChild ¶
func (t *TypeElement) ContainsChild(name string, m map[string]*TypeElement) bool
ContainsChild returns true if a child with the given name exist.
func (*TypeElement) Copy ¶
func (t *TypeElement) Copy() *TypeElement
Copy makes a copy of a TypeElement and its Children. - The copied element has no Parent.
func (*TypeElement) GetName ¶
func (t *TypeElement) GetName(lang string) string
GetName returns the alias for the given lang or Name.
func (*TypeElement) GetNativeType ¶
func (t *TypeElement) GetNativeType(dialect string) *NativeType
GetNativeType returns a new NativeType with Name,Type,TypeRef,Include set.
func (*TypeElement) IsBasicType ¶
func (t *TypeElement) IsBasicType() bool
IsBasicType returns true if the element is a basic type.
func (*TypeElement) IsExported ¶
func (t *TypeElement) IsExported() bool
IsExported returns true if the element Name starts with an uppercase letter.
func (*TypeElement) NativeDefault ¶
func (t *TypeElement) NativeDefault() *NativeType
NativeDefault returns the native element for the NativeDialect.
func (*TypeElement) NewChild ¶
func (t *TypeElement) NewChild(name string) *TypeElement
NewChild creates a new type element that is a child of the current one.
func (*TypeElement) ParentID ¶
func (t *TypeElement) ParentID() int
ParentID returns the ID of the parent of the current element.
func (*TypeElement) RemoveAllChildren ¶
func (t *TypeElement) RemoveAllChildren()
RemoveAllChildren removes all children from the current element.
func (*TypeElement) RemoveChild ¶
func (t *TypeElement) RemoveChild(childElem *TypeElement)
RemoveChild removes the given child from the Children list. - Uses ID for matching. - Sets Parent on child to nil.
func (*TypeElement) SetName ¶
func (t *TypeElement) SetName(dialect, alias string)
SetName sets the GetName for the native dialect.
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 ¶
func (typeList *TypeList) Copy(parentElem *TypeElement) *TypeList
Copy makes a copy of the current TypeList. - Parent is set if parentElem is not nil.
func (*TypeList) Elements ¶
func (typeList *TypeList) Elements() []*TypeElement
Elements returns the internal slice of TypeElements.
func (*TypeList) Pop ¶
func (typeList *TypeList) Pop() *TypeElement
Pop removes the last element from the list an returns it. - Returns nil is list is empty.
func (*TypeList) Push ¶
func (typeList *TypeList) Push(elem *TypeElement)
Push adds an element to the list.