Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## v0.4.1 - 2025-02-08

### Fixed

- Fixed failed generation when the interface parameter has map type which contains a named type.

## v0.4.0 - 2025-02-08

### Breaking Changes
Expand Down
3 changes: 3 additions & 0 deletions internal/codegen/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TypeToString(pkg *types.Package, t types.Type) string {
case *types.Slice:
return fmt.Sprintf("[]%s", TypeToString(pkg, t.Elem()))

case *types.Map:
return fmt.Sprintf("map[%s]%s", TypeToString(pkg, t.Key()), TypeToString(pkg, t.Elem()))

case *types.Named:
if pkg == nil || (t.Obj().Pkg() != nil && t.Obj().Pkg().Path() != pkg.Path()) {
return fmt.Sprintf("%s.%s", t.Obj().Pkg().Name(), t.Obj().Name())
Expand Down
26 changes: 26 additions & 0 deletions internal/codegen/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ func TestTypeToString(t *testing.T) {
typ: types.NewSlice(code.TypeString),
want: "[]string",
},
{
name: "map type",
typ: types.NewMap(code.TypeString, code.TypeInt),
want: "map[string]int",
},
{
name: "map with internal named type",
typ: types.NewMap(
types.NewNamed(types.NewTypeName(token.NoPos, internalPkg, "User", nil), nil, nil),
types.NewNamed(types.NewTypeName(token.NoPos, internalPkg, "Gender", nil), nil, nil),
),
want: "map[User]Gender",
},
{
name: "map with external named value type",
typ: types.NewMap(
types.NewNamed(types.NewTypeName(token.NoPos, externalPkg, "User", nil), nil, nil),
types.NewNamed(types.NewTypeName(token.NoPos, externalPkg, "Gender", nil), nil, nil),
),
want: "map[bar.User]bar.Gender",
},
{
name: "named type internal",
typ: types.NewNamed(types.NewTypeName(token.NoPos, internalPkg, "User", nil), nil, nil),
Expand Down Expand Up @@ -235,6 +256,11 @@ func TestTypeToString_PkgNil(t *testing.T) {
typ: types.NewSlice(code.TypeString),
want: "[]string",
},
{
name: "map type",
typ: types.NewMap(code.TypeString, code.TypeInt),
want: "map[string]int",
},
{
name: "named type external",
typ: types.NewNamed(types.NewTypeName(token.NoPos, externalPkg, "User", nil), nil, nil),
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const usageText = `repogen generates MongoDB repository implementation from repo
Supported options:`

// version indicates the version of repogen.
const version = "v0.5-next"
const version = "v0.4.1"

func main() {
flag.Usage = printUsage
Expand Down