feat(openapi): keep empty describable group tags

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 00:39:04 +00:00
parent 0bb07f43f0
commit 812400f303
2 changed files with 45 additions and 1 deletions

View file

@ -586,7 +586,7 @@ func (sb *SpecBuilder) buildTags(groups []preparedRouteGroup) []map[string]any {
for _, g := range groups {
name := strings.TrimSpace(g.group.Name())
if name != "" && !seen[name] && (!g.describable || len(g.descs) > 0) {
if name != "" && !seen[name] {
tags = append(tags, map[string]any{
"name": name,
"description": name + " endpoints",

View file

@ -1469,6 +1469,50 @@ func TestSpecBuilder_Good_NonDescribableGroup(t *testing.T) {
}
}
func TestSpecBuilder_Good_EmptyDescribableGroupStillAddsTag(t *testing.T) {
sb := &api.SpecBuilder{
Title: "Test",
Version: "1.0.0",
}
group := &specStubGroup{
name: "empty",
basePath: "/api/empty",
descs: nil,
}
data, err := sb.Build([]api.RouteGroup{group})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var spec map[string]any
if err := json.Unmarshal(data, &spec); err != nil {
t.Fatalf("invalid JSON: %v", err)
}
tags := spec["tags"].([]any)
foundEmpty := false
for _, tag := range tags {
tm := tag.(map[string]any)
if tm["name"] == "empty" {
foundEmpty = true
break
}
}
if !foundEmpty {
t.Fatal("expected empty describable group to appear in spec tags")
}
paths := spec["paths"].(map[string]any)
if len(paths) != 1 {
t.Fatalf("expected only /health path, got %d paths", len(paths))
}
if _, ok := paths["/health"]; !ok {
t.Fatal("expected /health path in spec")
}
}
func TestSpecBuilder_Good_DefaultTagsFromGroupName(t *testing.T) {
sb := &api.SpecBuilder{
Title: "Test",