From 1ed4e4036252a5a3e5f1dba6412ef1499fda9c67 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 19 Jul 2022 17:44:27 +0100 Subject: [PATCH] `render-object-table`: take a "title" rather than a "caption" ... which means we can use the result from resolve-additional-types directly. --- layouts/partials/events/render-event.html | 2 +- layouts/partials/openapi/render-object-table.html | 14 ++++++++------ layouts/partials/openapi/render-parameters.html | 2 +- layouts/partials/openapi/render-request.html | 2 +- layouts/partials/openapi/render-responses.html | 2 +- layouts/shortcodes/definition.html | 2 +- layouts/shortcodes/event-fields.html | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/layouts/partials/events/render-event.html b/layouts/partials/events/render-event.html index 15e8aa5a..feaace36 100644 --- a/layouts/partials/events/render-event.html +++ b/layouts/partials/events/render-event.html @@ -56,7 +56,7 @@ {{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $event_data.properties.content) }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" . }} {{end}}

Examples

diff --git a/layouts/partials/openapi/render-object-table.html b/layouts/partials/openapi/render-object-table.html index e132af30..4dc8aeaa 100644 --- a/layouts/partials/openapi/render-object-table.html +++ b/layouts/partials/openapi/render-object-table.html @@ -2,23 +2,25 @@ Render a table listing the properties of an object, given: - * `caption`: optional caption for the table + * `title`: optional caption for the table + * `properties`: dictionary of the properties to list, each given as: - `property_name` : `property_data` + `property_name` : `property_data` + * `required`: array containing the names of required properties. - In some cases (such as response body specifications) this isn't used, and - instead properties have a `required` boolean attribute. We support this too. + In some cases (such as response body specifications) this isn't used, and + instead properties have a `required` boolean attribute. We support this too. */}} -{{ $caption := .caption }} +{{ $title := .title }} {{ $properties := .properties}} {{ $required := .required}} {{ if $properties }} - {{ with $caption }} + {{ with $title }} {{ end }} diff --git a/layouts/partials/openapi/render-parameters.html b/layouts/partials/openapi/render-parameters.html index 2a36ea8d..b7861b7f 100644 --- a/layouts/partials/openapi/render-parameters.html +++ b/layouts/partials/openapi/render-parameters.html @@ -25,6 +25,6 @@ {{ end }} {{/* and render the parameters */}} - {{ partial "openapi/render-object-table" (dict "caption" $caption "properties" $param_dict) }} + {{ partial "openapi/render-object-table" (dict "title" $caption "properties" $param_dict) }} {{ end }} diff --git a/layouts/partials/openapi/render-request.html b/layouts/partials/openapi/render-request.html index d0383058..2174b552 100644 --- a/layouts/partials/openapi/render-request.html +++ b/layouts/partials/openapi/render-request.html @@ -41,7 +41,7 @@ {{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema) }} {{ $additional_types = uniq $additional_types }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" . }} {{ end }}

Request body example

diff --git a/layouts/partials/openapi/render-responses.html b/layouts/partials/openapi/render-responses.html index 38ca7aeb..3935c4e0 100644 --- a/layouts/partials/openapi/render-responses.html +++ b/layouts/partials/openapi/render-responses.html @@ -74,7 +74,7 @@ {{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema) }} {{ $additional_types = uniq $additional_types }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" . }} {{ end }} {{/* diff --git a/layouts/shortcodes/definition.html b/layouts/shortcodes/definition.html index 518d094c..2828db48 100644 --- a/layouts/shortcodes/definition.html +++ b/layouts/shortcodes/definition.html @@ -49,7 +49,7 @@ {{ $additional_types = uniq $additional_types }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" . }} {{end}}

Examples

diff --git a/layouts/shortcodes/event-fields.html b/layouts/shortcodes/event-fields.html index 135acab0..7120f87f 100644 --- a/layouts/shortcodes/event-fields.html +++ b/layouts/shortcodes/event-fields.html @@ -37,7 +37,7 @@ {{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $event) }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" . }} {{end}}
{{ . }}