Fix rendering of responses with empty bodies (#3674)

This commit is contained in:
Richard van der Hoff 2022-01-26 10:50:09 +00:00 committed by GitHub
parent 39a41a18ba
commit 783624d2cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,15 +36,13 @@
</table> </table>
{{ range $code, $response := $responses }} {{ range $code, $response := $responses }}
{{ if $response.schema }} {{ if $response.schema }}
<h3>{{$code}} response</h3>
{{ $schema := partial "json-schema/resolve-refs" (dict "schema" $response.schema "path" $path) }} {{ $schema := partial "json-schema/resolve-refs" (dict "schema" $response.schema "path" $path) }}
{{ $schema := partial "json-schema/resolve-allof" $schema }} {{ $schema := partial "json-schema/resolve-allof" $schema }}
{{ if or $schema.properties (eq $schema.type "array") }}
<h3>{{ $code}} response</h3>
{{/* {{/*
All this is to work out how to express the content of the response All this is to work out how to express the content of the response
in the case where it is an array. in the case where it is an array.
@ -67,12 +65,22 @@
<p>Array of <code>{{ $type_of }}</code>.</p> <p>Array of <code>{{ $type_of }}</code>.</p>
{{ end }} {{ 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 := partial "json-schema/resolve-additional-types" $schema }}
{{ $additional_types = uniq $additional_types }} {{ $additional_types = uniq $additional_types }}
{{ range $additional_types }} {{ range $additional_types }}
{{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }}
{{ end }} {{ 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 }} {{ $example := partial "json-schema/resolve-example" $schema }}
{{ if $response.examples }} {{ if $response.examples }}
{{ $example = partial "json-schema/resolve-refs" (dict "schema" $response.examples "path" $path) }} {{ $example = partial "json-schema/resolve-refs" (dict "schema" $response.examples "path" $path) }}