go-zero/tools/goctl/api/spec/spec.go

146 lines
2.8 KiB
Go
Raw Normal View History

2020-07-29 17:11:41 +08:00
package spec
type (
// Doc describes document
Doc []string
// Annotation defines key-value
2020-07-29 17:11:41 +08:00
Annotation struct {
Properties map[string]string
}
// ApiSyntax describes the syntax grammar
ApiSyntax struct {
Version string
Doc Doc
Comment Doc
2020-07-29 17:11:41 +08:00
}
// ApiSpec describes a api file
2020-07-29 17:11:41 +08:00
ApiSpec struct {
Info Info
Syntax ApiSyntax
Imports []Import
2020-07-29 17:11:41 +08:00
Types []Type
Service Service
}
// Import describes api import
Import struct {
Value string
Doc Doc
Comment Doc
}
// Group defines a set of routing information
2020-07-29 17:11:41 +08:00
Group struct {
Annotation Annotation
Routes []Route
2020-07-29 17:11:41 +08:00
}
// Info describes info grammar block
2020-07-29 17:11:41 +08:00
Info struct {
// Deprecated: use Properties instead
Title string
// Deprecated: use Properties instead
Desc string
// Deprecated: use Properties instead
2020-07-29 17:11:41 +08:00
Version string
// Deprecated: use Properties instead
Author string
// Deprecated: use Properties instead
Email string
Properties map[string]string
2020-07-29 17:11:41 +08:00
}
// Member describes the field of a structure
2020-07-29 17:11:41 +08:00
Member struct {
Name string
2020-07-29 17:11:41 +08:00
// 数据类型字面值string、map[int]string、[]int64、[]*User
Type Type
Tag string
Comment string
2020-07-29 17:11:41 +08:00
// 成员头顶注释说明
Docs Doc
2020-07-29 17:11:41 +08:00
IsInline bool
}
// Route describes api route
2020-07-29 17:11:41 +08:00
Route struct {
2021-03-04 17:13:07 +08:00
AtServerAnnotation Annotation
Method string
Path string
RequestType Type
ResponseType Type
Docs Doc
Handler string
AtDoc AtDoc
HandlerDoc Doc
HandlerComment Doc
Doc Doc
Comment Doc
2020-07-29 17:11:41 +08:00
}
// Service describes api service
2020-07-29 17:11:41 +08:00
Service struct {
Name string
Groups []Group
2020-07-29 17:11:41 +08:00
}
// Type defines api type
Type interface {
Name() string
Comments() []string
Documents() []string
2020-07-29 17:11:41 +08:00
}
// DefineStruct describes api structure
DefineStruct struct {
RawName string
Members []Member
Docs Doc
2020-07-29 17:11:41 +08:00
}
// PrimitiveType describes the basic golang type, such as bool,int32,int64, ...
PrimitiveType struct {
RawName string
2020-07-29 17:11:41 +08:00
}
// MapType describes a map for api
2020-07-29 17:11:41 +08:00
MapType struct {
RawName string
// only support the PrimitiveType
2020-07-29 17:11:41 +08:00
Key string
// it can be asserted as PrimitiveType: int、bool、
2020-07-29 17:11:41 +08:00
// PointerType: *string、*User、
// MapType: map[${PrimitiveType}]interface、
2020-07-29 17:11:41 +08:00
// ArrayType:[]int、[]User、[]*User
// InterfaceType: interface{}
// Type
Value Type
2020-07-29 17:11:41 +08:00
}
// ArrayType describes a slice for api
2020-07-29 17:11:41 +08:00
ArrayType struct {
RawName string
Value Type
2020-07-29 17:11:41 +08:00
}
// InterfaceType describes a interface for api
2020-07-29 17:11:41 +08:00
InterfaceType struct {
RawName string
2020-07-29 17:11:41 +08:00
}
// PointerType describes a pointer for api
PointerType struct {
RawName string
Type Type
2020-07-29 17:11:41 +08:00
}
// AtDoc describes a metadata for api grammar: @doc(...)
AtDoc struct {
Properties map[string]string
Text string
}
2020-07-29 17:11:41 +08:00
)