Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swag init error building doc.go due to missing package in /golang.org/x/tools/go/loader/testdata/badpkgdecl.go #417

Closed
bruceadowns opened this issue Jun 25, 2019 · 9 comments
Assignees
Labels
Milestone

Comments

@bruceadowns
Copy link
Contributor

Describe the bug
swag init is failing with latest change related to go modules.

To Reproduce
Steps to reproduce the behavior:

  1. go get github.com/swaggo/swag/cmd/swag

  2. run swag init

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

@easonlin404
Copy link
Member

fix via #418

@easonlin404
Copy link
Member

@bruceadowns thanks for you report the issue. 👍

@979163895
Copy link

979163895 commented Apr 20, 2020

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

@979163895
Copy link

@easonlin404

@tuxnavell
Copy link

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.

@KimSoungRyoul
Copy link

KimSoungRyoul commented Apr 30, 2020

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

we should run 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

@tuxnavell
Copy link

tuxnavell commented Apr 30, 2020

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

@jiere
Copy link

jiere commented Jun 26, 2020

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'

@pkqsun
Copy link

pkqsun commented Dec 9, 2020

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 '.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants