Skip to content

Commit 8bd467a

Browse files
committed
feat: Prevents empty tags from being added to routes
When a group is created with an empty path, the tag should not be added to the route.
1 parent 3e95271 commit 8bd467a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func Group(s *Server, path string, routeOptions ...func(*BaseRoute)) *Server {
3535
newServer := &ss
3636
newServer.basePath += path
3737

38-
if !s.disableAutoGroupTags {
39-
newServer.routeOptions = append(s.routeOptions, OptionTags(strings.TrimLeft(path, "/")))
38+
if autoTag := strings.TrimLeft(path, "/"); !s.disableAutoGroupTags && autoTag != "" {
39+
newServer.routeOptions = append(s.routeOptions, OptionTags(autoTag))
4040
}
4141
newServer.mainRouter = s
4242

mux_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,17 @@ func TestGroupTagsOnRoute(t *testing.T) {
467467

468468
require.Equal(t, []string{"my-server-tag", "my-route-tag"}, route.Operation.Tags)
469469
})
470+
471+
t.Run("do not add empty tag group", func(t *testing.T) {
472+
s := NewServer()
473+
groupEmpty := Group(s, "")
474+
groupSlash := Group(s, "/")
475+
routeEmpty := Get(groupEmpty, "/empty", dummyController)
476+
routeSlash := Get(groupSlash, "/slash", dummyController)
477+
478+
require.Nil(t, routeEmpty.Operation.Tags)
479+
require.Nil(t, routeSlash.Operation.Tags)
480+
})
470481
}
471482

472483
func TestHideOpenapiRoutes(t *testing.T) {

0 commit comments

Comments
 (0)