Skip to content

http-swagger/v2 does not support swag/v2 - Internal Server Error #132

@arantesxyz

Description

@arantesxyz
$ swag --version
Swag version:  v2.0.0
swag version v2.0.0

go.mod

go 1.24.2

require (
	github.com/go-chi/chi/v5 v5.2.2
	github.com/swaggo/http-swagger/v2 v2.0.2
	github.com/swaggo/swag/v2 v2.0.0-rc4
)

Generating the spec with swag/v2:

$ swag init --dir ./internal/handlers --v3.1

We get the following output:

docs/docs.go

// Code generated by swaggo/swag. DO NOT EDIT.

package docs

import "github.com/swaggo/swag/v2"

// ...

Then use http-swagger/v2 to render the page
routes.go

package server

import _ "app/docs"
import httpSwagger "github.com/swaggo/http-swagger/v2"

// ...
func registerRoutes(r *chi.Mux) {
    r.Get("/docs", func(w http.ResponseWriter, r *http.Request) {
    	http.Redirect(w, r, "/docs/", http.StatusFound)
    })
    
    r.Get("/docs/*", httpSwagger.Handler(
    	httpSwagger.URL("/docs/doc.json"),
    	httpSwagger.Layout(httpSwagger.BaseLayout),
    ))
}

And then we get the following error:
Image

But if we manually go to docs/docs.go and update the import to import "github.com/swaggo/swag" (removing the v2), everything works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions