From 3a66fc038fcbe89e4af10ccdb3813be9b0e7e292 Mon Sep 17 00:00:00 2001 From: fondoger Date: Mon, 1 May 2023 15:01:28 +0800 Subject: [PATCH] [dart-gen] Fix nullable list item issue (#3192) --- tools/goctl/api/dartgen/gendata.go | 2 +- tools/goctl/api/dartgen/util.go | 4 ++++ tools/goctl/api/dartgen/vars.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/goctl/api/dartgen/gendata.go b/tools/goctl/api/dartgen/gendata.go index 92391497..08ca1354 100644 --- a/tools/goctl/api/dartgen/gendata.go +++ b/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}} diff --git a/tools/goctl/api/dartgen/util.go b/tools/goctl/api/dartgen/util.go index 81d32fcd..0847057d 100644 --- a/tools/goctl/api/dartgen/util.go +++ b/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<") } diff --git a/tools/goctl/api/dartgen/vars.go b/tools/goctl/api/dartgen/vars.go index a61ff0cc..233a889c 100644 --- a/tools/goctl/api/dartgen/vars.go +++ b/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,