schema

package
v0.0.0-...-a7b288f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefinePrimitiveTypeClass

func DefinePrimitiveTypeClass(goKind reflect.Kind, terminusClass string)

func DefineTypeClass

func DefineTypeClass(goType reflect.Type, terminusClass string, toSchemaConverter ComplexTypeConverterFunc)

func GetSchemaClass

func GetSchemaClass(typ reflect.Type) (string, bool)

func SerializeObject

func SerializeObject(buf map[string]any, object any, mapCallback FieldSerializeMapCallback) error

Types

type AbstractModel

type AbstractModel struct{} // TODO: implement

type Class

type Class struct {
	ID            string                   `mapstructure:"@id"`
	Key           ClassKey                 `mapstructure:"@key"`
	Documentation []ClassDocumentationType `mapstructure:"@documentation,omitempty"`
	Base          string                   `mapstructure:"@base"`
	Inherits      []string                 `mapstructure:"-"`
	Fields        map[string]Field         `mapstructure:"-"`
	SubDocument   bool                     `mapstructure:"-"`
	Abstract      bool                     `mapstructure:"-"`
}

func (*Class) Deserialize

func (c *Class) Deserialize(m RawSchemaItem) error

func (*Class) FromObject

func (c *Class) FromObject(obj any)

func (*Class) MarshalJSON

func (c *Class) MarshalJSON() ([]byte, error)

func (*Class) Name

func (c *Class) Name() string

func (*Class) Serialize

func (c *Class) Serialize(buf RawSchemaItem) error

func (*Class) Type

func (c *Class) Type() ItemType

func (*Class) UnmarshalJSON

func (c *Class) UnmarshalJSON(bytes []byte) error

type ClassDocumentationPropertiesItem

type ClassDocumentationPropertiesItem struct {
	Label   string `json:"@label"`
	Comment string `json:"@comment"`
}

type ClassDocumentationType

type ClassDocumentationType struct {
	Language   string                                      `json:"@language,omitempty"`
	Label      string                                      `json:"@label"`
	Comment    string                                      `json:"@comment"`
	Properties map[string]ClassDocumentationPropertiesItem `json:"@properties,omitempty"`
	Values     map[string]string                           `json:"@values,omitempty"`
}

type ClassKey

type ClassKey struct {
	Type   ClassKeyType `mapstructure:"@type"`
	Fields []string     `mapstructure:"@fields,omitempty"`
}

type ClassKeyType

type ClassKeyType string
const (
	ClassKeyRandom    ClassKeyType = "Random"
	ClassKeyLexical   ClassKeyType = "Lexical"
	ClassKeyHash      ClassKeyType = "Hash"
	ClassKeyValueHash ClassKeyType = "ValueHash"
)

type ComplexTypeConverterFunc

type ComplexTypeConverterFunc func(any) any

func GetConverter

func GetConverter(typ reflect.Type) (ComplexTypeConverterFunc, bool)

type Context

type Context struct {
	Schema        string                `json:"@schema" mapstructure:"@schema"`
	Base          string                `json:"@base" mapstructure:"@base"`
	Documentation *ContextDocumentation `json:"@documentation,omitempty" mapstructure:"@documentation,omitempty"`
}

func (*Context) Deserialize

func (c *Context) Deserialize(m RawSchemaItem) error

func (*Context) Serialize

func (c *Context) Serialize(buf RawSchemaItem) error

func (*Context) Type

func (c *Context) Type() ItemType

type ContextDocumentation

type ContextDocumentation struct {
	Title       string   `json:"@title"`
	Description string   `json:"@description"`
	Authors     []string `json:"@authors"`
}

type Enum

type Enum struct {
	ID    string   `mapstructure:"@id"`
	Value []string `mapstructure:"@value"`
}

func (*Enum) Deserialize

func (e *Enum) Deserialize(m RawSchemaItem) error

func (*Enum) FromValue

func (e *Enum) FromValue(name string, enumValues []string)

func (*Enum) MarshalJSON

func (e *Enum) MarshalJSON() ([]byte, error)

func (*Enum) Name

func (e *Enum) Name() string

func (*Enum) Serialize

