-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.go.tmpl
68 lines (63 loc) · 1.72 KB
/
types.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{{define "types"}}
{{- $opts := .Opts -}}
{{- $types := .Types -}}
//
// Types
//
{{ if $types -}}
{{range $_, $type := $types -}}
{{if isEnumType $type -}}
{{$enumName := .Name}}
{{if $opts.exports}}export {{end}}var {{$enumName}};
(function ({{$enumName}}) {
{{- range $i, $field := .Fields}}
{{$enumName}}["{{$field.Name}}"] = "{{$field.Name}}"
{{- end}}
})({{$enumName}} || ({{$enumName}} = {}))
{{end -}}
{{- if isStructType $type }}
{{if $opts.exports}}export {{end}}class {{.Name}} {
constructor(_data) {
this._data = {}
if (_data) {
{{- range $_, $field := $type.Fields -}}
{{- $isExportable := true -}}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "json" -}}
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
{{- $isExportable = false}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $isExportable }}
this._data['{{template "fieldName" dict "Field" $field }}'] = _data['{{template "fieldName" dict "Field" $field }}']
{{- end -}}
{{end}}
}
}
{{ range $_, $field := $type.Fields -}}
{{- $isExportable := true -}}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "json" -}}
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
{{- $isExportable = false}}
{{- end -}}
{{- end -}}
{{- end }}
{{- if $isExportable }}
get {{template "fieldName" dict "Field" $field }}() {
return this._data['{{template "fieldName" dict "Field" $field }}']
}
set {{template "fieldName" dict "Field" $field }}(value) {
this._data['{{template "fieldName" dict "Field" $field }}'] = value
}
{{end}}
{{- end }}
toJSON() {
return this._data
}
}
{{end -}}
{{end -}}
{{end -}}
{{end}}