Swag: Go Modules support

Created on 19 Dec 2018  路  8Comments  路  Source: swaggo/swag

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Currently, I don't think this CLI supports go modules at all. It would be nice to support this as that is where go-lang seems to be heading

Describe the solution you'd like
A clear and concise description of what you want to happen.
I should be able to run the swag cli from outside of the GOPATH
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

feature

Most helpful comment

Why was this closed? I am still having this issue and could only resolve it using the workaround that @tzilist posted. I'm using v1.6.5

All 8 comments

I have the same problem when referencing structs as response defined in vendored packages using go mod. Swaggo creates a reference in the type of external.repo.io/repo.StructName but doesnt create a response definition for it. The swagger client then throws errors like

Resolver error at paths./stuff.get.responses.403.schema.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/external.repo.io/repo.StructName does not exist in document

When I manually add the missing response to the generated file, it works.

I have the same issue. I am developing a go module that implements a /health endpoint according to the upcoming IETC RFC. When I created the sample code that supports swag, I could not see the /health endpoint. Without having looked at the code, I would currently assume that swag does not scan module sources, but only recursively from the current directory.

It would be very useful for people if swag would support go modules, I just don't know how easy or difficult this is to implement. I will try something, maybe I can even come up with a PR.

@easonlin404 it looks like an issue with gotools loader not knowing where to look. It is entirely possible you would need to use a different tool or figure out how to configure it. I've heard of people using gogrep, but I am not entirely sure.

In the mean time, the work-around I have found is to run this before running swag:

# make sure to be in project root
go mod vendor
cp -R /vendor/* $GOPATH/src/

# now run swag
swag init

Usually this doesn't take very long but it's not ideal

It's not easy to support go modules. I will using different tool like gogrep,godef or any other tool instead of current searching mechanisms asap.

This ticket has been open for 6 months and is only becoming more relevant and more difficult to ignore. Would it be possible to get some traction on this?

I agree with you that having supported for Go modules feature is highest priority now. Will keep on support for it and release on v1.6.

Please use the latest swag that supports founding declarative annotations from go-module packages via #415. 馃帀

Why was this closed? I am still having this issue and could only resolve it using the workaround that @tzilist posted. I'm using v1.6.5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nerzal picture Nerzal  路  6Comments

padurean picture padurean  路  6Comments

fannheyward picture fannheyward  路  3Comments

kirillDanshin picture kirillDanshin  路  3Comments

LennyPenny picture LennyPenny  路  4Comments