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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ require (
github.com/spf13/cobra v1.8.0
golang.org/x/sync v0.20.0
golang.org/x/tools v0.44.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9
)

require (
github.com/fatih/structtag v1.2.0
github.com/go-generalize/go-dartfmt v0.1.1
github.com/go-generalize/go-easyparser v0.3.3
github.com/go-generalize/go-easyparser v0.5.0
github.com/go-generalize/go2dart v0.5.1
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4
github.com/go-generalize/go-dartfmt v0.1.1 h1:2W+CD7qGCNE/0JLtm394RJBBi/jhtXUcJ+G0v0Bcx88=
github.com/go-generalize/go-dartfmt v0.1.1/go.mod h1:xbPNNnCJpX/CtvxIy1grvi9X2A57jC6fsvoYVDXpAWQ=
github.com/go-generalize/go-easyparser v0.2.0/go.mod h1:I+Ifnjzw7UNzxkENknQQY9yB2gsz9RekzAbKLYq/Dzw=
github.com/go-generalize/go-easyparser v0.3.3 h1:sX1y6pON1dWEjVIzQr1FHRboM/4LRdXmTJHQf/h4caM=
github.com/go-generalize/go-easyparser v0.3.3/go.mod h1:8Rs26IvI49PII6hWsIRw02/rJrzBrxSrkDgY+Wbt+2E=
github.com/go-generalize/go-easyparser v0.5.0 h1:MyNXGpesbbXMZbITWATrRl/+UU5NwUMOctfx4oYeMWk=
github.com/go-generalize/go-easyparser v0.5.0/go.mod h1:JY2y+clYM+/gEN3AdoZrHjqk0TvpOrE7KOSK+cwu1VQ=
github.com/go-generalize/go2dart v0.5.1 h1:eeSjP7GMArcPHZ+sMYQxU79MxjHDqaQvLcNHdV0erFI=
github.com/go-generalize/go2dart v0.5.1/go.mod h1:peqHvoBnlWmpJPoYaIyGBditWFaNZ6jR0ywbIRNdY8o=
github.com/go-generalize/go2go v0.2.1 h1:YLUiBx8W9WgSeYDJnuF79Hx0dkMZu1VZygeyasCbyvk=
Expand Down Expand Up @@ -97,8 +97,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUOU8xyFgXv6cOTp2HASDlsDk=
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
30 changes: 30 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,33 @@ func TestGenerate(t *testing.T) {
t.Fatal(err)
}
}

// TestGenerateAliasRepro is a regression test for *types.Alias support (Go 1.23+).
// With GODEBUG=gotypesalias=1 (the default since Go 1.23), type aliases such as
// "any" (alias for interface{}) appear as *types.Alias in go/types output.
// go-easyparser v0.3.3 (used in api_gen v2.14.1) lacked a case for *types.Alias and
// panicked with "unsupported named type: *types.Alias" for any interface that uses
// map[string]any. This test verifies that code generation completes without error.
// The static fixture under testdir/alias_repro/server/ is intentionally NOT
// added to make gen_samples to avoid false-positive diffs from version-string drift.
func TestGenerateAliasRepro(t *testing.T) {
gr, err := parser.Parse("./testdir/alias_repro/interfaces")

if err != nil {
t.Fatalf("parser.Parse failed (regression: *types.Alias support): %v", err)
}

// Use a subdirectory under testdir so gopackages.NewModule can find testdir/go.mod.
outDir := "./testdir/alias_repro/server"
_ = os.RemoveAll(outDir)

gen, err := NewGenerator(gr, outDir, "server", "devel")

if err != nil {
t.Fatalf("NewGenerator failed: %v", err)
}

if err := gen.Generate(); err != nil {
t.Fatalf("Generate failed (regression: *types.Alias support): %v", err)
}
}
14 changes: 14 additions & 0 deletions pkg/server/testdir/alias_repro/interfaces/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package interfaces contains request/response types for alias_repro regression test.
// This file intentionally uses map[string]any which triggers *types.Alias in Go 1.23+
// with GODEBUG=gotypesalias=1 (the default since Go 1.23).
package interfaces

// GetRequest - request type with map[string]any (triggers *types.Alias in Go 1.23+)
type GetRequest struct {
Extra map[string]any `json:"extra"`
}

// GetResponse - response type with map[string]any
type GetResponse struct {
Data map[string]any `json:"data"`
}
71 changes: 71 additions & 0 deletions pkg/server/testdir/alias_repro/server/bundler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions pkg/server/testdir/alias_repro/server/controller/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Package controller handles requests and returns responses. api_gen users directly edit this file.
// generated version: devel
// nolint:dupl
package controller

import (
types "github.com/go-generalize/api_gen/v2/pkg/server/tmp/alias_repro/interfaces"
props "github.com/go-generalize/api_gen/v2/pkg/server/tmp/alias_repro/server/props"
"github.com/labstack/echo/v4"
)

// GetController ...
type GetController interface {
Get(c echo.Context, req *types.GetRequest) (res *types.GetResponse, err error)
}

type getController struct {
*props.ControllerProps
}

// NewGetController ...
func NewGetController(cp *props.ControllerProps) GetController {
return &getController{
ControllerProps: cp,
}
}

// Get - GET
func (ctrl *getController) Get(
c echo.Context, req *types.GetRequest,
) (res *types.GetResponse, err error) {
// return nil, apierror.NewAPIError(http.StatusBadRequest)
//
// return nil, apierror.NewAPIError(http.StatusBadRequest).SetError(err)
//
// body := map[string]interface{}{
// "code": http.StatusBadRequest,
// "message": "invalid request parameter.",
// }
// return nil, apierror.NewAPIError(http.StatusBadRequest, body).SetError(err)
panic("require implements.") // FIXME require implements.
}

// AutoBind - use echo.Bind
func (ctrl *getController) AutoBind() bool {
return true
}
91 changes: 91 additions & 0 deletions pkg/server/testdir/alias_repro/server/controller_initializer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading