Skip to content

Commit eea7089

Browse files
committed
Add shortcode to present JSON schema
Heavily based on the event-fields shortcode but allows to show schemas in the /data/schemas directory. Signed-off-by: Kévin Commaille <[email protected]>
1 parent 866c05f commit eea7089

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{{/*
2+
3+
This template is used to render the fields of a JSON schema that is not an
4+
event.
5+
6+
It expects to be passed a `name` parameter, which is the name of a file
7+
under /data/schemas. The file extension is omitted.
8+
9+
For example:
10+
11+
{{% json-schema name="oauth2-client-metadata" %}}
12+
13+
*/}}
14+
15+
{{ $schema := index .Site.Data "schemas" .Params.name }}
16+
{{ $path := delimit (slice "schemas" .Params.name) "/" }}
17+
18+
{{ $schema = partial "json-schema/resolve-refs" (dict "schema" $schema "path" $path) }}
19+
{{ $schema = partial "json-schema/resolve-allof" $schema }}
20+
21+
<section class="rendered-data event">
22+
23+
<details {{ if not .Site.Params.ui.rendered_data_collapsed }}open{{ end }}>
24+
<summary>
25+
26+
<h1>
27+
<code>{{ $schema.title }}</code>
28+
</h1>
29+
</summary>
30+
31+
<hr>
32+
33+
{{ if $schema.description -}}
34+
{{ $schema.description | markdownify -}}
35+
{{ end -}}
36+
37+
{{ $schema = merge $schema (dict "title" "") -}}
38+
39+
{{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema) -}}
40+
{{ range $additional_types -}}
41+
{{ partial "openapi/render-object-table" . -}}
42+
{{ end -}}
43+
44+
</details>
45+
46+
</section>

0 commit comments

Comments
 (0)