From 783624d2cd11a90c5ea76c36d165a078a957dc0f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:50:09 +0000 Subject: [PATCH] Fix rendering of responses with empty bodies (#3674) --- .../partials/openapi/render-responses.html | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/layouts/partials/openapi/render-responses.html b/layouts/partials/openapi/render-responses.html index 350b0257..79636945 100644 --- a/layouts/partials/openapi/render-responses.html +++ b/layouts/partials/openapi/render-responses.html @@ -35,44 +35,52 @@ -{{ range $code, $response := $responses }} - +{{ range $code, $response := $responses }} {{ if $response.schema }} +

{{$code}} response

+ {{ $schema := partial "json-schema/resolve-refs" (dict "schema" $response.schema "path" $path) }} {{ $schema := partial "json-schema/resolve-allof" $schema }} - {{ if or $schema.properties (eq $schema.type "array") }} -

{{ $code}} response

- - {{/* - All this is to work out how to express the content of the response - in the case where it is an array. - */}} - {{ if eq $schema.type "array" }} - {{ $type_of := "" }} - {{ if reflect.IsSlice $schema.items }} - {{ $types := slice }} - {{ range $schema.items }} - {{ if .title }} - {{ $types = $types | append .title}} - {{ else }} - {{ $types = $types | append .type }} - {{ end }} + {{/* + All this is to work out how to express the content of the response + in the case where it is an array. + */}} + {{ if eq $schema.type "array" }} + {{ $type_of := "" }} + {{ if reflect.IsSlice $schema.items }} + {{ $types := slice }} + {{ range $schema.items }} + {{ if .title }} + {{ $types = $types | append .title}} + {{ else }} + {{ $types = $types | append .type }} {{ end }} - {{ $type_of = delimit $types ", "}} - {{ else }} - {{ $type_of = $schema.items.title }} {{ end }} -

Array of {{ $type_of }}.

+ {{ $type_of = delimit $types ", "}} + {{ else }} + {{ $type_of = $schema.items.title }} {{ end }} +

Array of {{ $type_of }}.

+ {{ end }} - {{ $additional_types := partial "json-schema/resolve-additional-types" $schema }} - {{ $additional_types = uniq $additional_types }} - {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} - {{ end }} + {{/* + render object tables for any objects referenced in the + response. (This will be a no-op for response types which aren't + objects or arrays.) + */}} + {{ $additional_types := partial "json-schema/resolve-additional-types" $schema }} + {{ $additional_types = uniq $additional_types }} + {{ range $additional_types }} + {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ end }} + + {{/* + render an example. currently this is only supported for arrays and objects. + */}} + {{ if or (eq $schema.type "object") (eq $schema.type "array") }} {{ $example := partial "json-schema/resolve-example" $schema }} {{ if $response.examples }} {{ $example = partial "json-schema/resolve-refs" (dict "schema" $response.examples "path" $path) }}