-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathschema-type.html
More file actions
56 lines (49 loc) · 1.82 KB
/
schema-type.html
File metadata and controls
56 lines (49 loc) · 1.82 KB
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
{{ $schema := .schema | default . }}
{{ $schemas := .schemas | default dict }}
{{ $type := "" }}
{{ $format := "" }}
{{ if not $schema }}
{{ $type = "" }}
{{ else if and (reflect.IsMap $schema) (index $schema "$ref") }}
{{ $refName := replaceRE "^.*/" "" (index $schema "$ref") }}
{{ $type = (replace $refName "_" " " | title) }}
{{ else }}
{{ $source := partial "rest-apis/schema-source.html" (dict "schema" $schema "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ with index $source "format" }}
{{ $format = printf " (%s)" . }}
{{ end }}
{{ if index $source "type" }}
{{ $type = index $source "type" }}
{{ if eq $type "array" }}
{{ $itemType := partial "rest-apis/schema-type.html" (dict "schema" (index $source "items") "schemas" $schemas) }}
{{ if $itemType }}
{{ $type = printf "array of %s" $itemType }}
{{ end }}
{{ else if eq $type "object" }}
{{ $type = "object" }}
{{ end }}
{{ else if index $source "oneOf" }}
{{ $labels := slice }}
{{ range index $source "oneOf" }}
{{ $label := index . "title" | default (partial "rest-apis/schema-type.html" (dict "schema" . "schemas" $schemas)) | default "schema" }}
{{ if not (in $labels $label) }}
{{ $labels = $labels | append $label }}
{{ end }}
{{ end }}
{{ $type = printf "one of %s" (delimit $labels ", ") }}
{{ else if index $source "properties" }}
{{ $type = "object" }}
{{ else if index $source "enum" }}
{{ $type = "enum" }}
{{ end }}
{{ if and (index $source "nullable") $type }}
{{ $type = printf "%s | null" $type }}
{{ end }}
{{ if and $type $format (not (strings.Contains $type $format)) }}
{{ $type = printf "%s%s" $type $format }}
{{ end }}
{{ if not $type }}
{{ $type = "schema" }}
{{ end }}
{{ end }}
{{- $type -}}