Skip to content

Commit

Permalink
add map type (zeromicro#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
anstns committed Nov 18, 2023
1 parent 72dd273 commit da67ea2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/goctl/api/dartgen/genapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import '../data/{{with .Service}}{{.Name}}{{end}}.dart';
/// {{.Name}}
{{range $i, $Route := .Routes}}
/// --{{.Path}}--
///
/// --{{.AtDoc}}--
/// request: {{with .RequestType}}{{.Name}}{{end}}
/// response: {{with .ResponseType}}{{.Name}}{{end}}
Future {{normalizeHandlerName .Handler}}(
Expand Down
4 changes: 4 additions & 0 deletions tools/goctl/api/dartgen/gendata.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class {{.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 if isMapType .Type.Name}}
{{if isNumberType .Type.Name}}num{{else}}{{.Type.Name}}{{end}}.from(m['{{getPropertyFromMember .}}'] ?? {})
{{else}}
{{.Type.Name}}.fromJson(m['{{getPropertyFromMember .}}']){{end}}
,{{end}}
Expand All @@ -61,6 +63,8 @@ class {{.Name}} {
'{{getPropertyFromMember .}}':
{{if isDirectType .Type.Name}}
{{lowCamelCase .Name}}
{{else if isMapType .Type.Name}}
{{lowCamelCase .Name}}
{{else if isClassListType .Type.Name}}
{{lowCamelCase .Name}}{{if isNullableType .Type.Name}}?{{end}}.map((i) => i{{if isListItemsNullable .Type.Name}}?{{end}}.toJson())
{{else}}
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/api/dartgen/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var funcMap = template.FuncMap{
"hasUrlPathParams": hasUrlPathParams,
"extractPositionalParamsFromPath": extractPositionalParamsFromPath,
"makeDartRequestUrlPath": makeDartRequestUrlPath,
"isMapType": isMapType,
}

const (
Expand Down

0 comments on commit da67ea2

Please sign in to comment.