diff --git a/generics_test.go b/generics_test.go index deb5b75f5..d62f3898c 100644 --- a/generics_test.go +++ b/generics_test.go @@ -106,11 +106,12 @@ func TestParseGenericsNames(t *testing.T) { func TestParseGenericsPackageAlias(t *testing.T) { t.Parallel() - searchDir := "testdata/generics_package_alias" + searchDir := "testdata/generics_package_alias/internal" expected, err := os.ReadFile(filepath.Join(searchDir, "expected.json")) assert.NoError(t, err) p := New() + p.ParseDependency = true err = p.ParseAPI(searchDir, mainAPIFile, defaultParseDepth) assert.NoError(t, err) b, err := json.MarshalIndent(p.swagger, "", " ") diff --git a/packages.go b/packages.go index ff61ef49c..361dd9344 100644 --- a/packages.go +++ b/packages.go @@ -287,76 +287,93 @@ func (pkgDefs *PackagesDefinitions) loadExternalPackage(importPath string) error // findPackagePathFromImports finds out the package path of a package via ranging imports of an ast.File // @pkg the name of the target package // @file current ast.File in which to search imports -// @fuzzy search for the package path that the last part matches the @pkg if true -// @return the package path of a package of @pkg. -func (pkgDefs *PackagesDefinitions) findPackagePathFromImports(pkg string, file *ast.File, fuzzy bool) string { +// @return the package paths of a package of @pkg. +func (pkgDefs *PackagesDefinitions) findPackagePathFromImports(pkg string, file *ast.File) (matchedPkgPaths, externalPkgPaths []string) { if file == nil { - return "" + return } if strings.ContainsRune(pkg, '.') { pkg = strings.Split(pkg, ".")[0] } - hasAnonymousPkg := false - matchLastPathPart := func(pkgPath string) bool { paths := strings.Split(pkgPath, "/") - return paths[len(paths)-1] == pkg } // prior to match named package for _, imp := range file.Imports { + path := strings.Trim(imp.Path.Value, `"`) if imp.Name != nil { if imp.Name.Name == pkg { - return strings.Trim(imp.Path.Value, `"`) + // if name match, break loop and return + _, ok := pkgDefs.packages[path] + if ok { + matchedPkgPaths = []string{path} + externalPkgPaths = nil + } else { + externalPkgPaths = []string{path} + matchedPkgPaths = nil + } + break + } else if imp.Name.Name == "_" && len(pkg) > 0 { + //for unused types + pd, ok := pkgDefs.packages[path] + if ok { + if pd.Name == pkg { + matchedPkgPaths = append(matchedPkgPaths, path) + } + } else if matchLastPathPart(path) { + externalPkgPaths = append(externalPkgPaths, path) + } + } else if imp.Name.Name == "." && len(pkg) == 0 { + _, ok := pkgDefs.packages[path] + if ok { + matchedPkgPaths = append(matchedPkgPaths, path) + } else if len(pkg) == 0 || matchLastPathPart(path) { + externalPkgPaths = append(externalPkgPaths, path) + } } - - if imp.Name.Name == "_" { - hasAnonymousPkg = true + } else if pkgDefs.packages != nil && len(pkg) > 0 { + pd, ok := pkgDefs.packages[path] + if ok { + if pd.Name == pkg { + matchedPkgPaths = append(matchedPkgPaths, path) + } + } else if matchLastPathPart(path) { + externalPkgPaths = append(externalPkgPaths, path) } - - continue } + } - if pkgDefs.packages != nil { - path := strings.Trim(imp.Path.Value, `"`) - if fuzzy { - if matchLastPathPart(path) { - return path - } + if len(pkg) == 0 || file.Name.Name == pkg { + matchedPkgPaths = append(matchedPkgPaths, pkgDefs.files[file].PackagePath) + } - continue - } + return +} - pd, ok := pkgDefs.packages[path] - if ok && pd.Name == pkg { - return path - } +func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths, externalPkgPaths []string, name string, parseDependency bool) (typeDef *TypeSpecDef) { + for _, pkgPath := range matchedPkgPaths { + typeDef = pkgDefs.findTypeSpec(pkgPath, name) + if typeDef != nil { + return typeDef } } - // match unnamed package - if hasAnonymousPkg && pkgDefs.packages != nil { - for _, imp := range file.Imports { - if imp.Name == nil { - continue - } - if imp.Name.Name == "_" { - path := strings.Trim(imp.Path.Value, `"`) - if fuzzy { - if matchLastPathPart(path) { - return path - } - } else if pd, ok := pkgDefs.packages[path]; ok && pd.Name == pkg { - return path + if parseDependency { + for _, pkgPath := range externalPkgPaths { + if err := pkgDefs.loadExternalPackage(pkgPath); err == nil { + typeDef = pkgDefs.findTypeSpec(pkgPath, name) + if typeDef != nil { + return typeDef } } } } - return "" + return typeDef } // FindTypeSpec finds out TypeSpecDef of a type by typeName @@ -379,23 +396,8 @@ func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File return typeDef } - pkgPath := pkgDefs.findPackagePathFromImports(parts[0], file, false) - if len(pkgPath) == 0 { - // check if the current package - if parts[0] == file.Name.Name { - pkgPath = pkgDefs.files[file].PackagePath - } else if parseDependency { - // take it as an external package, needs to be loaded - if pkgPath = pkgDefs.findPackagePathFromImports(parts[0], file, true); len(pkgPath) > 0 { - if err := pkgDefs.loadExternalPackage(pkgPath); err != nil { - return nil - } - } - } - } - - typeDef = pkgDefs.findTypeSpec(pkgPath, parts[1]) - + pkgPaths, externalPkgPaths := pkgDefs.findPackagePathFromImports(parts[0], file) + typeDef = pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, parts[1], parseDependency) return pkgDefs.parametrizeGenericType(file, typeDef, typeName, parseDependency) } @@ -410,25 +412,11 @@ func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File return typeDef } - typeDef = func() *TypeSpecDef { - name := parts[0] - typeDef, ok := pkgDefs.uniqueDefinitions[fullTypeName(file.Name.Name, name)] - if ok { - return typeDef - } - typeDef = pkgDefs.findTypeSpec(pkgDefs.files[file].PackagePath, name) - if typeDef != nil { - return typeDef - } - for _, imp := range file.Imports { - if imp.Name != nil && imp.Name.Name == "." { - typeDef = pkgDefs.findTypeSpec(strings.Trim(imp.Path.Value, `"`), name) - if typeDef != nil { - break - } - } - } - return typeDef - }() + name := parts[0] + typeDef, ok = pkgDefs.uniqueDefinitions[fullTypeName(file.Name.Name, name)] + if !ok { + pkgPaths, externalPkgPaths := pkgDefs.findPackagePathFromImports("", file) + typeDef = pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, name, parseDependency) + } return pkgDefs.parametrizeGenericType(file, typeDef, typeName, parseDependency) } diff --git a/testdata/generics_package_alias/expected.json b/testdata/generics_package_alias/expected.json deleted file mode 100644 index ec2c51aa1..000000000 --- a/testdata/generics_package_alias/expected.json +++ /dev/null @@ -1,228 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "contact": {} - }, - "paths": { - "/api1": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path1_v1_ProductDto" - } - } - } - } - }, - "/api2": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/ListResultV1-ProductDtoV1" - } - } - } - } - }, - "/api3": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path2_v1_ProductDto" - } - } - } - } - }, - "/api4": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/ListResultV2-ProductDtoV2" - } - } - } - } - }, - "/api5": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path2_v1_ProductDto" - } - } - } - } - }, - "/api6": { - "post": { - "description": "Create a new movie production", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Create movie", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/ListResultV1-ProductDtoV2" - } - } - } - } - } - }, - "definitions": { - "ListResultV1-ProductDtoV1": { - "type": "object", - "properties": { - "items11": { - "type": "array", - "items": { - "$ref": "#/definitions/ProductDtoV1" - } - } - } - }, - "ListResultV1-ProductDtoV2": { - "type": "object", - "properties": { - "items11": { - "type": "array", - "items": { - "$ref": "#/definitions/ProductDtoV2" - } - } - } - }, - "ListResultV2-ProductDtoV2": { - "type": "object", - "properties": { - "items22": { - "type": "array", - "items": { - "$ref": "#/definitions/ProductDtoV2" - } - } - } - }, - "ProductDtoV1": { - "type": "object", - "properties": { - "name11": { - "type": "string" - } - } - }, - "ProductDtoV2": { - "type": "object", - "properties": { - "name22": { - "type": "string" - } - } - }, - "github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path1_v1_ProductDto": { - "type": "object", - "properties": { - "items1": { - "type": "array", - "items": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ProductDto" - } - } - } - }, - "github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path2_v1_ProductDto": { - "type": "object", - "properties": { - "items1": { - "type": "array", - "items": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path2_v1.ProductDto" - } - } - } - }, - "github_com_swaggo_swag_testdata_generics_package_alias_path1_v1.ProductDto": { - "type": "object", - "properties": { - "name1": { - "type": "string" - } - } - }, - "github_com_swaggo_swag_testdata_generics_package_alias_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_path2_v1_ProductDto": { - "type": "object", - "properties": { - "items2": { - "type": "array", - "items": { - "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_path2_v1.ProductDto" - } - } - } - }, - "github_com_swaggo_swag_testdata_generics_package_alias_path2_v1.ProductDto": { - "type": "object", - "properties": { - "name2": { - "type": "string" - } - } - } - } -} \ No newline at end of file diff --git a/testdata/generics_package_alias/external/external1/external.go b/testdata/generics_package_alias/external/external1/external.go new file mode 100644 index 000000000..58e0848e6 --- /dev/null +++ b/testdata/generics_package_alias/external/external1/external.go @@ -0,0 +1,6 @@ +package external1 + +type Customer struct { + Name string + Age int +} diff --git a/testdata/generics_package_alias/external/external2/external.go b/testdata/generics_package_alias/external/external2/external.go new file mode 100644 index 000000000..2a0771c6e --- /dev/null +++ b/testdata/generics_package_alias/external/external2/external.go @@ -0,0 +1,6 @@ +package external2 + +type Customer struct { + Name string + Age int +} diff --git a/testdata/generics_package_alias/external/external3/external.go b/testdata/generics_package_alias/external/external3/external.go new file mode 100644 index 000000000..a70e5ccc6 --- /dev/null +++ b/testdata/generics_package_alias/external/external3/external.go @@ -0,0 +1,6 @@ +package external3 + +type Customer struct { + Name string + Age int +} diff --git a/testdata/generics_package_alias/external/external4/external.go b/testdata/generics_package_alias/external/external4/external.go new file mode 100644 index 000000000..2d050bde9 --- /dev/null +++ b/testdata/generics_package_alias/external/external4/external.go @@ -0,0 +1,6 @@ +package external4 + +type Customer struct { + Name string + Age int +} diff --git a/testdata/generics_package_alias/api/api1.go b/testdata/generics_package_alias/internal/api/api1.go similarity index 72% rename from testdata/generics_package_alias/api/api1.go rename to testdata/generics_package_alias/internal/api/api1.go index cf443df62..4152ab313 100644 --- a/testdata/generics_package_alias/api/api1.go +++ b/testdata/generics_package_alias/internal/api/api1.go @@ -1,7 +1,7 @@ package api import ( - myv1 "github.com/swaggo/swag/testdata/generics_package_alias/path1/v1" + myv1 "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" ) // @Summary Create movie @@ -9,8 +9,8 @@ import ( // @Accept json // @Produce json // @Success 200 {object} myv1.ListResult[myv1.ProductDto] "" -// @Router /api1 [post] -func CreateMovie1() { +// @Router /api01 [post] +func CreateMovie01() { _ = myv1.ListResult[myv1.ProductDto]{} } @@ -19,7 +19,7 @@ func CreateMovie1() { // @Accept json // @Produce json // @Success 200 {object} myv1.RenamedListResult[myv1.RenamedProductDto] "" -// @Router /api2 [post] -func CreateMovie2() { +// @Router /api02 [post] +func CreateMovie02() { _ = myv1.ListResult[myv1.ProductDto]{} } diff --git a/testdata/generics_package_alias/api/api2.go b/testdata/generics_package_alias/internal/api/api2.go similarity index 71% rename from testdata/generics_package_alias/api/api2.go rename to testdata/generics_package_alias/internal/api/api2.go index 9ffdd3911..d0cb09610 100644 --- a/testdata/generics_package_alias/api/api2.go +++ b/testdata/generics_package_alias/internal/api/api2.go @@ -1,8 +1,8 @@ package api import ( - myv1 "github.com/swaggo/swag/testdata/generics_package_alias/path1/v1" - myv2 "github.com/swaggo/swag/testdata/generics_package_alias/path2/v1" + myv1 "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" + myv2 "github.com/swaggo/swag/testdata/generics_package_alias/internal/path2/v1" ) // @Summary Create movie @@ -10,8 +10,8 @@ import ( // @Accept json // @Produce json // @Success 200 {object} myv2.ListResult[myv2.ProductDto] "" -// @Router /api3 [post] -func CreateMovie3() { +// @Router /api03 [post] +func CreateMovie03() { _ = myv2.ListResult[myv2.ProductDto]{} } @@ -20,8 +20,8 @@ func CreateMovie3() { // @Accept json // @Produce json // @Success 200 {object} myv2.RenamedListResult[myv2.RenamedProductDto] "" -// @Router /api4 [post] -func CreateMovie4() { +// @Router /api04 [post] +func CreateMovie04() { _ = myv2.ListResult[myv2.ProductDto]{} } @@ -30,8 +30,8 @@ func CreateMovie4() { // @Accept json // @Produce json // @Success 200 {object} myv1.ListResult[myv2.ProductDto] "" -// @Router /api5 [post] -func CreateMovie5() { +// @Router /api05 [post] +func CreateMovie05() { _ = myv1.ListResult[myv2.ProductDto]{} } @@ -40,7 +40,7 @@ func CreateMovie5() { // @Accept json // @Produce json // @Success 200 {object} myv1.RenamedListResult[myv2.RenamedProductDto] "" -// @Router /api6 [post] -func CreateMovie6() { +// @Router /api06 [post] +func CreateMovie06() { _ = myv1.ListResult[myv2.ProductDto]{} } diff --git a/testdata/generics_package_alias/internal/api/api3.go b/testdata/generics_package_alias/internal/api/api3.go new file mode 100644 index 000000000..f269d734f --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api3.go @@ -0,0 +1,46 @@ +package api + +import ( + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" + . "github.com/swaggo/swag/testdata/generics_package_alias/internal/path2/v1" +) + +// @Summary Create movie +// @Description models imported from an unnamed package +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[v1.ProductDto] "" +// @Router /api07 [post] +func CreateMovie07() { + var _ ProductDto +} + +// @Summary Create movie +// @Description models imported from an unnamed package +// @Accept json +// @Produce json +// @Success 200 {object} ListResult[ProductDto] "" +// @Router /api08 [post] +func CreateMovie08() { + var _ ProductDto +} + +// @Summary Create movie +// @Description models imported from an unnamed package +// @Accept json +// @Produce json +// @Success 200 {object} ListResult[v1.ProductDto] "" +// @Router /api09 [post] +func CreateMovie09() { + var _ ProductDto +} + +// @Summary Create movie +// @Description models imported from an unnamed package +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[ProductDto] "" +// @Router /api10 [post] +func CreateMovie10() { + var _ ProductDto +} diff --git a/testdata/generics_package_alias/internal/api/api4.go b/testdata/generics_package_alias/internal/api/api4.go new file mode 100644 index 000000000..9a851ba04 --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api4.go @@ -0,0 +1,16 @@ +package api + +import ( + "github.com/swaggo/swag/testdata/generics_package_alias/external/external1" + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" +) + +// @Summary Create movie +// @Description models imported from an external package +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[external1.Customer] "" +// @Router /api11 [post] +func CreateMovie11() { + var _ external1.Customer +} diff --git a/testdata/generics_package_alias/internal/api/api5.go b/testdata/generics_package_alias/internal/api/api5.go new file mode 100644 index 000000000..c15272709 --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api5.go @@ -0,0 +1,16 @@ +package api + +import ( + myexternal "github.com/swaggo/swag/testdata/generics_package_alias/external/external2" + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" +) + +// @Summary Create movie +// @Description models imported from a named external package +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[myexternal.Customer] "" +// @Router /api12 [post] +func CreateMovie12() { + var _ myexternal.Customer +} diff --git a/testdata/generics_package_alias/internal/api/api6.go b/testdata/generics_package_alias/internal/api/api6.go new file mode 100644 index 000000000..5d1d27072 --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api6.go @@ -0,0 +1,16 @@ +package api + +import ( + . "github.com/swaggo/swag/testdata/generics_package_alias/external/external3" + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" +) + +// @Summary Create movie +// @Description models from an external package imported by mode dot +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[Customer] "" +// @Router /api13 [post] +func CreateMovie13() { + var _ Customer +} diff --git a/testdata/generics_package_alias/internal/api/api7.go b/testdata/generics_package_alias/internal/api/api7.go new file mode 100644 index 000000000..5a5ad72c4 --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api7.go @@ -0,0 +1,16 @@ +package api + +import ( + _ "github.com/swaggo/swag/testdata/generics_package_alias/external/external4" + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" +) + +// @Summary Create movie +// @Description models imported from an unnamed external package +// @Accept json +// @Produce json +// @Success 200 {object} v1.ListResult[external4.Customer] "" +// @Router /api14 [post] +func CreateMovie14() { + +} diff --git a/testdata/generics_package_alias/internal/api/api8.go b/testdata/generics_package_alias/internal/api/api8.go new file mode 100644 index 000000000..bcdd94715 --- /dev/null +++ b/testdata/generics_package_alias/internal/api/api8.go @@ -0,0 +1,16 @@ +package api + +import ( + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path1/v1" + _ "github.com/swaggo/swag/testdata/generics_package_alias/internal/path2/v1" +) + +// @Summary Create movie +// @Description model from a package whose name conflicts with other packages +// @Accept json +// @Produce json +// @Success 200 {object} v1.UniqueProduct "" +// @Router /api15 [post] +func CreateMovie15() { + +} diff --git a/testdata/generics_package_alias/internal/expected.json b/testdata/generics_package_alias/internal/expected.json new file mode 100644 index 000000000..2f6c85f52 --- /dev/null +++ b/testdata/generics_package_alias/internal/expected.json @@ -0,0 +1,515 @@ +{ + "swagger": "2.0", + "info": { + "contact": {} + }, + "paths": { + "/api01": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1_ProductDto" + } + } + } + } + }, + "/api02": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ListResultV1-ProductDtoV1" + } + } + } + } + }, + "/api03": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto" + } + } + } + } + }, + "/api04": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ListResultV2-ProductDtoV2" + } + } + } + } + }, + "/api05": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto" + } + } + } + } + }, + "/api06": { + "post": { + "description": "Create a new movie production", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/ListResultV1-ProductDtoV2" + } + } + } + } + }, + "/api07": { + "post": { + "description": "models imported from an unnamed package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1_ProductDto" + } + } + } + } + }, + "/api08": { + "post": { + "description": "models imported from an unnamed package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto" + } + } + } + } + }, + "/api09": { + "post": { + "description": "models imported from an unnamed package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1_ProductDto" + } + } + } + } + }, + "/api10": { + "post": { + "description": "models imported from an unnamed package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto" + } + } + } + } + }, + "/api11": { + "post": { + "description": "models imported from an external package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external1_Customer" + } + } + } + } + }, + "/api12": { + "post": { + "description": "models imported from a named external package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external2_Customer" + } + } + } + } + }, + "/api13": { + "post": { + "description": "models from an external package imported by mode dot", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external3_Customer" + } + } + } + } + }, + "/api14": { + "post": { + "description": "models imported from an unnamed external package", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external4_Customer" + } + } + } + } + }, + "/api15": { + "post": { + "description": "model from a package whose name conflicts with other packages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Create movie", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.UniqueProduct" + } + } + } + } + } + }, + "definitions": { + "ListResultV1-ProductDtoV1": { + "type": "object", + "properties": { + "items11": { + "type": "array", + "items": { + "$ref": "#/definitions/ProductDtoV1" + } + } + } + }, + "ListResultV1-ProductDtoV2": { + "type": "object", + "properties": { + "items11": { + "type": "array", + "items": { + "$ref": "#/definitions/ProductDtoV2" + } + } + } + }, + "ListResultV2-ProductDtoV2": { + "type": "object", + "properties": { + "items22": { + "type": "array", + "items": { + "$ref": "#/definitions/ProductDtoV2" + } + } + } + }, + "ProductDtoV1": { + "type": "object", + "properties": { + "name11": { + "type": "string" + } + } + }, + "ProductDtoV2": { + "type": "object", + "properties": { + "name22": { + "type": "string" + } + } + }, + "external1.Customer": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "external2.Customer": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "external3.Customer": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "external4.Customer": { + "type": "object", + "properties": { + "age": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external1_Customer": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/external1.Customer" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external2_Customer": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/external2.Customer" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external3_Customer": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/external3.Customer" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-external4_Customer": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/external4.Customer" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1_ProductDto": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ProductDto" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto": { + "type": "object", + "properties": { + "items1": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ProductDto" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ProductDto": { + "type": "object", + "properties": { + "name1": { + "type": "string" + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1_ProductDto": { + "type": "object", + "properties": { + "items2": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path1_v1.ProductDto" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ListResult-github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1_ProductDto": { + "type": "object", + "properties": { + "items2": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ProductDto" + } + } + } + }, + "github_com_swaggo_swag_testdata_generics_package_alias_internal_path2_v1.ProductDto": { + "type": "object", + "properties": { + "name2": { + "type": "string" + } + } + }, + "v1.UniqueProduct": { + "type": "object", + "properties": { + "unique_product_name": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/testdata/generics_package_alias/main.go b/testdata/generics_package_alias/internal/main.go similarity index 100% rename from testdata/generics_package_alias/main.go rename to testdata/generics_package_alias/internal/main.go diff --git a/testdata/generics_package_alias/path1/v1/product.go b/testdata/generics_package_alias/internal/path1/v1/product.go similarity index 100% rename from testdata/generics_package_alias/path1/v1/product.go rename to testdata/generics_package_alias/internal/path1/v1/product.go diff --git a/testdata/generics_package_alias/path2/v1/product.go b/testdata/generics_package_alias/internal/path2/v1/product.go similarity index 79% rename from testdata/generics_package_alias/path2/v1/product.go rename to testdata/generics_package_alias/internal/path2/v1/product.go index 754ddb591..14a1b1107 100644 --- a/testdata/generics_package_alias/path2/v1/product.go +++ b/testdata/generics_package_alias/internal/path2/v1/product.go @@ -15,3 +15,7 @@ type RenamedProductDto struct { type RenamedListResult[T any] struct { Items22 []T `json:"items22,omitempty"` } // @name ListResultV2 + +type UniqueProduct struct { + UniqueProductName string `json:"unique_product_name"` +}