Swag: Fail when module contains no package

Created on 2 Jul 2019  ยท  4Comments  ยท  Source: swaggo/swag

Describe the bug
When using this with go modules:
If the module only has sub packages and no package itself

$ tree
.
โ”œโ”€โ”€ a
โ”‚ โ””โ”€โ”€ a.go
โ”œโ”€โ”€ b
โ”‚ โ””โ”€โ”€ b.go
โ””โ”€โ”€ go.mod

then swag init will fail.
The error message is:

2019/07/02 16:36:50 execute go list command, exit status 1, stdout:, stderr:can't load package: package gitlab.com/fino/uba: unknown import path "path/to/module": cannot find module providing package path/to/module

Creating a random go file that contains the package , fixes the issue

I think you are using go list on the ./ directory, which causes this

Expected behavior
It should work without a redundant "root" package in the module

Screenshots
If applicable, add screenshots to help explain your problem.
image

Your swag version
e.g. 1.6.0

Your go version
e.g. 1.12.6

Desktop (please complete the following information):

  • OS: fedora 29
bug

Most helpful comment

Thanks for report it, I will fix tmr.

All 4 comments

Thanks for report it, I will fix tmr.

I am running into this with the a module that exists outside of the GOPATH. I notice the command used is just go list -f={{.ImportPath}} but locally that command does not work, the command that does is go list -f={{.ImportPath}} ./...
I believe the change needs to be made in parser.go on line 111 to:
cmd := exec.Command("go", "list", "-f={{.ImportPath}}", "./...")
but I have not dived any deeper for my case.

@LennyPenny Please try again using the latest version.

yup it works now, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmirubtsov picture dmirubtsov  ยท  7Comments

fannheyward picture fannheyward  ยท  3Comments

touyu picture touyu  ยท  3Comments

zhongkeqin picture zhongkeqin  ยท  4Comments

henrahmagix picture henrahmagix  ยท  7Comments