schema

package
v1.0.0-beta.38 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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   string            `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"`

	// 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

	Description string
}

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 (c *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 (c *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