浏览代码

[dart-gen] Fix nullable list item issue (#3192)

fondoger 2 年之前
父节点
当前提交
3a66fc038f
共有 3 个文件被更改,包括 6 次插入1 次删除
  1. 1 1
      tools/goctl/api/dartgen/gendata.go
  2. 4 0
      tools/goctl/api/dartgen/util.go
  3. 1 0
      tools/goctl/api/dartgen/vars.go

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

@@ -60,7 +60,7 @@ class {{.Name}} {
 				{{if isDirectType .Type.Name}}
 					{{lowCamelCase .Name}}
 				{{else if isClassListType .Type.Name}}
-					{{lowCamelCase .Name}}{{if isNullableType .Type.Name}}?{{end}}.map((i) => i.toJson())
+					{{lowCamelCase .Name}}{{if isNullableType .Type.Name}}?{{end}}.map((i) => i{{if isListItemsNullable .Type.Name}}?{{end}}.toJson())
 				{{else}}
 					{{lowCamelCase .Name}}{{if isNullableType .Type.Name}}?{{end}}.toJson()
 				{{end}}

+ 4 - 0
tools/goctl/api/dartgen/util.go

@@ -74,6 +74,10 @@ func isClassListType(s string) bool {
 	return strings.HasPrefix(s, "List<") && !isAtomicType(getCoreType(s))
 }
 
+func isListItemsNullable(s string) bool {
+	return isListType(s) && isNullableType(getCoreType(s))
+}
+
 func isMapType(s string) bool {
 	return strings.HasPrefix(s, "Map<")
 }

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

@@ -8,6 +8,7 @@ var funcMap = template.FuncMap{
 	"isDirectType":                    isDirectType,
 	"isNumberType":                    isNumberType,
 	"isClassListType":                 isClassListType,
+	"isListItemsNullable":             isListItemsNullable,
 	"isNullableType":                  isNullableType,
 	"appendNullCoalescing":            appendNullCoalescing,
 	"appendDefaultEmptyValue":         appendDefaultEmptyValue,