swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.58k stars 1.19k forks source link

Provide a way to specify an external module to include #1800

Open ns-mglaske opened 5 months ago

ns-mglaske commented 5 months ago

Is your feature request related to a problem? Please describe. I have a module that I include in my go app, that returns a struct that I'd like to use. This module, uses a model from a 3rd party to return it's results, and imports the 'model' module as 'em', and parseDependencies doesn't seem to pick it up, unless I pre-init the variable I use to contain the result. Basically, since I'm not using the struct directly, gofmt removes the reference from imports, since it's not used directly, so swag has no way to identify what em.Blah is.

Describe the solution you'd like A way to specify a import that swag should use, but is not used by go directly. (eg. @includeDep em "github.com/blah")

Describe alternatives you've considered I can get around this currently by pre-initializing the response variable.

import (
  em "github.com/blah"
)
func x() {
    resp := make([]em.Blah, 0)
    resp, err := library.GetDetails()
   ...

Maybe you already have a way around this, but I couldn't find it.

haminh0307 commented 5 months ago
_ "github.com/blah"

Have you tried this? gofmt won't remove import statement with blank identifier as explicit package name.