types

package
v0.0.0-...-f260a3c Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindImport

func FindImport(file ast.File, alias string) (string, *ast.ImportSpec)

func GetFieldTypeFormat

func GetFieldTypeFormat(t string) string

Types

type ArrayType

type ArrayType struct {
	ItemType  Type
	ArrayType *ast.ArrayType
	// contains filtered or unexported fields
}

func NewArray

func NewArray(file *ast.File, name string, array *ast.ArrayType, innerType ast.Expr, tag *ast.BasicLit) ArrayType

func NewSimpleArrayType

func NewSimpleArrayType(name string, itemType Type) ArrayType

func (ArrayType) AddMethod

func (tb ArrayType) AddMethod(f FuncType)

func (ArrayType) EqualTo

func (a ArrayType) EqualTo(t Type) bool

func (ArrayType) Field

func (tb ArrayType) Field(name string) Type

func (ArrayType) Fields

func (tb ArrayType) Fields() map[string]Type

func (ArrayType) File

func (tb ArrayType) File() *ast.File

func (ArrayType) GetDescription

func (tb ArrayType) GetDescription() string

func (ArrayType) Implements

func (tb ArrayType) Implements(it InterfaceType) bool

func (ArrayType) MarshalJSON

func (a ArrayType) MarshalJSON() ([]byte, error)

func (ArrayType) Method

func (tb ArrayType) Method(name string) *FuncType

func (ArrayType) Methods

func (tb ArrayType) Methods() map[string]Type

func (ArrayType) Name

func (tb ArrayType) Name() string

func (ArrayType) SchemaType

func (tb ArrayType) SchemaType() SchemaType

func (ArrayType) SetDescription

func (tb ArrayType) SetDescription(desc string)

func (ArrayType) Tag

func (tb ArrayType) Tag(name string) string

type BasicType

type BasicType struct {
	Value string
	Ident *ast.Ident

	Format string `json:"format,omitempty"`
	// contains filtered or unexported fields
}

func NewBasicFromBasicLit

func NewBasicFromBasicLit(file *ast.File, name string, basic, tag *ast.BasicLit) BasicType

func NewSimpleBasicType

func NewSimpleBasicType(name SchemaType) BasicType

func (BasicType) AddMethod

func (tb BasicType) AddMethod(f FuncType)

func (BasicType) EqualTo

func (o BasicType) EqualTo(t Type) bool

func (BasicType) Field

func (tb BasicType) Field(name string) Type

func (BasicType) Fields

func (tb BasicType) Fields() map[string]Type

func (BasicType) File

func (tb BasicType) File() *ast.File

func (BasicType) GetDescription

func (tb BasicType) GetDescription() string

func (BasicType) Implements

func (tb BasicType) Implements(it InterfaceType) bool

func (BasicType) MarshalJSON

func (o BasicType) MarshalJSON() ([]byte, error)

func (BasicType) Method

func (tb BasicType) Method(name string) *FuncType

func (BasicType) Methods

func (tb BasicType) Methods() map[string]Type

func (BasicType) Name

func (tb BasicType) Name() string

func (BasicType) SchemaType

func (tb BasicType) SchemaType() SchemaType

func (BasicType) SetDescription

func (tb BasicType) SetDescription(desc string)

func (BasicType) Tag

func (tb BasicType) Tag(name string) string

type Call

type Call struct {
	Call       Type
	Parameters []Type
	// contains filtered or unexported fields
}

func NewCall

func NewCall(file *ast.File, name string, decl *ast.CallExpr, tag *ast.BasicLit) Call

func (Call) AddMethod

func (tb Call) AddMethod(f FuncType)

func (Call) Decl

func (call Call) Decl() *ast.CallExpr

func (Call) EqualTo

func (tb Call) EqualTo(t Type) bool

func (Call) Field

func (tb Call) Field(name string) Type

func (Call) Fields

func (tb Call) Fields() map[string]Type

func (Call) File

func (tb Call) File() *ast.File

func (Call) GetDescription

func (tb Call) GetDescription() string

func (Call) Implements

func (tb Call) Implements(it InterfaceType) bool

func (Call) MarshalJSON

func (tb Call) MarshalJSON() ([]byte, error)

func (Call) Method

func (tb Call) Method(name string) *FuncType

func (Call) Methods

func (tb Call) Methods() map[string]Type

func (Call) Name

func (tb Call) Name() string

func (Call) SchemaType

func (tb Call) SchemaType() SchemaType

func (Call) SetDescription

func (tb Call) SetDescription(desc string)

func (Call) Tag

func (tb Call) Tag(name string) string

type Components

type Components struct {
	Schemas       map[string]Type        `json:"schemas,omitempty"`
	Parameters    map[string]IParameter  `json:"parameters,omitempty"`
	RequestBodies map[string]RequestBody `json:"requestBodies,omitempty"`
	Responses     map[string]Response    `json:"responses,omitempty"`
	// contains filtered or unexported fields
}

func NewComponents

func NewComponents() Components

func (*Components) Add

func (c *Components) Add(comp Components)

type Content

type Content struct {
	Schema Reference `json:"schema"`
}

type FuncType

type FuncType struct {
	Parameters []Type
	Results    []Type
	Statements []interface{}

	Body []ast.Stmt
	// contains filtered or unexported fields
}

func NewFunc

func NewFunc(file *ast.File, name string, decl *ast.FuncType, body []ast.Stmt, tag *ast.BasicLit) FuncType

func NewFuncDeclaration

func NewFuncDeclaration(name string, params []Type, results []Type) FuncType

func NewMethodFromField

func NewMethodFromField(file *ast.File, field *ast.Field) (string, *FuncType)

func (FuncType) AddMethod

func (FuncType) AddMethod(FuncType)

func (FuncType) EqualTo

func (f FuncType) EqualTo(t Type) bool

func (FuncType) Field

func (tb FuncType) Field(name string) Type

func (FuncType) Fields

func (tb FuncType) Fields() map[string]Type

func (FuncType) File

func (tb FuncType) File() *ast.File

func (FuncType) GetBody

func (f FuncType) GetBody() []Statement

func (FuncType) GetDescription

func (tb FuncType) GetDescription() string

func (FuncType) Implements

func (f FuncType) Implements(it InterfaceType) bool

func (FuncType) MarshalJSON

func (tb FuncType) MarshalJSON() ([]byte, error)

func (FuncType) Method

func (tb FuncType) Method(name string) *FuncType

func (FuncType) Methods

func (tb FuncType) Methods() map[string]Type

func (FuncType) Name

func (tb FuncType) Name() string

func (FuncType) ReturnStatements

func (f FuncType) ReturnStatements() []ast.ReturnStmt

func (FuncType) SchemaType

func (tb FuncType) SchemaType() SchemaType

func (FuncType) SetDescription

func (tb FuncType) SetDescription(desc string)

func (FuncType) Tag

func (tb FuncType) Tag(name string) string

type IParameter

type IParameter interface {
	NameParam() string
	Type() string
	EqualTo(interface{}) bool
}

type ImportedType

type ImportedType struct {
	Package string
	// contains filtered or unexported fields
}

func NewImported

func NewImported(file *ast.File, selector *ast.SelectorExpr, tag *ast.BasicLit) ImportedType

func NewSimpleImported

func NewSimpleImported(name, path string) ImportedType

func (ImportedType) AddMethod

func (i ImportedType) AddMethod(FuncType)

func (ImportedType) EqualTo

func (i ImportedType) EqualTo(t Type) bool

func (ImportedType) Field

func (i ImportedType) Field(name string) Type

func (ImportedType) Fields

func (i ImportedType) Fields() map[string]Type

func (ImportedType) File

func (tb ImportedType) File() *ast.File

func (ImportedType) GetDescription

func (tb ImportedType) GetDescription() string

func (ImportedType) Implements

func (tb ImportedType) Implements(it InterfaceType) bool

func (ImportedType) IsWebAPI

func (i ImportedType) IsWebAPI() bool

func (ImportedType) MarshalJSON

func (tb ImportedType) MarshalJSON() ([]byte, error)

func (ImportedType) Method

func (i ImportedType) Method(name string) *FuncType

func (ImportedType) Methods

func (tb ImportedType) Methods() map[string]Type

func (ImportedType) Name

func (tb ImportedType) Name() string

func (ImportedType) SchemaType

func (tb ImportedType) SchemaType() SchemaType

func (ImportedType) Selector

func (i ImportedType) Selector() *ast.SelectorExpr

func (ImportedType) SetDescription

func (tb ImportedType) SetDescription(desc string)

func (ImportedType) Tag

func (tb ImportedType) Tag(name string) string

type Info

type Info struct {
	Title   string `json:"title"`
	Version string `json:"version"`
}

type InterfaceType

type InterfaceType struct {
	// contains filtered or unexported fields
}

func NewInterface

func NewInterface(file *ast.File, name string, interf *ast.InterfaceType, tag *ast.BasicLit) InterfaceType

func NewInterfaceFields

func NewInterfaceFields(fields map[string]Type) InterfaceType

func RoutersFuncInterface

func RoutersFuncInterface() InterfaceType

func RoutersInterface

func RoutersInterface() InterfaceType

func (InterfaceType) AddMethod

func (tb InterfaceType) AddMethod(f FuncType)

func (InterfaceType) EqualTo

func (tb InterfaceType) EqualTo(t Type) bool

func (InterfaceType) Field

func (tb InterfaceType) Field(name string) Type

func (InterfaceType) Fields

func (tb InterfaceType) Fields() map[string]Type

func (InterfaceType) File

func (tb InterfaceType) File() *ast.File

func (InterfaceType) GetDescription

func (tb InterfaceType) GetDescription() string

func (InterfaceType) Implements

func (tb InterfaceType) Implements(it InterfaceType) bool

func (InterfaceType) MarshalJSON

func (tb InterfaceType) MarshalJSON() ([]byte, error)

func (InterfaceType) Method

func (tb InterfaceType) Method(name string) *FuncType

func (InterfaceType) Methods

func (tb InterfaceType) Methods() map[string]Type

func (InterfaceType) Name

func (tb InterfaceType) Name() string

func (InterfaceType) SchemaType

func (tb InterfaceType) SchemaType() SchemaType

func (InterfaceType) SetDescription

func (tb InterfaceType) SetDescription(desc string)

func (InterfaceType) Tag

func (tb InterfaceType) Tag(name string) string

type MapType

type MapType struct {
	Key   Type
	Value Type
	// contains filtered or unexported fields
}

func NewMap

func NewMap(file *ast.File, name string, str *ast.MapType, tag *ast.BasicLit) MapType

func NewSimpleMap

func NewSimpleMap(name string, key Type, value Type) MapType

func (MapType) AddMethod

func (tb MapType) AddMethod(f FuncType)

func (MapType) EqualTo

func (m MapType) EqualTo(t Type) bool

func (MapType) Field

func (tb MapType) Field(name string) Type

func (MapType) Fields

func (tb MapType) Fields() map[string]Type

func (MapType) File

func (tb MapType) File() *ast.File

func (MapType) GetDescription

func (tb MapType) GetDescription() string

func (MapType) Implements

func (tb MapType) Implements(it InterfaceType) bool

func (MapType) MarshalJSON

func (tb MapType) MarshalJSON() ([]byte, error)

func (MapType) Method

func (tb MapType) Method(name string) *FuncType

func (MapType) Methods

func (tb MapType) Methods() map[string]Type

func (MapType) Name

func (tb MapType) Name() string

func (MapType) SchemaType

func (tb MapType) SchemaType() SchemaType

func (MapType) SetDescription

func (tb MapType) SetDescription(desc string)

func (MapType) Tag

func (tb MapType) Tag(name string) string

type OpenAPISpec

type OpenAPISpec struct {
	Openapi    string                      `json:"openapi"`
	Info       Info                        `json:"info"`
	Servers    []ServerInfo                `json:"servers"`
	Components Components                  `json:"components"`
	Paths      map[string]map[string]Route `json:"paths"`
}

func NewOpenAPISpec

func NewOpenAPISpec(servers ...ServerInfo) *OpenAPISpec

type ParameterOptionHandler

type ParameterOptionHandler func(Type, Call) error

type Reference

type Reference struct {
	Ref string `json:"$ref"`
	// contains filtered or unexported fields
}

func NewReference

func NewReference(name, where string) *Reference

func (Reference) EqualTo

func (r Reference) EqualTo(ref interface{}) bool

func (Reference) NameParam

func (r Reference) NameParam() string

func (Reference) Type

func (Reference) Type() string

type RequestBody

type RequestBody struct {
	Description string             `json:"description,omitempty"`
	Required    bool               `json:"required,omitempty"`
	Content     map[string]Content `json:"content"`
}

func NewRequestBody

func NewRequestBody(ref Reference) RequestBody

type Response

type Response struct {
	Description string             `json:"description"`
	Content     map[string]Content `json:"content,omitempty"`
}

func NewErrorResponse

func NewErrorResponse(desc string, refs ...Reference) *Response

func NewResponse

func NewResponse(desc string, refs ...Reference) *Response

type Route

type Route struct {
	Summary     string             `json:"summary,omitempty"`
	Tags        []string           `json:"tags,omitempty"`
	Parameters  []IParameter       `json:"parameters,omitempty"`
	RequestBody *Reference         `json:"requestBody,omitempty"`
	Responses   map[int]*Reference `json:"responses"`
	Description string             `json:"description,omitempty"`
}

