Swag: Since v1.6.8 generating docs does not work anymore (applies also to v1.6.9)

Created on 7 Dec 2020  Â·  6Comments  Â·  Source: swaggo/swag

Describe the bug

swag init --parseDependency --parseInternal -g cmd/server/main.go
2020/12/07 14:10:18 Generate swagger docs....
2020/12/07 14:10:18 Generate general API Info, search dir:./
2020/12/07 14:10:19 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/ogg/ws/github/ledger-compliance/server

and the command hangs indefinitely.

NOTE: the project structure looks like this:

- cmd
   - server
      main.go
- internal
   - server
      server.go
      router.go
      ...

To Reproduce
Steps to reproduce the behavior:

  1. Create a project with a package/dir structure so that there are no go files in the root folder of it (e.g. like the one illustrated above).
  2. Run swag init --parseDependency --parseInternal -g cmd/server/main.go

Expected behavior
Generation should work (it works with v1.6.7 even without the extra flags for --parseDependency and --parseInternal).
Probably go list ./... should be used internally, instead of just go list.

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

Your swag version
e.g. v.1.6.8, v1.6.9

Your go version
go1.15.5 darwin/amd64

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • Browser: [e.g. chrome, safari]
  • Version: [e.g. 22]

Additional context
N/A

bug

Most helpful comment

With v1.6.9 we get a warning but the docs are still generated:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 07:28:49 Generate swagger docs....
2020/12/08 07:28:49 Generate general API Info, search dir:./
2020/12/08 07:28:49 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 07:28:50 create docs.go at spec/docs.go
2020/12/08 07:28:50 create swagger.json at spec/swagger.json
2020/12/08 07:28:50 create swagger.yaml at spec/swagger.yaml
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.6.9

And after upgrading to v1.7.0 the doc generation fails:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:02:56 Generate swagger docs....
2020/12/08 08:02:56 Generate general API Info, search dir:./
2020/12/08 08:02:56 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:02:58 ParseComment error in file internal/http/routes/merchant_cancel_process.go :can not parse response comment "400 "Failed to pass json schema""
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.7.0

--parseDepth 1 has no effect on the error:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --parseDepth 1  --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:07:50 Generate swagger docs....
2020/12/08 08:07:50 Generate general API Info, search dir:./
2020/12/08 08:07:51 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:07:52 ParseComment error in file internal/http/routes/merchant_return_period.go :can not parse response comment "400 "Failed to pass json schema""

All 6 comments

Try adding --depth 1
swag init --parseDependency --parseInternal --depth 1 -g cmd/server/main.go

@sdghchj Thanks, this seems to kind of get it one step further:

➤ swag init --parseDependency --parseInternal --parseDepth 1 -g cmd/server/main.go
2020/12/07 16:31:53 Generate swagger docs....
2020/12/07 16:31:53 Generate general API Info, search dir:./
2020/12/07 16:31:53 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in ~/some-project
2020/12/07 16:31:57 Generating controller.SMTPConfigRequest
...
2020/12/07 16:31:57 Generating controller.NullTime
2020/12/07 16:31:57 ParseComment error in file internal/controller/ledger.go :cannot find type definition: sql.NullTime

Looks like --parseDependency has no effect ...

With v1.6.9 we get a warning but the docs are still generated:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 07:28:49 Generate swagger docs....
2020/12/08 07:28:49 Generate general API Info, search dir:./
2020/12/08 07:28:49 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 07:28:50 create docs.go at spec/docs.go
2020/12/08 07:28:50 create swagger.json at spec/swagger.json
2020/12/08 07:28:50 create swagger.yaml at spec/swagger.yaml
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.6.9

And after upgrading to v1.7.0 the doc generation fails:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:02:56 Generate swagger docs....
2020/12/08 08:02:56 Generate general API Info, search dir:./
2020/12/08 08:02:56 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:02:58 ParseComment error in file internal/http/routes/merchant_cancel_process.go :can not parse response comment "400 "Failed to pass json schema""
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.7.0

--parseDepth 1 has no effect on the error:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --parseDepth 1  --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:07:50 Generate swagger docs....
2020/12/08 08:07:50 Generate general API Info, search dir:./
2020/12/08 08:07:51 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:07:52 ParseComment error in file internal/http/routes/merchant_return_period.go :can not parse response comment "400 "Failed to pass json schema""

@sdghchj Thanks, this seems to kind of get it one step further:

➤ swag init --parseDependency --parseInternal --parseDepth 1 -g cmd/server/main.go
2020/12/07 16:31:53 Generate swagger docs....
2020/12/07 16:31:53 Generate general API Info, search dir:./
2020/12/07 16:31:53 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in ~/some-project
2020/12/07 16:31:57 Generating controller.SMTPConfigRequest
...
2020/12/07 16:31:57 Generating controller.NullTime
2020/12/07 16:31:57 ParseComment error in file internal/controller/ledger.go :cannot find type definition: sql.NullTime

Looks like --parseDependency has no effect ...

Try increasing the depth

--parseDependency --parseInternal --parseDepth 3 -g cmd/server/main.go

With v1.6.9 we get a warning but the docs are still generated:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 07:28:49 Generate swagger docs....
2020/12/08 07:28:49 Generate general API Info, search dir:./
2020/12/08 07:28:49 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 07:28:50 create docs.go at spec/docs.go
2020/12/08 07:28:50 create swagger.json at spec/swagger.json
2020/12/08 07:28:50 create swagger.yaml at spec/swagger.yaml
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.6.9

And after upgrading to v1.7.0 the doc generation fails:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:02:56 Generate swagger docs....
2020/12/08 08:02:56 Generate general API Info, search dir:./
2020/12/08 08:02:56 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:02:58 ParseComment error in file internal/http/routes/merchant_cancel_process.go :can not parse response comment "400 "Failed to pass json schema""
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.7.0

--parseDepth 1 has no effect on the error:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --parseDepth 1  --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:07:50 Generate swagger docs....
2020/12/08 08:07:50 Generate general API Info, search dir:./
2020/12/08 08:07:51 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:07:52 ParseComment error in file internal/http/routes/merchant_return_period.go :can not parse response comment "400 "Failed to pass json schema""

Sorry for this bug, my fault. Refer to new issue #853

@sdghchj Using 2 for depth works, indeed, although the warning about go list not finding any go files is still there:
swag init --parseDependency --parseInternal --parseDepth 2 -g cmd/server/main.go.
The performance is much worst than it was with v1.6.7, though. Even if that didn't require any extra params - so it was just swag init -g cmd/server/main.go :(
Anyway, thanks.
If this is considered fixed, please close the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wuhuizuo picture wuhuizuo  Â·  4Comments

Nerzal picture Nerzal  Â·  6Comments

Ashtonian picture Ashtonian  Â·  6Comments

welenlin picture welenlin  Â·  3Comments

chiragg6 picture chiragg6  Â·  7Comments