package server import ( "encoding/json" "testing" "github.com/gin-gonic/gin" ) func TestSwaggerMarksOnlyPublicRoutesWithoutAuth(t *testing.T) { document := buildSwaggerDocument([]gin.RouteInfo{ {Method: "GET", Path: "/api/freshCasbin"}, {Method: "GET", Path: "/info/getInfoDataSource"}, {Method: "GET", Path: "/info/getInfoPublic"}, }, "", "test") var payload struct { Paths map[string]map[string]map[string]any `json:"paths"` } if err := json.Unmarshal([]byte(document), &payload); err != nil { t.Fatal(err) } for _, path := range []string{"/api/freshCasbin", "/info/getInfoDataSource"} { if _, ok := payload.Paths[path]["get"]["security"]; !ok { t.Fatalf("private route %s was marked public", path) } } if _, ok := payload.Paths["/info/getInfoPublic"]["get"]["security"]; ok { t.Fatal("public route /info/getInfoPublic requires authentication") } }