From d2bc3d0ce44dd8b810eda5e435e67e6ded6e2390 Mon Sep 17 00:00:00 2001 From: sdghchj Date: Mon, 20 Mar 2023 16:16:20 +0800 Subject: [PATCH] fix alias type of generic with multi formal params (#1505) * fix alias type of generic with multi formal params --- generics.go | 2 +- testdata/generics_basic/api/api.go | 3 +++ testdata/generics_basic/expected.json | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/generics.go b/generics.go index 276c1f349..8a64cd389 100644 --- a/generics.go +++ b/generics.go @@ -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 { diff --git a/testdata/generics_basic/api/api.go b/testdata/generics_basic/api/api.go index 381fe5446..629d4ecb6 100644 --- a/testdata/generics_basic/api/api.go +++ b/testdata/generics_basic/api/api.go @@ -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 @@ -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) { diff --git a/testdata/generics_basic/expected.json b/testdata/generics_basic/expected.json index b1d362497..6eca46ed9 100644 --- a/testdata/generics_basic/expected.json +++ b/testdata/generics_basic/expected.json @@ -49,6 +49,12 @@ "$ref": "#/definitions/web.GenericResponse-types_Field-string" } }, + "203": { + "description": "Non-Authoritative Information", + "schema": { + "$ref": "#/definitions/api.Foo" + } + }, "222": { "description": "", "schema": { @@ -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": {