schema

package
v1.0.0-beta.122 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType               = fmt.Errorf("invalid type. expected string or array of strings")
	ErrOnlyOneNonNullTypeAllowed = fmt.Errorf("only one non-null type allowed for the field")
)
View Source
var (
	ErrUnsupportedFormat = fmt.Errorf("unsupported format. supported formats are: JSON, TypeScripts, Go, Java")
	ErrEmptyObjectName   = fmt.Errorf("object name should be non-zero length")
)
View Source
var ErrUnsupportedType = fmt.Errorf("unsupported type")

Functions

func GenCollectionSchema

func GenCollectionSchema(jsonSchema []byte, lang string) ([]byte, error)

Types

type Collection

type Collection struct {
	Name      string
	NameDecap string
	JSON      string
}

type Field

type Field struct {
	Type   FieldMultiType    `json:"type,omitempty"`
	Format string            `json:"format,omitempty"`
	Tags   []string          `json:"tags,omitempty"`
	Desc   string            `json:"description,omitempty"`
	Fields map[string]*Field `json:"properties,omitempty"`
	Items  *Field            `json:"items,omitempty"`

	Default      any  `json:"default,omitempty"`
	MaxLength    int  `json:"maxLength,omitempty"`
	CreatedAt    bool `json:"createdAt,omitempty"`
	UpdatedAt    bool `json:"updatedAt,omitempty"`
	AutoGenerate bool `json:"autoGenerate,omitempty"`

	Required []string `json:"required,omitempty"`

	SearchIndex bool `json:"searchIndex,omitempty"`
	Facet       bool `json:"facet,omitempty"`
	Sort        bool `json:"sort,omitempty"`

	// RequiredTag is used during schema building only
	RequiredTag bool `json:"-"`
}

Field represents JSON schema object.

type FieldGen

type FieldGen struct {
	Type      string
	TypeDecap string

	Name       string
	NameDecap  string
	NameSnake  string
	NameJSON   string
	NamePlural string
	JSONCap    string

	IsArray  bool
	IsObject bool

	AutoGenerate    bool
	PrimaryKeyIdx   int
	ArrayDimensions int

	Default                any
	DefaultStr             string
	DefaultStrSingleQuotes string

	MaxLength int
	UpdatedAt bool
	CreatedAt bool
	Required  bool

	SearchIndex bool
	Facet       bool
	Sort        bool

	Nullable      bool
	ItemsNullable bool

	Description string
}

type FieldMultiType

type FieldMultiType struct {
	Type []string
	// contains filtered or unexported fields
}

func NewArrayType

func NewArrayType() FieldMultiType

func NewBooleanType

func NewBooleanType() FieldMultiType

func NewFloatType

func NewFloatType() FieldMultiType

func NewIntegerType

func NewIntegerType() FieldMultiType

func NewMultiType

func NewMultiType(val string) FieldMultiType

func NewNullableMultiType

func NewNullableMultiType(val string) FieldMultiType

func NewObjectType

func NewObjectType() FieldMultiType

func NewStringType

func NewStringType() FieldMultiType

func (*FieldMultiType) First

func (f *FieldMultiType) First() string

func (*FieldMultiType) MarshalJSON

func (f *FieldMultiType) MarshalJSON() ([]byte, error)

func (*FieldMultiType) Set

func (f *FieldMultiType) Set(tp string)

func (*FieldMultiType) SetNullable

func (f *FieldMultiType) SetNullable()

func (*FieldMultiType) UnmarshalJSON

func (f *FieldMultiType) UnmarshalJSON(b []byte) error

type JSONToGo

type JSONToGo struct{}

func (*JSONToGo) GetObjectTemplate

func (*JSONToGo) GetObjectTemplate() string

func (*JSONToGo) GetType

func (*JSONToGo) GetType(tp string, format string) (string, error)

type JSONToJava

type JSONToJava struct{}

func (*JSONToJava) GetObjectTemplate

func (*JSONToJava) GetObjectTemplate() string

func (*JSONToJava) GetType

func (*JSONToJava) GetType(tp string, format string) (string, error)

type JSONToLangType

type JSONToLangType interface {
	GetType(string, string) (string, error)
	GetObjectTemplate() string
}

type JSONToTypeScript

type JSONToTypeScript struct{}

func (*JSONToTypeScript) GetObjectTemplate

func (*JSONToTypeScript) GetObjectTemplate() string

func (*JSONToTypeScript) GetType

func (*JSONToTypeScript) GetType(tp string, format string) (string, error)

type Object

type Object struct {
	Name      string
	NameDecap string
	NameSnake string
	NameJSON  string

	NamePlural string

	Description string

	Nested bool

	Fields []FieldGen
}

type Schema

type Schema struct {
	Name   string            `json:"title,omitempty"`
	Desc   string            `json:"description,omitempty"`
	Fields map[string]*Field `json:"properties,omitempty"`

	PrimaryKey []string `json:"primary_key,omitempty"`
	Required   []string `json:"required,omitempty"`

	CollectionType string `json:"collection_type,omitempty"`
}

Schema is top level JSON schema object.

Jump to

Keyboard shortcuts

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