Describe the bug
swag init is failing with latest change related to go modules.
To Reproduce
Steps to reproduce the behavior:
swag init -g cmd/cnc.go
2019/06/25 14:48:36 Generate swagger docs....
2019/06/25 14:48:36 Generate general API Info
2019/06/25 14:48:41 ParseFile error:/home/downsb/go/src/golang.org/x/tools/go/loader/testdata/badpkgdecl.go:1:34: expected 'package', found 'EOF'
Expected behavior
swag init generates docs/doc.go
Screenshots
Your swag version
latest
1.5.1
Your go version
go version go1.12.6 darwin/amd64
go version go1.12.4 linux/amd64
fix via #418
@bruceadowns thanks for you report the issue. 馃憤
Problem of repetition:
swag init
2020/04/20 19:57:15 Generate swagger docs....
2020/04/20 19:57:15 Generate general API Info, search dir:./
2020/04/20 19:57:24 ParseFile error:gopath/pkg/mod/golang.org/x/[email protected]/cmd/fiximports/testdata/src/old.com/bad/bad.go:2:43: expected 'package', found 'EOF'
golang version : 1.14
swa version : 1.6.5
@easonlin404
Problem of repetition:
swag init
2020/04/20 19:57:15 Generate swagger docs....
2020/04/20 19:57:15 Generate general API Info, search dir:./
2020/04/20 19:57:24 ParseFile error:gopath/pkg/mod/golang.org/x/[email protected]/cmd/fiximports/testdata/src/old.com/bad/bad.go:2:43: expected 'package', found 'EOF'golang version : 1.14
swa version : 1.6.5
I had the same issue, but it was related to a wrong gopath definition at the beginning of my azure pipelines script.
~~~
swag init -g ./src/main/main.go
2020/04/30 19:11:02 Generate swagger docs....
2020/04/30 19:11:02 Generate general API Info, search dir:./
2020/04/30 19:11:06 ParseFile error:pkg/mod/golang.org/x/[email protected]/cmd/fiximports/testdata/src/old.com/bad/bad.go:2:43: expected 'package', found 'EOF'
~~~
golang version: go 1.14
swag version : github.com/swaggo/swag v1.6.5
~I had the same issue also~
oops it was my mistake
swag init same PATH with go.mod_if i run swag init different path with go.mod
then The above problem occurs.
maybe it's the same issue as me? @tuxnavell
My go.mod was in the same directory, but the GOPATH was set to a subfolder of the module-path. I changed it to a higher level and it was working afterwards. But this might be a similar issue. GOPATH and module-path variables in azure pipeline scripts are not 100% clear to me ;)
Git Change:
- GOPATH: '$(system.defaultWorkingDirectory)/GOPATH'
- modulePath: '$(system.defaultWorkingDirectory)' # Path to the module's code
+ GOPATH: '$(system.defaultWorkingDirectory)'
+ modulePath: '$(GOPATH)/repo-dir' # Path to the module's code
I also changed the repo-dir from the $(system.defaultWorkingDirectory) to $(system.defaultWorkingDirectory)/path-dir
golang version: go 1.13
tested swag versions:
github.com/swaggo/swag v1.6.5
github.com/swaggo/swag v1.6.4
github.com/swaggo/swag v1.6.3
my local laptop no such issue, but when I build docker image and met the issue again, even if I used swag 1.6.7 and my go version is 1.13, use go mod, etc.
See details of the docker build failure logs:
Step 6/16 : RUN go get -u github.com/swaggo/swag/cmd/swag && go mod init fts
---> Running in 86927f7b5fda
go: finding github.com/swaggo/swag v1.6.7
go: downloading github.com/swaggo/swag v1.6.7
go: extracting github.com/swaggo/swag v1.6.7
...
go: creating new go.mod: module fts
Removing intermediate container 86927f7b5fda
---> 2237ce8afc13
Step 7/16 : ARG CACHEBUST=1
---> Running in 231d7ebc1680
Removing intermediate container 231d7ebc1680
---> 1b9e5620ca5f
Step 8/16 : RUN swag init -g pkg/account/api.go -g pkg/transaction/api.go && go build -o app main.go && mkdir -p /bin && cp $PROJ/app /bin
---> Running in 59c4e385e7c4
2020/06/26 02:49:07 Generate swagger docs....
2020/06/26 02:49:07 Generate general API Info, search dir:./
2020/06/26 02:49:14 ParseFile error:pkg/mod/golang.org/x/[email protected]/cmd/fiximports/testdata/src/old.com/bad/bad.go:2:43: expected 'package', found 'EOF'
Any update on this issue ?
golang version : 1.15.2
swag version : 1.7.0
$ swag init
2020/12/09 18:19:01 Generate swagger docs....
2020/12/09 18:19:01 Generate general API Info, search dir:./
2020/12/09 18:19:01 ParseFile error:pkg/mod/golang.org/x/[email protected]/go/packages/packagestest/testdata/groups/two/modules/example.com/extra/v2/me.go:1:16: expected ';', found '.'
Most helpful comment
fix via #418