Problem
echo-swagger/v2 (v2.0.1) depends on both github.com/swaggo/swag (v1) and github.com/swaggo/swag/v2 in its go.mod:
require (
github.com/swaggo/swag v1.16.2
github.com/swaggo/swag/v2 v2.0.0-rc4
)
This means every consumer of echo-swagger/v2 is forced to carry swag v1 as an indirect dependency, even when they only use EchoWrapHandlerV3 (which already uses swag v2 internally).
Root cause
In swagger.go, EchoWrapHandler imports and uses github.com/swaggo/swag (v1) for swag.ReadDoc() and swag.Name, while EchoWrapHandlerV3 uses github.com/swaggo/swag/v2. The swag.ReadDoc() and swag.Name APIs are identical in v2 — the v1 dependency is unnecessary.
Specifically:
- Line 14:
"github.com/swaggo/swag" — v1 import
- Line 119:
swag.Name — uses v1 constant (identical value "swagger" in v2)
- Line 174, 180:
swag.ReadDoc() — uses v1 registry
Impact on consumers
Any project using echo-swagger/v2 gets this in their go.mod:
github.com/swaggo/swag v1.16.6 // indirect — unwanted dead weight
This pulls in v1's transitive dependencies (KyleBanks/depth, go-openapi/spec, go-openapi/jsonpointer, go-openapi/jsonreference, etc.) adding unnecessary module bloat.
Fix
Replace all swag v1 imports with swag/v2 in swagger.go and swagger_test.go. The APIs are identical — this is a drop-in import path change with no behavioral difference.
PR with the fix: #146 (all 16 tests pass)
Related
Problem
echo-swagger/v2(v2.0.1) depends on bothgithub.com/swaggo/swag(v1) andgithub.com/swaggo/swag/v2in itsgo.mod:This means every consumer of
echo-swagger/v2is forced to carryswag v1as an indirect dependency, even when they only useEchoWrapHandlerV3(which already uses swag v2 internally).Root cause
In
swagger.go,EchoWrapHandlerimports and usesgithub.com/swaggo/swag(v1) forswag.ReadDoc()andswag.Name, whileEchoWrapHandlerV3usesgithub.com/swaggo/swag/v2. Theswag.ReadDoc()andswag.NameAPIs are identical in v2 — the v1 dependency is unnecessary.Specifically:
"github.com/swaggo/swag"— v1 importswag.Name— uses v1 constant (identical value"swagger"in v2)swag.ReadDoc()— uses v1 registryImpact on consumers
Any project using
echo-swagger/v2gets this in theirgo.mod:This pulls in v1's transitive dependencies (KyleBanks/depth, go-openapi/spec, go-openapi/jsonpointer, go-openapi/jsonreference, etc.) adding unnecessary module bloat.
Fix
Replace all
swag v1imports withswag/v2inswagger.goandswagger_test.go. The APIs are identical — this is a drop-in import path change with no behavioral difference.PR with the fix: #146 (all 16 tests pass)
Related
github.com/swaggo/swag/v2#125 — PR that added swag v2 support (merged Sep 2025) but kept the v1 dependency forEchoWrapHandler