Support rendering of patternProperties

Currently the pattern is ignored as there is always only one
pattern in current definitions,
and the pattern is clear with the descriptions.
First step to render `m.receipt` event

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille 2023-09-13 16:19:50 +02:00
parent 4ca33aec90
commit 7838d32596
No known key found for this signature in database
GPG key ID: 29A48C1F03620416
2 changed files with 30 additions and 0 deletions

View file

@ -52,6 +52,20 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
{{/*
Add any nested objects referenced in this object's `patternProperties`
*/}}
{{ if $this_object.patternProperties }}
{{ range $pattern, $object := $this_object.patternProperties}}
{{ $additional_objects = partial "get-additional-objects" (dict
"this_object" $object
"additional_objects" $additional_objects
"anchor_base" $anchor_base
"name" (printf "%s.pattern.%s" $name $pattern)
) }}
{{ end }}
{{ end }}
{{/* {{/*
Add any nested objects referenced in this object's `properties` Add any nested objects referenced in this object's `properties`
*/}} */}}

View file

@ -104,6 +104,22 @@
*/}} */}}
{{ $additionalProperties := partial "json-schema/resolve-allof" .additionalProperties }} {{ $additionalProperties := partial "json-schema/resolve-allof" .additionalProperties }}
{{ $type = delimit (slice "{string: " (partial "property-type" $additionalProperties) "}" ) "" }} {{ $type = delimit (slice "{string: " (partial "property-type" $additionalProperties) "}" ) "" }}
{{ else if reflect.IsMap .patternProperties }}
{{/*
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
always have a single pattern, but we might need to handle
them later to differentiate schemas according to patterns.
*/}}
{{ $types := slice }}
{{ range $pattern, $schema := .patternProperties}}
{{ $schema = partial "json-schema/resolve-allof" $schema }}
{{ $types = $types | append (partial "property-type" $schema) }}
{{ end }}
{{ $type = delimit (slice "{string: " (delimit $types "|") "}" ) "" }}
{{ else if reflect.IsSlice .type }} {{ else if reflect.IsSlice .type }}
{{/* It's legal to specify an array of types. Join them together in that case */}} {{/* It's legal to specify an array of types. Join them together in that case */}}