Skip to content

Remove swag v1 indirect dependency from echo-swagger/v2 #147

Description

@AndriyKalashnykov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions