From a561048d590a427060def5fa1f32dc1ea3066a75 Mon Sep 17 00:00:00 2001 From: Snake Date: Sat, 18 Mar 2023 22:49:22 +0800 Subject: [PATCH] Fix bug: replace int and float with num type in dart (#3042) Co-authored-by: zhoumingji --- tools/goctl/api/dartgen/gendata.go | 4 ++-- tools/goctl/api/dartgen/util.go | 9 +++++++++ tools/goctl/api/dartgen/vars.go | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/goctl/api/dartgen/gendata.go b/tools/goctl/api/dartgen/gendata.go index 90d97ab2..e2ff03c2 100644 --- a/tools/goctl/api/dartgen/gendata.go +++ b/tools/goctl/api/dartgen/gendata.go @@ -13,7 +13,7 @@ const dataTemplate = `// --{{with .Info}}{{.Title}}{{end}}-- class {{.Name}}{ {{range .Members}} /// {{.Comment}} - final {{.Type.Name}} {{lowCamelCase .Name}}; + final {{if isNumberType .Type.Name}}num{{else}}{{.Type.Name}}{{end}} {{lowCamelCase .Name}}; {{end}} {{.Name}}({ {{range .Members}} this.{{lowCamelCase .Name}},{{end}} @@ -37,7 +37,7 @@ const dataTemplateV2 = `// --{{with .Info}}{{.Title}}{{end}}-- class {{.Name}} { {{range .Members}} {{if .Comment}}{{.Comment}}{{end}} - final {{.Type.Name}} {{lowCamelCase .Name}}; + final {{if isNumberType .Type.Name}}num{{else}}{{.Type.Name}}{{end}} {{lowCamelCase .Name}}; {{end}}{{.Name}}({{if .Members}}{ {{range .Members}} required this.{{lowCamelCase .Name}}, {{end}}}{{end}}); diff --git a/tools/goctl/api/dartgen/util.go b/tools/goctl/api/dartgen/util.go index 714d844b..d69d6518 100644 --- a/tools/goctl/api/dartgen/util.go +++ b/tools/goctl/api/dartgen/util.go @@ -57,6 +57,15 @@ func isAtomicType(s string) bool { } } +func isNumberType(s string) bool { + switch s { + case "int", "double": + return true + default: + return false + } +} + func isListType(s string) bool { return strings.HasPrefix(s, "List<") } diff --git a/tools/goctl/api/dartgen/vars.go b/tools/goctl/api/dartgen/vars.go index 1a304f5b..d923820f 100644 --- a/tools/goctl/api/dartgen/vars.go +++ b/tools/goctl/api/dartgen/vars.go @@ -6,6 +6,7 @@ var funcMap = template.FuncMap{ "getBaseName": getBaseName, "getPropertyFromMember": getPropertyFromMember, "isDirectType": isDirectType, + "isNumberType": isNumberType, "isClassListType": isClassListType, "getCoreType": getCoreType, "lowCamelCase": lowCamelCase,