diff --git a/lib/loader.go b/lib/loader.go index d6a6908..b6f8321 100644 --- a/lib/loader.go +++ b/lib/loader.go @@ -34,6 +34,9 @@ func addStruct(a *ast.GenDecl) { llog("Adding type: %s => %#v", tp.Name, md) for _, v := range a.Specs[0].(*ast.TypeSpec).Type.(*ast.StructType).Fields.List { + if len(v.Names) < 1 { + panic("Does not support Composition: " + tp.Name) + } tp.Fields[v.Names[0].Name] = &APIField{} tp.Fields[v.Names[0].Name].Tags = make(map[string]APIFieldTag) @@ -203,6 +206,7 @@ func addFunction(a *ast.FuncDecl) error { return nil } +// load is responsible for loading the package for AST Parsing func load(src string) error { api.Types = (make(map[string]*APIType)) @@ -221,6 +225,7 @@ func load(src string) error { return err } + //iterate over packages for _, v := range f { llog("Loading Package: %s", v.Name) diff --git a/lib/types.go b/lib/types.go index a62dfd8..df930ff 100644 --- a/lib/types.go +++ b/lib/types.go @@ -9,7 +9,7 @@ type API struct { Imports map[string]string `yaml:"imports"` UsedImportsTypes map[string]string `yaml:"used_imports_types"` UsedImportsFunctions map[string]string `yaml:"used_imports_functions"` - SortedPaths []*APIPath `yaml:"sorted_paths"` + SortedPaths []*APIPath `yaml:"-"` Paths map[string]*APIPath `yaml:"paths"` } @@ -65,8 +65,9 @@ type APIMethod struct { Desc string `yaml:"desc"` Verb string `yaml:"verb"` Path string `yaml:"path"` - Perm string `yaml:perm` + Perm string `yaml:"perm"` Raw bool `yaml:"raw"` + OpID string `yaml:"op_id"` ReqType *APIParamType ResType *APIParamType } diff --git a/main.go b/main.go index 281df61..7b42d4d 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "os" ) -var Ver string = "Tue Sep 7 12:38:32 -03 2021" +var Ver string = "2021-11-28T13:57:28.822468Z" func main() { os.Stdout.WriteString(fmt.Sprintf("Version: %s\n", Ver)) diff --git a/test/demo/api/apigen.go b/test/demo/api/apigen.go index ee57122..3e2d398 100644 --- a/test/demo/api/apigen.go +++ b/test/demo/api/apigen.go @@ -191,6 +191,7 @@ func Init() *API { }) mux.HandleFunc("/some2", func(w http.ResponseWriter, r *http.Request) { switch r.Method { + case "POST": h_Dosome2(w, r) default: diff --git a/test/goapi.yaml b/test/goapi.yaml index acfde28..b99abac 100644 --- a/test/goapi.yaml +++ b/test/goapi.yaml @@ -1,21 +1,99 @@ +types: + AStr: + name: AStr + fields: + Arrofpstr: + type: string + array: true + tags: + json: + key: json + name: arrofpstr + opts: + - omitempty + City: + type: string + Country: + type: string + HouseNumber: + type: int64 + IsCondo: + type: bool + Recursive: + map: true + mapkey: string + mapval: AStr + Some: + type: crypto.Decrypter + SomeWeirdTest: + type: string + tags: + json: + key: json + name: SUPERCALIFRAGILISPEALIDOUX + opts: [] + When: + type: time.Time methods: - SomeAPI3: - desc: SomeAPI3 - verb: PUT + SomeAPI: + name: SomeAPI + desc: SomeAPI + verb: POST path: /someapi perm: ASD + raw: false reqtype: - typename: time.Time - ispointer: false + typename: AStr + ispointer: true isarray: false restype: - typename: string - ispointer: false - isarray: true - raw: false -namespace: "" + typename: AStr + ispointer: true + isarray: false +namespace: goapi imports: context: context + crypto: crypto time: time -used_imports: -- time +used_imports_types: + crypto: crypto + time: time +used_imports_functions: {} +paths: + /someapi: + path: /someapi + map_verbs: + POST: + verb: POST + method: + name: SomeAPI + desc: SomeAPI + verb: POST + path: /someapi + perm: ASD + raw: false + reqtype: + typename: AStr + ispointer: true + isarray: false + restype: + typename: AStr + ispointer: true + isarray: false + sorted_verbs: + - verb: POST + method: + name: SomeAPI + desc: SomeAPI + verb: POST + path: /someapi + perm: ASD + raw: false + reqtype: + typename: AStr + ispointer: true + isarray: false + restype: + typename: AStr + ispointer: true + isarray: false diff --git a/test/goapi/test.go b/test/goapi/test.go index 834f5d5..d20587e 100644 --- a/test/goapi/test.go +++ b/test/goapi/test.go @@ -25,7 +25,7 @@ type AStr struct { @PERM: ASD @VERB: POST */ -func SomeAPI(ctx context.Context, s *AStr, c int) (out *AStr, err error) { +func SomeAPI(ctx context.Context, s *AStr) (out *AStr, err error) { //print("Got:" + s) //out = time.Now().String() + " - Hey Ya!" return