swag icon indicating copy to clipboard operation
swag copied to clipboard

generic type support

Open hicker-kin opened this issue 2 years ago • 11 comments
trafficstars

my golang project use generic type, when i use swag to init api docs, occur error: don't recognise "[]" in generic function or param

hicker-kin avatar Aug 24 '23 09:08 hicker-kin

Encountering the same problem

qmdx avatar Aug 28 '23 13:08 qmdx

using generic type like this, it works

type Result[T any] struct {
	Code     int64  `json:"code"`                                
	ErrorMsg string `json:"err_msg,omitempty"`     
	Data     T      `json:"data,omitempty" swaggerignore:"true"`
}

// @Response 200 {object} res.Result{data=xxx}

marsberrys avatar Sep 12 '23 13:09 marsberrys

oh~ I found now swag is support generic type, the using demo: https://github.com/swaggo/swag/blob/master/testdata/generics_nested/api/api.go

marsberrys avatar Sep 12 '23 13:09 marsberrys

oh~ I found now swag is support generic type, the using demo: https://github.com/swaggo/swag/blob/master/testdata/generics_nested/api/api.go

Maybe we can just add a comprehensive example in the README/examples section?

rpedrodasilva10 avatar Nov 03 '23 20:11 rpedrodasilva10

@ubogdan can we close this issue? Also, do you know if there's any way we could improve this flow of closing issues? I'm seeking issues or features to contribute to but a lot of times I've seen that they were already done but the issue is not closed. Thanks for your help.

rpedrodasilva10 avatar Nov 07 '23 09:11 rpedrodasilva10