-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathschema-source.html
More file actions
57 lines (50 loc) · 2.18 KB
/
schema-source.html
File metadata and controls
57 lines (50 loc) · 2.18 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
57
{{ $schema := .schema | default dict }}
{{ $schemas := .schemas | default dict }}
{{ if not $schema }}
{{- dict | jsonify -}}
{{- return -}}
{{ end }}
{{ $resolved := $schema }}
{{ if and (reflect.IsMap $schema) (index $schema "$ref") }}
{{ $refName := replaceRE "^.*/" "" (index $schema "$ref") }}
{{ with index $schemas $refName }}
{{ $resolved = partial "rest-apis/schema-source.html" (dict "schema" . "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ end }}
{{ else if and (reflect.IsMap $schema) (index $schema "allOf") }}
{{ $properties := dict }}
{{ $required := slice }}
{{ $description := index $schema "description" | default "" }}
{{ $type := index $schema "type" | default "object" }}
{{ range index $schema "allOf" }}
{{ $part := partial "rest-apis/schema-source.html" (dict "schema" . "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ with index $part "properties" }}
{{ $properties = merge $properties . }}
{{ end }}
{{ range (index $part "required" | default (slice)) }}
{{ if not (in $required .) }}
{{ $required = $required | append . }}
{{ end }}
{{ end }}
{{ if and (eq $description "") (index $part "description") }}
{{ $description = index $part "description" }}
{{ end }}
{{ if and (eq $type "object") (index $part "type") }}
{{ $type = index $part "type" }}
{{ end }}
{{ end }}
{{ with index $schema "properties" }}
{{ $properties = merge $properties . }}
{{ end }}
{{ range (index $schema "required" | default (slice)) }}
{{ if not (in $required .) }}
{{ $required = $required | append . }}
{{ end }}
{{ end }}
{{ $resolved = dict "type" $type "properties" $properties "required" $required }}
{{ if $description }}
{{ $resolved = merge $resolved (dict "description" $description) }}
{{ end }}
{{ else if and (reflect.IsMap $schema) (eq (index $schema "type") "array") (index $schema "items") }}
{{ $resolved = merge $schema (dict "items" (partial "rest-apis/schema-source.html" (dict "schema" (index $schema "items") "schemas" $schemas) | transform.Unmarshal (dict "format" "json"))) }}
{{ end }}
{{- $resolved | jsonify -}}