2020-11-04 13:14:18 -03:00
|
|
|
package main
|
|
|
|
|
|
|
|
type API struct {
|
|
|
|
BasePath string `yaml:"basepath"`
|
|
|
|
Host string `yaml:"host"`
|
|
|
|
Types map[string]*APIType `yaml:"types"`
|
|
|
|
Methods map[string]*APIMethod `yaml:"methods"`
|
|
|
|
Namespace string
|
|
|
|
}
|
2021-01-30 06:53:34 -03:00
|
|
|
type APIFieldTag struct {
|
|
|
|
Key string
|
|
|
|
Name string
|
|
|
|
Opts []string
|
|
|
|
}
|
2020-11-04 13:14:18 -03:00
|
|
|
type APIField struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Array bool `yaml:"array"`
|
|
|
|
Desc string `yaml:"desc"`
|
|
|
|
Map bool `yaml:"map"`
|
|
|
|
Mapkey string `yaml:"mapkey"`
|
|
|
|
Mapval string `yaml:"mapval"`
|
2021-01-30 06:53:34 -03:00
|
|
|
Tags map[string]APIFieldTag
|
2020-11-04 13:14:18 -03:00
|
|
|
}
|
2020-12-22 10:08:57 -03:00
|
|
|
|
|
|
|
func (a *APIField) String() string {
|
|
|
|
if a.Array {
|
|
|
|
return "[]" + a.Type
|
|
|
|
} else {
|
|
|
|
return a.Type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 13:14:18 -03:00
|
|
|
type APIType struct {
|
2021-01-30 06:53:34 -03:00
|
|
|
Name string `yaml:"name"`
|
2020-11-04 13:14:18 -03:00
|
|
|
Desc string `yaml:"desc"`
|
|
|
|
Fields map[string]*APIField `yaml:"fields"`
|
|
|
|
Col string `yaml:"col"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type APIParamType struct {
|
|
|
|
Typename string
|
|
|
|
Ispointer bool
|
2020-12-12 09:21:12 -03:00
|
|
|
IsArray bool
|
2020-11-04 13:14:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
type APIMethod struct {
|
|
|
|
Desc string `yaml:"desc"`
|
|
|
|
Verb string `yaml:"verb"`
|
|
|
|
Path string `yaml:"path"`
|
|
|
|
Perm string `yaml:perm`
|
|
|
|
ReqType *APIParamType
|
|
|
|
ResType *APIParamType
|
|
|
|
Raw bool `yaml:"raw"`
|
|
|
|
}
|
2020-12-12 09:21:12 -03: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 {
|
|
|
|
ret = ret + "&"
|
|
|
|
}
|
|
|
|
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 09:23:36 -03:00
|
|
|
|
|
|
|
func APIParamTypeUseRef(t *APIParamType) string {
|
|
|
|
if t.IsArray || !t.Ispointer {
|
|
|
|
return "&"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|