swag icon indicating copy to clipboard operation
swag copied to clipboard

Generics from 1.18 not working

Open nesymno opened this issue 2 years ago • 10 comments

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/[email protected]/di.go:5:13: expected '(', found '[' (and 10 more errors)

In this di.go:5:13:

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

nesymno avatar Sep 06 '22 17:09 nesymno

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/[email protected]/packages.go:168 +0xa8
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0xc0000127b0)
	/home/mrus/.go/pkg/mod/github.com/swaggo/[email protected]/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/[email protected]/parser.go:362 +0x3bf
github.com/swaggo/swag/gen.(*Gen).Build(0xc0001f3920, 0xc0001f4c30)
	/home/mrus/.go/pkg/mod/github.com/swaggo/[email protected]/gen/gen.go:177 +0x5c9
main.initAction(0xc0001c3680?)
	/home/mrus/.go/pkg/mod/github.com/swaggo/[email protected]/cmd/swag/main.go:151 +0x757
github.com/urfave/cli/v2.(*Command).Run(0xc0001cab40, 0xc00020c340)
	/home/mrus/.go/pkg/mod/github.com/urfave/cli/[email protected]/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/[email protected]/app.go:313 +0xb7d
github.com/urfave/cli/v2.(*App).Run(...)
	/home/mrus/.go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:224
main.main()
	/home/mrus/.go/pkg/mod/github.com/swaggo/[email protected]/cmd/swag/main.go:221 +0x5c5

mrusme avatar Sep 10 '22 00:09 mrusme

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

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

FabianMartin avatar Sep 12 '22 11:09 FabianMartin

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

TomHellier avatar Sep 14 '22 19:09 TomHellier

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

mrusme avatar Sep 14 '22 20:09 mrusme

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?

nesymno avatar Sep 16 '22 08:09 nesymno

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

TomHellier avatar Sep 16 '22 08:09 TomHellier

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 avatar Sep 16 '22 09:09 ubogdan

v1.8.6 is now available.

ubogdan avatar Sep 17 '22 20:09 ubogdan

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

have try v1.8.8, master branch.

lowang-bh avatar Nov 25 '22 08:11 lowang-bh

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

sdghchj avatar Dec 01 '22 08:12 sdghchj