From b83bc65850ee9105159454859654f9caa684e82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 21 Feb 2025 16:09:47 +0100 Subject: [PATCH] Only show empty examples if the object is suppoed to be empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- layouts/partials/json-schema/resolve-examples.html | 4 +++- layouts/shortcodes/definition.html | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/layouts/partials/json-schema/resolve-examples.html b/layouts/partials/json-schema/resolve-examples.html index 2caf3e95..a0bb7090 100644 --- a/layouts/partials/json-schema/resolve-examples.html +++ b/layouts/partials/json-schema/resolve-examples.html @@ -37,7 +37,9 @@ {{ end }} {{ end }} - {{ $examples = slice $example }} + {{ if (or $example (not $this_object.properties)) }} + {{ $examples = slice $example }} + {{ end }} {{ else if eq $this_object.type "array" }} diff --git a/layouts/shortcodes/definition.html b/layouts/shortcodes/definition.html index 875ac16a..1a9643d9 100644 --- a/layouts/shortcodes/definition.html +++ b/layouts/shortcodes/definition.html @@ -58,11 +58,13 @@ {{ partial "openapi/render-object-table" . }} {{end}} +{{ $examples := partial "json-schema/resolve-examples" $definition }} +{{ if $examples }}

Examples

-{{ $examples := partial "json-schema/resolve-examples" $definition }} -{{ range $examples }} - {{ partial "render-example" (dict "example" .) }} + {{ range $examples }} + {{ partial "render-example" (dict "example" .) }} + {{ end }} {{ end }}