From 13e721532d93cb112db6ba554a48d20979f68ac6 Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 23 Sep 2025 15:40:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A3=80=E6=9F=A5=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=98=AF=E5=90=A6=E5=8C=85=E5=90=AB=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=AD=97=E6=AE=B5=E5=B9=B6=E7=9B=B8=E5=BA=94=E5=9C=B0?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=AD=97=E6=AE=B5=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/ast/route/builder.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/ast/route/builder.go b/pkg/ast/route/builder.go index b86fd38..49a216b 100644 --- a/pkg/ast/route/builder.go +++ b/pkg/ast/route/builder.go @@ -27,6 +27,7 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) { imports := []string{} controllers := []string{} + hasModelParams := false for _, route := range opts.Routes { imports = append(imports, route.Imports...) @@ -46,6 +47,14 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) { return tok, true }) + // Check if any parameter has model field specified + for _, param := range action.Params { + if param.Model != "" && param.Position == PositionPath { + hasModelParams = true + break + } + } + rd.Routes[route.Name] = append(rd.Routes[route.Name], Router{ Method: strcase.ToCamel(action.Method), Route: action.Route, @@ -57,6 +66,11 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) { } } + // Add field package import if there are model parameters + if hasModelParams { + imports = append(imports, `"go.ipao.vip/gen/field"`) + } + // de-dup and sort imports/controllers for stable output rd.Imports = lo.Uniq(imports) sort.Strings(rd.Imports)