apigen/lib/types.go

115 lines
2.8 KiB
Go
Raw Permalink Normal View History

2021-09-06 12:54:09 +00:00
package lib
type API struct {
2021-03-22 02:08:04 +00:00
BasePath string `yaml:"basepath,omitempty"`
Host string `yaml:"host,omitempty"`
Types map[string]*APIType `yaml:"types,omitempty"`
Methods map[string]*APIMethod `yaml:"methods,omitempty"`
Namespace string `yaml:"namespace"`
Imports map[string]string `yaml:"imports"`
2021-04-02 14:40:28 +00:00
UsedImportsTypes map[string]string `yaml:"used_imports_types"`
UsedImportsFunctions map[string]string `yaml:"used_imports_functions"`
2021-11-28 22:08:32 +00:00
SortedPaths []*APIPath `yaml:"-"`
2021-04-02 14:40:28 +00:00
Paths map[string]*APIPath `yaml:"paths"`
}
type APIPath struct {
Path string `yaml:"path"`
MapVerbs map[string]*APIVerb `yaml:"map_verbs"`
SortedVerbs []*APIVerb `yaml:"sorted_verbs"`
}
type APIVerb struct {
Verb string `yaml:"verb"`
Method *APIMethod `yaml:"method"`
}
2021-01-30 09:53:34 +00:00
type APIFieldTag struct {
2021-04-02 14:40:28 +00:00
Key string `yaml:"key"`
Name string `yaml:"name"`
Opts []string `yaml:"opts"`
2021-01-30 09:53:34 +00:00
}
type APIField struct {
2021-03-22 02:08:04 +00:00
Type string `yaml:"type,omitempty"`
Array bool `yaml:"array,omitempty"`
Desc string `yaml:"desc,omitempty"`
Map bool `yaml:"map,omitempty"`
Mapkey string `yaml:"mapkey,omitempty"`
Mapval string `yaml:"mapval,omitempty"`
Tags map[string]APIFieldTag `yaml:"tags,omitempty"`
}
2020-12-22 13:08:57 +00:00
func (a *APIField) String() string {
if a.Array {
return "[]" + a.Type
} else {
return a.Type
}
}
type APIType struct {
2021-04-02 14:40:28 +00:00
Name string `yaml:"name,omitempty"`
Desc string `yaml:"desc,omitempty"`
Fields map[string]*APIField `yaml:"fields,omitempty"`
Col string `yaml:"col,omitempty"`
TypeDef string `yaml:"-"`
}
type APIParamType struct {
Typename string
Ispointer bool
2020-12-12 12:21:12 +00:00
IsArray bool
}
type APIMethod struct {
2021-04-02 14:40:28 +00:00
Name string `yaml:"name"`
Desc string `yaml:"desc"`
Verb string `yaml:"verb"`
Path string `yaml:"path"`
2021-11-28 22:08:32 +00:00
Perm string `yaml:"perm"`
2021-09-06 12:54:09 +00:00
Raw bool `yaml:"raw"`
2021-11-28 22:08:32 +00:00
OpID string `yaml:"op_id"`
ReqType *APIParamType
ResType *APIParamType
}
2020-12-12 12:21:12 +00:00
func APIParamTypeToString(t *APIParamType) string {
ret := ""
if t.IsArray {
ret = "[]"
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
if t.Ispointer {
2021-03-22 02:08:04 +00:00
ret = ret + "*"
2020-12-12 12:21:12 +00:00
}
ret = ret + t.Typename
return ret
}
func APIParamTypeDecToString(t *APIParamType) string {
ret := ""
if t.IsArray {
ret = "[]"
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
if t.Ispointer {
ret = ret + "*"
}
ret = ret + t.Typename
return ret
}
2020-12-13 12:23:36 +00:00
func APIParamTypeUseRef(t *APIParamType) string {
if t.IsArray || !t.Ispointer {
return "&"
}
return ""
}