swag: Swag init no longer works after updating to 1.5.1

Describe the bug Previously used Swaggo/Swag 1.5.0. No longer works after updating to 1.5.1. Getting the following output:

2019/07/01 10:31:18 Generate swagger docs....
2019/07/01 10:31:18 Generate general API Info
2019/07/01 10:31:18 execute go list command, exit status 1

To Reproduce Not entirely sure. Using a standard layout with cmd, pkg and internal folders. Running swag init from project root folder.

Steps to reproduce the behavior:

  1. Use swag 1.5.1
  2. Run swag init.

Expected behavior Swag generates swagger docs in docs-folder.

Your swag version 1.5.1

Your go version 1.12.6

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

I’m having this exact same issue on swag v1.6.7. What was the best recommended fix? Tried everything in this thread and it doesn’t work. Following project structure as recommended here:

https://github.com/golang-standards/project-layout

cmd/app/main.go <- the application entrypoint and where initial swagger attributes are above main() pkg/api/server.go <- where the HTTP API starts up with Echo pkg/api/[entity]/[entity].go <- multiple folders that follow this path. Each entity contains a set of API docs for their respective API routes.

I am having the same issue, can we reopen this or get pointed to the correct solution?

we have almost the same project structure as @lsattem Today I updated swag to v1.6.0, and it works fine as

swag init -d api -g main.go

without any changes in the project structure I had some errors on v1.5.1 yesterday, but today I cannot reproduce them

I’m having this exact same issue on swag v1.6.7. What was the best recommended fix? Tried everything in this thread and it doesn’t work. Following project structure as recommended here:

https://github.com/golang-standards/project-layout

cmd/app/main.go <- the application entrypoint and where initial swagger attributes are above main() pkg/api/server.go <- where the HTTP API starts up with Echo pkg/api/[entity]/[entity].go <- multiple folders that follow this path. Each entity contains a set of API docs for their respective API routes.

I’m sorry to keep you waiting. This is the reproduced repo. I run swag init -g app/main/mian.go and get below message

2019/07/06 17:56:24 Generate swagger docs....
2019/07/06 17:56:24 Generate general API Info, search dir:./
2019/07/06 17:56:24 execute go list command, exit status 1, stdout:, stderr:can't load package: package swag-test: unknown import path "swag-test": cannot find module providing package swag-test

@easonlin404 I used v1.6.0 when writing the previous message. Adding --parseDependency=true does not make any difference. This is not an outside dependency, as I understand it. The swagger doc is in a file in this specific project, and Swag no longer seems able to detect any go files in my project.

Running the following:

swag --version
echo "running 'swag init -g \"$SWAGGER_INFO\"' --parseDependency=true"
swag init -g "$SWAGGER_INFO" --parseDependency=true

Yields this output:

swag version v1.6.0
running 'swag init -g "./pkg/swagger/info.go"' --parseDependency=true
2019/07/02 11:06:06 Generate swagger docs....
2019/07/02 11:06:06 Generate general API Info, search dir:./
2019/07/02 11:06:06 execute go list command, exit status 1, stdout:, stderr:can't load package: package bitbucket.org/USER/REPO: no Go files in /home/USER/go/src/bitbucket.org/USER/REPO

Relevant project structure

root:
  cmd:
    main:
      - main.go # run program
  pkg:
    swagger:
      - info.go #contains general swagger info
  internal:
    api:
      - api.go #contains http end points with swagger comments

I tried playing around with the “-d” and “-g”, parameters (e.g. full path), but to no avail. It still is unable to detect any go files.

@lsattem The issue have fixes after merged https://github.com/swaggo/swag/pull/425. And now you update version to v1.6.0 and execute the following to specify paring outside dependencies, disabled by default. swag init --parseDependency=true