Skip to content

Commit e2b6b6e

Browse files
Merge pull request #70 from alexthemayers/templates/go-client
allow for optional boolean fields in requests and responses
2 parents 7309810 + a9e6c59 commit e2b6b6e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

templates/go-client/schema.tmpl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ type {{ .GetName | SanitiseName }} {{ . | SanitiseType }}
1111
{{ if eq ($schema | SanitiseType) "struct" -}}
1212
{{ $name | ToTitle }} {{ $schema.GetName | SanitiseName }}
1313
{{- else -}}
14-
{{ $name | ToTitle }} {{ $schema | SanitiseType }} `json:"{{ $name }}"`
14+
{{- $required := false }}
15+
{{- range $requiredProperty := $schema.Required }}
16+
{{- if eq $name $requiredProperty }}
17+
{{- $required = true }}
18+
{{- end }}
19+
{{- end }}
20+
{{- if eq $required false -}}
21+
{{ $name | ToTitle }} {{ if eq ($schema | SanitiseType) "bool" }}*{{ end }}{{ $schema | SanitiseType }} `json:"{{ $name }},omitempty"`
22+
{{- else }}
23+
{{ $name | ToTitle }} {{ $schema | SanitiseType }} `json:"{{ $name }}"`
24+
{{- end }}
1525
{{- end }}
1626
{{- end }}
1727
}

0 commit comments

Comments
 (0)