func NewRoute

func NewRoute(tags ...string) *Route

type RouteOptionHanlder

type RouteOptionHanlder func(*Route, Call) error

type SchemaType

type SchemaType string
const (
	EmptySchemaType   SchemaType = ""
	ArraySchemaType   SchemaType = "array"
	NumberSchemaType  SchemaType = "number"
	ObjectSchemaType  SchemaType = "object"
	StringSchemaType  SchemaType = "string"
	IntegerSchemaType SchemaType = "integer"
	BooleanSchemaType SchemaType = "boolean"
)

func ConvertFieldType

func ConvertFieldType(t string) SchemaType

type ServerInfo

type ServerInfo struct {
	URL         string `json:"url"`
	Description string `json:"description"`
}

type Statement

type Statement interface{}

type StringType

type StringType struct {
	Data  string
	Basic *ast.BasicLit
	// contains filtered or unexported fields
}

func NewString

func NewString(basic *ast.BasicLit) StringType

func (StringType) AddMethod

func (tb StringType) AddMethod(f FuncType)

func (StringType) EqualTo

func (s StringType) EqualTo(sch Type) bool

func (StringType) Field

func (tb StringType) Field(name string) Type

func (StringType) Fields

func (tb StringType) Fields() map[string]Type

func (StringType) File

func (tb StringType) File() *ast.File

func (StringType) GetDescription

func (tb StringType) GetDescription() string

func (StringType) Implements

func (tb StringType) Implements(it InterfaceType) bool

func (StringType) MarshalJSON

func (tb StringType) MarshalJSON() ([]byte, error)

func (StringType) Method

func (tb StringType) Method(name string) *FuncType

func (StringType) Methods

func (tb StringType) Methods() map[string]Type

func (StringType) Name

func (s StringType) Name() string

func (StringType) SchemaType

func (tb StringType) SchemaType() SchemaType

func (StringType) SetDescription

func (tb StringType) SetDescription(desc string)

func (StringType) Tag

func (tb StringType) Tag(name string) string

type StructType

type StructType struct {
	StructType *ast.StructType

	// *BaseSchema
	Properties map[string]Type `json:"properties,omitempty"`
	// contains filtered or unexported fields
}

func NewStruct

func NewStruct(file *ast.File, name string, str *ast.StructType, tag *ast.BasicLit) StructType

func (StructType) AddMethod

func (tb StructType) AddMethod(f FuncType)

func (StructType) EqualSchema

func (o StructType) EqualSchema(s Type) bool

func (StructType) EqualTo

func (tb StructType) EqualTo(t Type) bool

func (StructType) Field

func (tb StructType) Field(name string) Type

func (StructType) Fields

func (tb StructType) Fields() map[string]Type

func (StructType) File

func (tb StructType) File() *ast.File

func (StructType) GetDescription

func (tb StructType) GetDescription() string

func (StructType) Implements

func (tb StructType) Implements(it InterfaceType) bool

func (StructType) MarshalJSON

func (o StructType) MarshalJSON() ([]byte, error)

func (StructType) Method

func (tb StructType) Method(name string) *FuncType

func (StructType) Methods

func (tb StructType) Methods() map[string]Type

func (StructType) Name

func (tb StructType) Name() string

func (StructType) SchemaType

func (tb StructType) SchemaType() SchemaType

func (StructType) SetDescription

func (tb StructType) SetDescription(desc string)

func (StructType) Tag

func (tb StructType) Tag(name string) string

type Type

type Type interface {
	Name() string
	Tag(string) string
	AddMethod(FuncType)
	Field(string) Type
	Method(string) *FuncType
	Fields() map[string]Type
	File() *ast.File
	GetDescription() string
	SetDescription(string)

	EqualTo(t Type) bool
	Implements(InterfaceType) bool
	SchemaType() SchemaType
}

func NewBasic

func NewBasic(file *ast.File, name string, ident *ast.Ident, tag *ast.BasicLit) Type

func NewFromObject

func NewFromObject(file *ast.File, name string, obj *ast.Object, tag *ast.BasicLit) Type

func NewType

func NewType(file *ast.File, name string, ts ast.Expr, tag *ast.BasicLit) Type

TODO: review params

func NewTypeFromField

func NewTypeFromField(file *ast.File, field *ast.Field) (string, Type)

func RoutersFunc

func RoutersFunc() Type

Jump to

Keyboard shortcuts

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