From 7838d32596d295f8a55031d848e433e33263f944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 13 Sep 2023 16:19:50 +0200 Subject: [PATCH] Support rendering of patternProperties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../json-schema/resolve-additional-types.html | 14 ++++++++++++++ .../partials/openapi/render-object-table.html | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/layouts/partials/json-schema/resolve-additional-types.html b/layouts/partials/json-schema/resolve-additional-types.html index 449b4222..8bf210ea 100644 --- a/layouts/partials/json-schema/resolve-additional-types.html +++ b/layouts/partials/json-schema/resolve-additional-types.html @@ -52,6 +52,20 @@ {{ 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` */}} diff --git a/layouts/partials/openapi/render-object-table.html b/layouts/partials/openapi/render-object-table.html index 9690e978..d76f1a74 100644 --- a/layouts/partials/openapi/render-object-table.html +++ b/layouts/partials/openapi/render-object-table.html @@ -104,6 +104,22 @@ */}} {{ $additionalProperties := partial "json-schema/resolve-allof" .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 }} {{/* It's legal to specify an array of types. Join them together in that case */}}