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

Generics from 1.18 not working #1321

Open
nesymno opened this issue Sep 6, 2022 · 10 comments
Open

Generics from 1.18 not working #1321

nesymno opened this issue Sep 6, 2022 · 10 comments

Comments

@nesymno
Copy link

nesymno commented Sep 6, 2022

I'm using a package https://github.com/samber/do to implement DI in my project.
This package uses at least 1.18 and generics. And when I'm trying to swag init --pd it doesn't work.

cd cmd/api && swag fmt && swag init --pd
2022/09/06 20:13:23 Formating code.... 
2022/09/06 20:13:23 Format API Info, search dir:./
2022/09/06 20:13:24 Generate swagger docs....
2022/09/06 20:13:24 Generate general API Info, search dir:./
2022/09/06 20:14:13 ParseFile error:/Users/weijinnx/go/pkg/mod/github.com/samber/do@v1.2.1/di.go:5:13: expected '(', found '[' (and 10 more errors)

In this di.go:5:13:

Знімок екрана 2022-09-06 о 20 20 13

@mrusme
Copy link

mrusme commented Sep 10, 2022

I did some research. This issue was mentioned before here, here, and here and it seems to have been implemented here, and released here.

However, having that said, I'm also struggling to get it working nevertheless:

swag init --pd -g v1/v1.go                                                                                                                                        ⇡ master 47m ⬡
2022/09/09 19:30:17 Generate swagger docs....
2022/09/09 19:30:17 Generate general API Info, search dir:./
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x87de48]

goroutine 1 [running]:
github.com/swaggo/swag.(*PackagesDefinitions).parseFunctionScopedTypesFromFile(0xc0000127b0, 0xc000503100, {0xc0002727c8, 0x15}, 0xc0051f3f50)
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:168 +0xa8
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0xc0000127b0)
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:110 +0xc9
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc0001fa2a0, {0xc0001edfd0?, 0x1?, 0x0?}, {0x7ffc0877aa0f?, 0x8?}, 0x64)
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/parser.go:362 +0x3bf
github.com/swaggo/swag/gen.(*Gen).Build(0xc0001f3920, 0xc0001f4c30)
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/gen/gen.go:177 +0x5c9
main.initAction(0xc0001c3680?)
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:151 +0x757
github.com/urfave/cli/v2.(*Command).Run(0xc0001cab40, 0xc00020c340)
	/home/mrus/.go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x5dc
github.com/urfave/cli/v2.(*App).RunContext(0xc0001b5860, {0xa57690?, 0xc000032140}, {0xc0000240a0, 0x5, 0x5})
	/home/mrus/.go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0xb7d
github.com/urfave/cli/v2.(*App).Run(...)
	/home/mrus/.go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
	/home/mrus/.go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:221 +0x5c5

@FabianMartin
Copy link
Contributor

try the master branch of swaggo. You can install it with the following command.

go install github.com/swaggo/swag/cmd/swag@master

@TomHellier
Copy link

@mrusme - looks like the fix for that bug made it in #1310

@mrusme
Copy link

mrusme commented Sep 14, 2022

@TomHellier thank you for pointing it out / linking the PR!

@nesymno
Copy link
Author

nesymno commented Sep 16, 2022

try the master branch of swaggo. You can install it with the following command.

go install github.com/swaggo/swag/cmd/swag@master

Thanks so much, it works! And, as I understood, the fix will be in the nearest release, isn't it?

@TomHellier
Copy link

Yes my understanding is this repo gets monthly releases and the maintainer will be doing one soon

@ubogdan
Copy link
Contributor

ubogdan commented Sep 16, 2022

Yes my understanding is this repo gets monthly releases and the maintainer will be doing one soon

The idea of having a 1-month time frame between releases is that the new version will get enough window to be tested and to have time to write fixes for known bugs.

@ubogdan
Copy link
Contributor

ubogdan commented Sep 17, 2022

v1.8.6 is now available.

@lowang-bh
Copy link
Contributor

why same error to me:
pkg/common/util.go:29:14: expected '(', found '['

have try v1.8.8, master branch.

@sdghchj
Copy link
Member

sdghchj commented Dec 1, 2022

why same error to me: pkg/common/util.go:29:14: expected '(', found '['

have try v1.8.8, master branch.

Maybe your swag is compiled by go lower than v1.8

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

No branches or pull requests

7 participants