swaggo / swag

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

failed to parse file [...]/tools@v0.1.12/[...] expected 'package', found 'EOF' #1478

Open david-christ opened 1 year ago

david-christ commented 1 year ago

Describe the bug

Running swag init causes an error

To Reproduce

Steps to reproduce the behavior:

$ go install github.com/swaggo/swag/cmd/swag@latest
go: downloading github.com/swaggo/swag v1.8.10
[...]

$ swag --version
swag version v1.8.10

$ swag init
2023/02/28 13:57:50 Generate swagger docs....
2023/02/28 13:57:50 Generate general API Info, search dir:./
2023/02/28 13:58:01 failed to parse file go/pkg/mod/golang.org/x/tools@v0.1.12/cmd/fiximports/testdata/src/old.com/bad/bad.go, error:go/pkg/mod/golang.org/x/tools@v0.1.12/cmd/fiximports/testdata/src/old.com/bad/bad.go:2:43: expected 'package', found 'EOF'

Expected behavior

Initialises directory.

Your swag version

e.g. 1.8.10, although also tried down to 1.6.0

Your go version

e.g. 1.19.2

Desktop (please complete the following information):

hiPsyDuck commented 1 year ago

I also encountered the same situation, the same go version and swag version

david-christ commented 1 year ago

@hiPsyDuck I figured out the issue. For me, I have a local $GOPATH in my project directory. swag init fails trying to parse it. $ swag init --exclude go/ solves the issue for me.

Is this the same for you?

Still, would be good if swag could somehow handle the GOPATH being in the project root.

ubogdan commented 1 year ago

@david-christ We are dropping support for the older versions of go due to various security issues and a lack of support. See https://endoflife.date/go. This means GOPATH will disappear at some point in favor of Go modules.