func (e *Enum) Serialize(buf RawSchemaItem) error

func (*Enum) Type

func (e *Enum) Type() ItemType

func (*Enum) UnmarshalJSON

func (e *Enum) UnmarshalJSON(bytes []byte) error

type Field

type Field struct {
	Type           FieldType `json:"@type,omitempty"`
	Class          string    `json:"@class,omitempty"`           // For all types except Foreign
	ID             string    `json:"@id,omitempty"`              // For Foreign type
	Cardinality    uint      `json:"@cardinality,omitempty"`     // For Set type
	MinCardinality uint      `json:"@min_cardinality,omitempty"` // For Set type
	MaxCardinality uint      `json:"@max_cardinality,omitempty"` // For Set type
	Dimensions     uint      `json:"@dimensions,omitempty"`      // For Array type

	Tags map[string]string `json:"-" mapstructure:"-"`
}

type FieldSerializeMapCallback

type FieldSerializeMapCallback func(field reflect.StructField, name string, typeName string, value any) any

type FieldType

type FieldType string
const (
	FieldTypeOptional FieldType = "Optional"
	FieldTypeList     FieldType = "List"
	FieldTypeArray    FieldType = "Array"
	FieldTypeForeign  FieldType = "Foreign"
	FieldTypeSet      FieldType = "Set"
)

type IdentityKeeper

type IdentityKeeper interface {
	Type() ItemType
	Name() string
}

type ItemType

type ItemType string
const (
	ClassSchemaItem       ItemType = "Class"
	EnumSchemaItem        ItemType = "Enum"
	TaggedUnionSchemaItem ItemType = "TaggedUnion"
	UnitSchemaItem        ItemType = "Unit"    // TODO: implement
	ContextSchemaItem     ItemType = "context" // Ad-hoc type, not used in real schema
)

type RawSchemaItem

type RawSchemaItem map[string]any

func (RawSchemaItem) ToSchemaItem

func (rsi RawSchemaItem) ToSchemaItem(schemaItemBuf Serializable) error

func (RawSchemaItem) Type

func (rsi RawSchemaItem) Type() (ItemType, error)

type Schema

type Schema struct {
	Context     Context
	SchemaItems []Serializable
}

func (*Schema) Deserialize

func (s *Schema) Deserialize(items []RawSchemaItem) error

func (*Schema) FindEnum

func (s *Schema) FindEnum(name string) int

func (*Schema) FindModel

func (s *Schema) FindModel(model any) int

func (*Schema) MarshalJSON

func (s *Schema) MarshalJSON() ([]byte, error)

func (*Schema) Serialize

func (s *Schema) Serialize(buf []RawSchemaItem) error

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(bytes []byte) error

type Serializable

type Serializable interface {
	Deserialize(RawSchemaItem) error
	Serialize(RawSchemaItem) error // FIXME: maybe make parameter as pointer?
}

type SubDocumentModel

type SubDocumentModel struct{}

type TaggedUnion

type TaggedUnion struct {
	ID            string                   `mapstructure:"@id"`
	Key           ClassKey                 `mapstructure:"@key"`
	Documentation []ClassDocumentationType `mapstructure:"@documentation,omitempty"` // TODO: implement -- how to describe in object
	Base          string                   `mapstructure:"@base"`
	Fields        map[string]Field         `mapstructure:"-"`
}

func (*TaggedUnion) Deserialize

func (t *TaggedUnion) Deserialize(m RawSchemaItem) error

func (*TaggedUnion) FromObject

func (t *TaggedUnion) FromObject(obj any)

func (*TaggedUnion) MarshalJSON

func (t *TaggedUnion) MarshalJSON() ([]byte, error)

func (*TaggedUnion) Name

func (t *TaggedUnion) Name() string

func (*TaggedUnion) Serialize

func (t *TaggedUnion) Serialize(buf RawSchemaItem) error

func (*TaggedUnion) Type

func (t *TaggedUnion) Type() ItemType

func (*TaggedUnion) UnmarshalJSON

func (t *TaggedUnion) UnmarshalJSON(bytes []byte) error

type TaggedUnionModel

type TaggedUnionModel struct{}

Jump to

Keyboard shortcuts

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