Browse Source

[dart-gen] Fix lists containing atomic types (#3210)

fondoger 2 years ago
parent
commit
c22bc1c8ea

+ 3 - 1
tools/goctl/api/dartgen/gendata.go

@@ -45,8 +45,10 @@ class {{.Name}} {
 		return {{.Name}}(
 			{{range .Members}}
 				{{lowCamelCase .Name}}: {{appendNullCoalescing .}}
-					{{if isDirectType .Type.Name}}
+					{{if isAtomicType .Type.Name}}
 						m['{{getPropertyFromMember .}}'] {{appendDefaultEmptyValue .Type.Name}}
+					{{else if isAtomicListType .Type.Name}}
+						m['{{getPropertyFromMember .}}']?.cast<{{getCoreType .Type.Name}}>() {{appendDefaultEmptyValue .Type.Name}}
 					{{else if isClassListType .Type.Name}}
 						((m['{{getPropertyFromMember .}}'] {{appendDefaultEmptyValue .Type.Name}}) as List<dynamic>).map((i) => {{getCoreType .Type.Name}}.fromJson(i)).toList()
 					{{else}}

+ 5 - 1
tools/goctl/api/dartgen/util.go

@@ -71,7 +71,11 @@ func isListType(s string) bool {
 }
 
 func isClassListType(s string) bool {
-	return strings.HasPrefix(s, "List<") && !isAtomicType(getCoreType(s))
+	return isListType(s) && !isAtomicType(getCoreType(s))
+}
+
+func isAtomicListType(s string) bool {
+	return isListType(s) && isAtomicType(getCoreType(s))
 }
 
 func isListItemsNullable(s string) bool {

+ 2 - 0
tools/goctl/api/dartgen/vars.go

@@ -6,8 +6,10 @@ var funcMap = template.FuncMap{
 	"getBaseName":                     getBaseName,
 	"getPropertyFromMember":           getPropertyFromMember,
 	"isDirectType":                    isDirectType,
+	"isAtomicType":                    isAtomicType,
 	"isNumberType":                    isNumberType,
 	"isClassListType":                 isClassListType,
+	"isAtomicListType":                isAtomicListType,
 	"isListItemsNullable":             isListItemsNullable,
 	"isNullableType":                  isNullableType,
 	"appendNullCoalescing":            appendNullCoalescing,