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

fix alias type of generic with multi formal params #1505

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (parser *Parser) parseGenericTypeExpr(file *ast.File, typeExpr ast.Expr) (*
case *ast.ArrayType:
case *ast.MapType:
case *ast.FuncType:
case *ast.IndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
name, err := getExtendedGenericFieldType(file, expr, nil)
if err == nil {
if schema, err := parser.getTypeSchema(name, file, false); err == nil {
Expand Down
3 changes: 3 additions & 0 deletions testdata/generics_basic/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type StringStruct struct {
Data string
}

type Foo = web.GenericResponseMulti[types.Post, types.Post]

// @Summary Add a new pet to the store
// @Description get string by ID
// @Accept json
Expand Down Expand Up @@ -46,6 +48,7 @@ func GetPost(w http.ResponseWriter, r *http.Request) {
// @Success 200 {object} web.GenericResponse[types.Post]
// @Success 201 {object} web.GenericResponse[types.Hello]
// @Success 202 {object} web.GenericResponse[types.Field[string]]
// @Success 203 {object} Foo
// @Success 222 {object} web.GenericResponseMulti[types.Post, types.Post]
// @Router /posts-multi/ [post]
func GetPostMulti(w http.ResponseWriter, r *http.Request) {
Expand Down
20 changes: 20 additions & 0 deletions testdata/generics_basic/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"$ref": "#/definitions/web.GenericResponse-types_Field-string"
}
},
"203": {
"description": "Non-Authoritative Information",
"schema": {
"$ref": "#/definitions/api.Foo"
}
},
"222": {
"description": "",
"schema": {
Expand Down Expand Up @@ -182,6 +188,20 @@
}
},
"definitions": {
"api.Foo": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/types.Post"
},
"meta": {
"$ref": "#/definitions/types.Post"
},
"status": {
"type": "string"
}
}
},
"api.Response-api_StringStruct-types_Field-int": {
"type": "object",
"properties": {
Expand Down