-
Notifications
You must be signed in to change notification settings - Fork 9
/
types.go.tmpl
68 lines (58 loc) · 1.73 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"}}
{{- $typeMap := .TypeMap -}}
{{- $types := .Types -}}
{{- $services := .Services -}}
//
// Types
//
{{if $types -}}
{{range $_i, $type := $types -}}
{{if isEnumType $type }}
export enum {{$type.Name}} {
{{- range $i, $field := $type.Fields}}
{{- if $i}},{{end}}
{{$field.Name}} = '{{$field.Name}}'
{{- end}}
}
{{end -}}
{{- if isStructType $type }}
export interface {{$type.Name}} {
{{- 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 }}
{{template "fieldName" dict "Field" .}}{{if .Optional}}?{{end}}: {{template "type" dict "Type" $field.Type "TypeMap" $typeMap}}
{{- end -}}
{{- end}}
}
{{end -}}
{{end -}}
{{end -}}
{{if $services}}
{{- range $_, $service := $services}}
export interface {{$service.Name}} {
{{- range $_, $method := $service.Methods}}
{{firstLetterToLower $method.Name}}({{template "methodInputs" dict "Method" $method "TypeMap" $typeMap}}): {{if $method.StreamOutput}}WebrpcStreamController{{else}}Promise<{{$method.Name}}Return>{{end}}
{{- end}}
}
{{range $_, $method := $service.Methods -}}
export interface {{$method.Name}}Args {
{{- range $_, $input := $method.Inputs}}
{{$input.Name}}{{if $input.Optional}}?{{end}}: {{template "type" dict "Type" $input.Type "TypeMap" $typeMap}}
{{- end}}
}
export interface {{$method.Name}}Return {
{{- range $_, $output := $method.Outputs}}
{{$output.Name}}{{if $output.Optional}}?{{end}}: {{template "type" dict "Type" $output.Type "TypeMap" $typeMap}}
{{- end}}
}
{{end}}
{{- end}}
{{end -}}
{{end}}