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
Describe the bug Don't working properly with parametric generics panic: interface conversion: ast.Expr is *ast.ArrayType, not *ast.StructType
panic: interface conversion: ast.Expr is *ast.ArrayType, not *ast.StructType
To Reproduce Steps to reproduce the behavior:
main.go
Content: pgjson.go
pgjson.go
package pgjson import ( "database/sql/driver" "encoding/json" "errors" "fmt" ) func Scan(dest interface{}, value interface{}) error { switch t := value.(type) { case string: return json.Unmarshal([]byte(t), dest) case []byte: return json.Unmarshal(t, dest) default: return errors.New(fmt.Sprint("failed to unmarshal JSON value:", value)) } } func Value(src interface{}) (driver.Value, error) { value, err := json.Marshal(src) return string(json.RawMessage(value)), err } type Slice[T any] []T func (j *Slice[any]) Scan(value interface{}) error { return Scan(j, value) } func (j Slice[any]) Value() (driver.Value, error) { if len(j) == 0 { return "[]", nil } return Value(j) }
package main import "main/pgjson" type controller struct{} type Destination struct { Images pgjson.Slice[string] `json:"images,omitempty"` } // @name Destination type doSomethingBody struct { } type doSomethingResponse struct { *Destination } // @ID DoSomething. // @Summary Do something. // @Accept application/json // @Produce application/json // @Param fields body doSomethingBody true "data" // @Success 200 {object} doSomethingResponse // @Failure 422,500 {object} Error // @Router /doSomething [POST] func (c *controller) doSomething() {} func main() { c := &controller{} c.doSomething() }
Expected behavior Should generate docs correctly without any errors
Screenshots
Your swag version latest (1.8.6)
Your go version go version go1.18 windows/amd64
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered:
It can be fixed by adding swaggertype:"array,string" as a tag to structure field. But is there a way to implement it automatically by parsing generic instantiation type parameter?
swaggertype:"array,string"
Sorry, something went wrong.
fix issue #1346 about generics
424bbbf
Signed-off-by: sdghchj <chengjin@cmiot.chinamobile.com>
56c074e
fix issue #1346 about generics (#1348)
04c699c
* fix issue #1346 about generics Signed-off-by: sdghchj <chengjin@cmiot.chinamobile.com> * fix issue #1346 about generics Signed-off-by: sdghchj <chengjin@cmiot.chinamobile.com> Co-authored-by: sdghchj <chengjin@cmiot.chinamobile.com>
No branches or pull requests
Describe the bug
Don't working properly with parametric generics
panic: interface conversion: ast.Expr is *ast.ArrayType, not *ast.StructType
To Reproduce
Steps to reproduce the behavior:
main.go
with the next content (listed below)Content:
pgjson.go
main.go
Expected behavior
Should generate docs correctly without any errors
Screenshots

Your swag version
latest (1.8.6)
Your go version
go version go1.18 windows/amd64
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: