diff --git a/internal/api/api.go b/internal/api/api.go
index 4fc8658..ea34423 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -424,8 +424,14 @@
return fmt.Errorf("symbols for package %s: %w", pkgPath, err)
}
+ if params.Kind != "" {
+ syms = slices.DeleteFunc(syms, func(s *internal.Symbol) bool {
+ return !strings.EqualFold(string(s.Kind), params.Kind)
+ })
+ }
+
syms, err = filter(syms, params.Filter, func(s *internal.Symbol) []string {
- return []string{s.Name, s.Synopsis}
+ return []string{s.Name, s.Synopsis, string(s.Kind)}
})
if err != nil {
return err
diff --git a/internal/api/openapi.yaml b/internal/api/openapi.yaml
index ce61165..fb0cdaf 100644
--- a/internal/api/openapi.yaml
+++ b/internal/api/openapi.yaml
@@ -348,6 +348,14 @@
}
},
{
+ "description": "include only symbols of this kind",
+ "in": "query",
+ "name": "kind",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
"description": "max number of items to return",
"in": "query",
"name": "limit",
diff --git a/internal/api/params.go b/internal/api/params.go
index 1119b11..cee9ab4 100644
--- a/internal/api/params.go
+++ b/internal/api/params.go
@@ -52,6 +52,8 @@
GOOS string `form:"goos"`
// GOARCH of documentation build context
GOARCH string `form:"goarch"`
+ // include only symbols of this kind
+ Kind string `form:"kind"`
ListParams
}
diff --git a/internal/postgres/package_symbol.go b/internal/postgres/package_symbol.go
index 5325e61..f1159cb 100644
--- a/internal/postgres/package_symbol.go
+++ b/internal/postgres/package_symbol.go
@@ -63,12 +63,6 @@
Kind: kind,
Synopsis: synopsis,
}
- if sm.ParentName != "" && sm.ParentName != sm.Name {
- if parent, ok := symbolMap[sm.ParentName]; ok {
- parent.Children = append(parent.Children, &sm)
- return nil
- }
- }
// Treat as top-level if no parent or parent not found in this build context.
s := &internal.Symbol{
SymbolMeta: sm,
diff --git a/internal/tests/api/api_test.go b/internal/tests/api/api_test.go
index 2b02e7e..134ac68 100644
--- a/internal/tests/api/api_test.go
+++ b/internal/tests/api/api_test.go
@@ -1062,11 +1062,11 @@
func testServePackageSymbols(t *testing.T, ds internal.TestingDataSource) {
- sym := func(doc *internal.Documentation, name string) *internal.Symbol {
+ sym := func(doc *internal.Documentation, name string, kind internal.SymbolKind) *internal.Symbol {
return &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: name,
- Kind: internal.SymbolKindFunction,
+ Kind: kind,
Section: internal.SymbolSectionFunctions,
},
GOOS: doc.GOOS,
@@ -1075,11 +1075,15 @@
}
linuxDoc := sample.Documentation("linux", "amd64", sample.DocContents)
- linuxDoc.API = []*internal.Symbol{sym(linuxDoc, "LinuxSym"), sym(linuxDoc, "F")}
+ linuxDoc.API = []*internal.Symbol{
+ sym(linuxDoc, "LinuxSym", internal.SymbolKindFunction),
+ sym(linuxDoc, "F", internal.SymbolKindFunction),
+ sym(linuxDoc, "LinuxType", internal.SymbolKindType),
+ }
winDoc := sample.Documentation("windows", "amd64", sample.DocContents)
- winDoc.API = []*internal.Symbol{sym(winDoc, "WindowsSym")}
+ winDoc.API = []*internal.Symbol{sym(winDoc, "WindowsSym", internal.SymbolKindFunction)}
wasmDoc := sample.Documentation("js", "wasm", sample.DocContents)
- wasmDoc.API = []*internal.Symbol{sym(wasmDoc, "WasmSym")}
+ wasmDoc.API = []*internal.Symbol{sym(wasmDoc, "WasmSym", internal.SymbolKindFunction)}
ds.MustInsertModule(t,
module(t, modinfo("example.com", "v1.0.0"),
unit("pkg", linuxDoc, winDoc, wasmDoc)))
@@ -1095,7 +1099,7 @@
name: "default best match (linux)",
url: "/v1beta/symbols/example.com/pkg?version=v1.0.0",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "package not found",
@@ -1113,13 +1117,13 @@
name: "explicit linux",
url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&goos=linux&goarch=amd64",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "version latest",
url: "/v1beta/symbols/example.com/pkg?version=latest",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "explicit windows",
@@ -1142,6 +1146,24 @@
Message: "not found",
},
},
+ {
+ name: "kind filter (function)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=function",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"F", "LinuxSym"},
+ },
+ {
+ name: "kind filter (type)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=type",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"LinuxType"},
+ },
+ {
+ name: "kind filter (type, case insensitive)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=Type",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"LinuxType"},
+ },
} {
t.Run(test.name, func(t *testing.T) {
r := httptest.NewRequest("GET", test.url, nil)