swag icon indicating copy to clipboard operation
swag copied to clipboard

Go1.18: cannot find all dependencies, unable to resolve root package

Open tylfin opened this issue 2 years ago • 6 comments

Describe the bug

Upgrading our project to Go1.18 leads to swag raising an error message. I saw another Github issue and think the issue might be related to the use of the parseDependency flag and the changes to go mod

Error Message

When I first upgraded, the swag command hung indefinitely, so I added the GOWORK=off GOFLAGS="-mod=vendor" environment variables and started to receive the message cannot find all dependencies, unable to resolve root package:

$ GOWORK=off GOFLAGS="-mod=vendor" swag init --parseDependency --generalInfo [YY] --dir /[XX] --output /[XX]/swagger --exclude /[XX]/[ZZ]
2022/03/25 20:18:46 Generate swagger docs....
2022/03/25 20:18:46 Generate general API Info, search dir:/[XX]
2022/03/25 20:18:51 pkg XX/YY cannot find all dependencies, unable to resolve root package

Expected behavior

Swag files generate same as before

Your swag version

1.8.0

Your go version

1.18

Desktop (please complete the following information):

  • OS: macOS, Linux (Docker)

tylfin avatar Mar 25 '22 20:03 tylfin

You made so many changes that it's almost impossible to figure out the issue.

Please do a 1 step change until you can conclude where the issue is and let us know.

ubogdan avatar Mar 28 '22 18:03 ubogdan

Everything worked until the upgrade to Go1.18 / deprecation of the GOPATH, I was able to get swag to generate again forcing GO111MODULE=off and specifying a GOPATH.

The issue may be that this dependency doesn't handle go modules correctly? https://github.com/KyleBanks/depth

tylfin avatar Mar 30 '22 15:03 tylfin

I have no clue, and I usually don't set GOPATH. On the other go1.18 just got released, and it will take some time until all the ecosystem will align with the newest changes.

If using go1.18 with swag is essential to you, please feel free to contribute with a PR, and I will be pleased to assist you with a CR.

ubogdan avatar Mar 30 '22 17:03 ubogdan

Sure I could take a look, what about shelling out to go list as a fallback to remain compatible across many versions of Go?

tylfin avatar Mar 30 '22 17:03 tylfin

I also encountered this problem.

when i use --parseInternal --parseDependency --parseDepth=100 to genarate doc, will happen error

cannot find all dependencies, unable to resolve root package
  • go: 1.18.3
  • swag: 1.8.3
  • os: win10

QiqiM avatar Jul 15 '22 14:07 QiqiM

I fixed this problem by install latest swag:

$ go install github.com/swaggo/swag/cmd/swag@latest
$ swag --version
swag version v1.16.2
$ go version
 go1.20.6 darwin/arm64

xuehuiye avatar Sep 05 '23 12:09 xuehuiye