|
|
|
@ -179,17 +179,45 @@
|
|
|
|
|
{{/*
|
|
|
|
|
If the property uses `patternProperties` to describe its
|
|
|
|
|
internal structure, handle this with a bit of recursion.
|
|
|
|
|
Note that we ignore the pattern as the current definitions
|
|
|
|
|
Types are grouped by pattern format. Note that we ignore
|
|
|
|
|
patterns without a format as the current definitions
|
|
|
|
|
always have a single pattern, but we might need to handle
|
|
|
|
|
them later to differentiate schemas according to patterns.
|
|
|
|
|
*/}}
|
|
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
|
Construct a map from format ID to the type string of the format.
|
|
|
|
|
*/}}
|
|
|
|
|
{{ $formatMap := newScratch }}
|
|
|
|
|
|
|
|
|
|
{{ range $pattern, $schema := .patternProperties }}
|
|
|
|
|
{{ $formatId := or (index $schema "x-pattern-format") "string" }}
|
|
|
|
|
|
|
|
|
|
{{ if $formatMap.Get $formatId }}
|
|
|
|
|
{{ errorf "'%s' pattern format is defined more than once for the same property" $formatId }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ $formatMap.Set $formatId (partial "property-type" $schema) }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{/* First generate the type string for each format. */}}
|
|
|
|
|
{{ $types := slice }}
|
|
|
|
|
{{ range $formatId, $formatType := $formatMap.Values }}
|
|
|
|
|
{{ $formatKey := "string" }}
|
|
|
|
|
{{ if ne $formatId "string" }}
|
|
|
|
|
{{ with index site.Data "custom-formats" $formatId }}
|
|
|
|
|
{{ $formatKey = printf "<a href=\"%s\">%s</a>" (htmlEscape .url) (htmlEscape .title) }}
|
|
|
|
|
{{ else }}
|
|
|
|
|
{{ errorf "Unsupported value for `x-pattern-format`: %s" $formatId }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ range $pattern, $schema := .patternProperties}}
|
|
|
|
|
{{ $types = $types | append (partial "property-type" $schema) }}
|
|
|
|
|
{{ $formatString := printf "{%s: %s}" $formatKey $formatType }}
|
|
|
|
|
{{ $types = $types | append $formatString }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ $type = delimit (slice "{string: " (delimit $types "|") "}" ) "" }}
|
|
|
|
|
{{/* Then join all the formats. */}}
|
|
|
|
|
{{ $type = delimit $types "|" }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ return $type }}
|
|
|
|
|