Skip to content

Commit

Permalink
fix alias type of generic with multi formal params (#1505)
Browse files Browse the repository at this point in the history
* fix alias type of generic with multi formal params
  • Loading branch information
sdghchj authored Mar 20, 2023
1 parent 0524687 commit d2bc3d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit d2bc3d0

Please sign in to comment.