Compare commits
3 Commits
439456b6ad
...
13e721532d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13e721532d | ||
|
|
f8f4c7b76a | ||
|
|
c7a753887d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ go.work.sum
|
|||||||
tests/*
|
tests/*
|
||||||
atomctl
|
atomctl
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
|
atom
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParserConfig represents the configuration for the parser
|
// ParserConfig represents the configuration for the parser
|
||||||
@@ -77,7 +79,7 @@ func NewParserConfig() *ParserConfig {
|
|||||||
StrictMode: false,
|
StrictMode: false,
|
||||||
DefaultMode: "basic",
|
DefaultMode: "basic",
|
||||||
AllowTestFiles: false,
|
AllowTestFiles: false,
|
||||||
AllowGenFiles: false,
|
AllowGenFiles: true,
|
||||||
MaxFileSize: 10 * 1024 * 1024, // 10MB
|
MaxFileSize: 10 * 1024 * 1024, // 10MB
|
||||||
Concurrency: 1,
|
Concurrency: 1,
|
||||||
CacheEnabled: true,
|
CacheEnabled: true,
|
||||||
@@ -115,12 +117,9 @@ func (c *ParserContext) ShouldIncludeFile(filePath string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip generated files if not allowed, but allow routes.gen.go and services.gen.go since they may contain providers
|
// Skip generated files if not allowed, but allow routes.gen.go and services.gen.go since they may contain providers
|
||||||
if !c.Config.AllowGenFiles {
|
if !c.Config.AllowGenFiles && strings.HasSuffix(filePath, ".gen.go") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// if !c.Config.AllowGenFiles && strings.HasSuffix(filePath, ".gen.go") && !strings.HasSuffix(filePath, "routes.gen.go") && !strings.HasSuffix(filePath, "services.gen.go") {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Check file size
|
// Check file size
|
||||||
if info, err := os.Stat(filePath); err == nil {
|
if info, err := os.Stat(filePath); err == nil {
|
||||||
@@ -132,6 +131,7 @@ func (c *ParserContext) ShouldIncludeFile(filePath string) bool {
|
|||||||
|
|
||||||
// TODO: Implement include/exclude pattern matching
|
// TODO: Implement include/exclude pattern matching
|
||||||
// For now, include all Go files that pass the basic checks
|
// For now, include all Go files that pass the basic checks
|
||||||
|
log.Debugf("Including file in parsing: %s", filePath)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) {
|
|||||||
|
|
||||||
imports := []string{}
|
imports := []string{}
|
||||||
controllers := []string{}
|
controllers := []string{}
|
||||||
|
hasModelParams := false
|
||||||
|
|
||||||
for _, route := range opts.Routes {
|
for _, route := range opts.Routes {
|
||||||
imports = append(imports, route.Imports...)
|
imports = append(imports, route.Imports...)
|
||||||
@@ -46,6 +47,14 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) {
|
|||||||
return tok, true
|
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{
|
rd.Routes[route.Name] = append(rd.Routes[route.Name], Router{
|
||||||
Method: strcase.ToCamel(action.Method),
|
Method: strcase.ToCamel(action.Method),
|
||||||
Route: action.Route,
|
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
|
// de-dup and sort imports/controllers for stable output
|
||||||
rd.Imports = lo.Uniq(imports)
|
rd.Imports = lo.Uniq(imports)
|
||||||
sort.Strings(rd.Imports)
|
sort.Strings(rd.Imports)
|
||||||
|
|||||||
Reference in New Issue
Block a user