From 3f688fe5fa80cd3e4142539c2f999b6fcd9a0317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 24 May 2025 18:44:26 +0200 Subject: [PATCH] Add shortcode to present JSON schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Heavily based on the event-fields shortcode but allows to show schemas in the /data/schemas directory. Signed-off-by: Kévin Commaille --- layouts/shortcodes/json-schema.html | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 layouts/shortcodes/json-schema.html diff --git a/layouts/shortcodes/json-schema.html b/layouts/shortcodes/json-schema.html new file mode 100644 index 00000000..632ed03d --- /dev/null +++ b/layouts/shortcodes/json-schema.html @@ -0,0 +1,46 @@ +{{/* + + This template is used to render the fields of a JSON schema that is not an + event. + + It expects to be passed a `name` parameter, which is the name of a file + under /data/schemas. The file extension is omitted. + + For example: + + {{% json-schema name="oauth2-client-metadata" %}} + +*/}} + +{{ $schema := index .Site.Data "schemas" .Params.name }} +{{ $path := delimit (slice "schemas" .Params.name) "/" }} + +{{ $schema = partial "json-schema/resolve-refs" (dict "schema" $schema "path" $path) }} +{{ $schema = partial "json-schema/resolve-allof" $schema }} + +
+ +
+ + +

+ {{ $schema.title }} +

+
+ +
+ +{{ if $schema.description -}} + {{ $schema.description | markdownify -}} +{{ end -}} + +{{ $schema = merge $schema (dict "title" "") -}} + +{{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema) -}} +{{ range $additional_types -}} + {{ partial "openapi/render-object-table" . -}} +{{ end -}} + +
+ +