swag icon indicating copy to clipboard operation
swag copied to clipboard

go 1.18 generics support issue

Open liveever opened this issue 2 years ago • 17 comments

Describe the bug go 1.18 generics not supported

To Reproduce type Result2 [T any] struct { Data T json:"data" Meta string json:"meta" }

The T type could not be recognized

Expected behavior The T type could be recognized

Screenshots If applicable, add screenshots to help explain your problem.

Your swag version 1.8.1

Your go version 1.18

liveever avatar Mar 31 '22 04:03 liveever

My bad, the binary was built with go version go1.17.8 linux/amd64 which doesn't support generics.

I won't do a release only for this , please use the following command to build It locally go install github.com/swaggo/swag/cmd/[email protected]

ubogdan avatar Mar 31 '22 11:03 ubogdan

@ubogdan How do I use this feature? I updated to the version that commented above, but still the error persists: :cannot find type definition: T

wagnerww avatar Mar 31 '22 13:03 wagnerww

What feature?

ubogdan avatar Mar 31 '22 14:03 ubogdan

@ubogdan How do I generate the documentation with swag for this: type Result2 [T any] struct { Data T json:"data" Meta string json:"meta" }

you mentioned to install the version below, but how do I get the T parameter go install github.com/swaggo/swag/cmd/[email protected]

wagnerww avatar Mar 31 '22 14:03 wagnerww

GoLang 1.18 comes with many changes, and swag is not ready yet, as you may see.

If you need this feature, please feel free and contribute with a PR, and I will be more than happy to assist you with a CR.

ubogdan avatar Mar 31 '22 15:03 ubogdan

@ubogdan - do we have any specific issues created for generics support? I may be able to tackle some a smaller piece at a time if this were broken out... Or is this the only generics/1.18 issue at the moment?

ipointer-netrise avatar Apr 07 '22 21:04 ipointer-netrise

would be really nice to get support for 1.18! I have 1 function in my code. Our solution at the moment is to remove this generic function until this pkg is ready

image

Output error:

swag init -g cmd/api/main.go
2022/04/07 18:56:36 Generate swagger docs....
2022/04/07 18:56:36 Generate general API Info, search dir:./
2022/04/07 18:56:36 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/username/path/to/project
2022/04/07 18:56:36 ParseFile error:pkg/helpers/common.go:3:10: expected '(', found '['
make: *** [swagger] Error 1

Maybe we can add a temporary hack so that users could ignore certain file patterns ? https://github.com/swaggo/swag/blob/32f02b99260db21a5bf0c28757a89e015682c574/parser.go#L1393

ghoshabhi avatar Apr 08 '22 02:04 ghoshabhi

would be really nice to get support for 1.18! I have 1 function in my code. Our solution at the moment is to remove this generic function until this pkg is ready

There is no support for generics at all. If someone here intends to contribute, I will be more than happy to assist you with a CR.

Please remember to open a feature request and document what exactly is going to be implemented, We need a way to track these changes.

ubogdan avatar Apr 08 '22 10:04 ubogdan

would be really nice to get support for 1.18! I have 1 function in my code. Our solution at the moment is to remove this generic function until this pkg is ready

Unfortunately, this is the only option for now.

ubogdan avatar Apr 08 '22 10:04 ubogdan

would be really nice to get support for 1.18! I have 1 function in my code. Our solution at the moment is to remove this generic function until this pkg is ready

Unfortunately, this is the only option for now.

Any updates on this one ? I think one generic function should not break the whole pipeline after almost 3 months of generics being released and an open PR about that topic. I would prioritize that.

eljoth avatar Jun 03 '22 05:06 eljoth

@eljoth Don't you think it would be more helpful to contribute instead of criticizing? This is an open-source project, and all the features come from community contributions.

ubogdan avatar Jun 14 '22 13:06 ubogdan

@ubogdan I did not want to offend and sound that harsh. It just seemed for me that there is no prio to work in that.

eljoth avatar Jun 14 '22 13:06 eljoth

@ubogdan Is there a planned release for the features @FabianMartin added?

I'll fork and do a release myself otherwise since it's much needed in my project at the moment 😅

johan-lejdung avatar Aug 22 '22 15:08 johan-lejdung

We will release a new version in the next few days.

ubogdan avatar Aug 23 '22 11:08 ubogdan

Thank you for the response @ubogdan. I couldn't help myself and I forked to repo to be able to try it against our codebase.

Seems like there still are some issues with nested generic fields, I've raised the following issue https://github.com/swaggo/swag/issues/1304

@FabianMartin was this use-case expected to be covered by your contributions? Or am I using it in an unsupported way?

johan-lejdung avatar Aug 23 '22 11:08 johan-lejdung

This should be possible to close when a new release is done, right?

johan-lejdung avatar Sep 19 '22 13:09 johan-lejdung

v1.8.6 has been released.

ubogdan avatar Sep 19 '22 13:09 ubogdan