-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go.tmpl
73 lines (63 loc) · 2.37 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
69
70
71
72
73
/Users/danielrutkovsky/Developer/gen-typescript/types.go.tmpl{{define "types"}}
{{- $typeMap := .TypeMap -}}
{{- $types := .Types -}}
{{- $services := .Services -}}
// MARK: - Types
{{- if $types -}}
{{range $_i, $type := $types -}}
{{if isEnumType $type }}
public enum {{$type.Name}}: String, Codable {
{{- range $_, $field := $type.Fields}}
case {{camelCase $field.Name}} = "{{$field.Name}}"
{{- end}}
}
{{end -}}
{{- if isStructType $type }}
public struct {{$type.Name}}: Codable {
{{- 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 }}
let {{template "fieldName" dict "Field" .}}: {{template "type" dict "Type" $field.Type "TypeMap" $typeMap}}{{if .Optional}}?{{end}}
{{- end -}}
{{- end}}
{{- if $type.Fields}}
enum CodingKeys: String, CodingKey {
{{- 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 }}
case {{template "fieldName" dict "Field" .}} = "{{template "codingKey" dict "Field" .}}"
{{- end -}}
{{- end}}
}
{{- end}}
}
{{end -}}
{{end -}}
{{end -}}
{{if $services}}
{{- range $_, $service := $services}}
public protocol {{$service.Name}} {
{{- range $_, $method := $service.Methods}}
{{ $generateHeaders := "false" -}}
func {{firstLetterToLower $method.Name}}({{template "methodInputs" dict "Method" $method "TypeMap" $typeMap "GenerateHeaders" $generateHeaders}}) async throws {{- if gt (len $method.Outputs) 0}}-> {{end}}{{template "methodOutputs" dict "Method" $method "TypeMap" $typeMap}}
{{ $generateHeaders := "true" -}}
func {{firstLetterToLower $method.Name}}({{template "methodInputs" dict "Method" $method "TypeMap" $typeMap "GenerateHeaders" $generateHeaders}}) async throws {{- if gt (len $method.Outputs) 0}}-> {{end}}{{template "methodOutputs" dict "Method" $method "TypeMap" $typeMap}}
{{- end }}
}
{{- end -}}
{{end -}}
{{end}}