diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 5c4cdda0..e12ba41e 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -273,8 +273,10 @@ func (p *Param) astGetParamType(param *ast.Field) { p.astGetEltType(v.X) case *ast.IndexExpr: p.astGetEltType(v.X) + p.astGetGenericType(v.Index) case *ast.IndexListExpr: p.astGetEltType(v.X) + p.astGetGenericType(v.Indices...) default: log.Printf("Unsupported param type: %+v", v) } @@ -302,11 +304,33 @@ func (p *Param) astGetEltType(expr ast.Expr) { p.Type = "[]" + p.Type case *ast.IndexExpr: p.astGetEltType(v.X) + p.astGetGenericType(v.Index) + case *ast.IndexListExpr: + p.astGetEltType(v.X) + p.astGetGenericType(v.Indices...) default: log.Printf("Unsupported param type: %+v", v) } } +func (p *Param) astGetGenericType(exprList ...ast.Expr) { + if p.Package == "" { + p.Package = "UNDEFINED" // Generic types are definitely not built-in types. + } + if len(exprList) == 0 { + return + } + var types []string + for _, expr := range exprList { + typeStr := astGetType(expr) + if typeStr == "" { + typeStr = "interface{}" // fallback for unsupported types + } + types = append(types, typeStr) + } + p.Type = fmt.Sprintf("%s[%s]", p.Type, strings.Join(types, ", ")) +} + func (p *Param) astGetPackageName(expr ast.Expr) { switch v := expr.(type) { case *ast.Ident: