Skip to content

Commit 160fadb

Browse files
committed
Fix rendering of responses with empty bodies
1 parent 6c4aabd commit 160fadb

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

layouts/partials/openapi/render-responses.html

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,52 @@ <h2>Responses</h2>
3535

3636
</table>
3737

38-
{{ range $code, $response := $responses }}
39-
38+
{{ range $code, $response := $responses }}
4039
{{ if $response.schema }}
4140

41+
<h3>{{$code}} response</h3>
42+
4243
{{ $schema := partial "json-schema/resolve-refs" (dict "schema" $response.schema "path" $path) }}
4344
{{ $schema := partial "json-schema/resolve-allof" $schema }}
4445

45-
{{ if or $schema.properties (eq $schema.type "array") }}
46-
<h3>{{ $code}} response</h3>
47-
48-
{{/*
49-
All this is to work out how to express the content of the response
50-
in the case where it is an array.
51-
*/}}
52-
{{ if eq $schema.type "array" }}
53-
{{ $type_of := "" }}
54-
{{ if reflect.IsSlice $schema.items }}
55-
{{ $types := slice }}
56-
{{ range $schema.items }}
57-
{{ if .title }}
58-
{{ $types = $types | append .title}}
59-
{{ else }}
60-
{{ $types = $types | append .type }}
61-
{{ end }}
46+
{{/*
47+
All this is to work out how to express the content of the response
48+
in the case where it is an array.
49+
*/}}
50+
{{ if eq $schema.type "array" }}
51+
{{ $type_of := "" }}
52+
{{ if reflect.IsSlice $schema.items }}
53+
{{ $types := slice }}
54+
{{ range $schema.items }}
55+
{{ if .title }}
56+
{{ $types = $types | append .title}}
57+
{{ else }}
58+
{{ $types = $types | append .type }}
6259
{{ end }}
63-
{{ $type_of = delimit $types ", "}}
64-
{{ else }}
65-
{{ $type_of = $schema.items.title }}
6660
{{ end }}
67-
<p>Array of <code>{{ $type_of }}</code>.</p>
61+
{{ $type_of = delimit $types ", "}}
62+
{{ else }}
63+
{{ $type_of = $schema.items.title }}
6864
{{ end }}
65+
<p>Array of <code>{{ $type_of }}</code>.</p>
66+
{{ end }}
6967

70-
{{ $additional_types := partial "json-schema/resolve-additional-types" $schema }}
71-
{{ $additional_types = uniq $additional_types }}
72-
{{ range $additional_types }}
73-
{{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }}
74-
{{ end }}
7568

69+
{{/*
70+
render object tables for any objects referenced in the
71+
response. (This will be a no-op for response types which aren't
72+
objects or arrays.)
73+
*/}}
74+
{{ $additional_types := partial "json-schema/resolve-additional-types" $schema }}
75+
{{ $additional_types = uniq $additional_types }}
76+
{{ range $additional_types }}
77+
{{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }}
78+
{{ end }}
79+
80+
{{/*
81+
render an example. currently this is only supported for arrays and objects.
82+
*/}}
83+
{{ if or (eq $schema.type "object") (eq $schema.type "array") }}
7684
{{ $example := partial "json-schema/resolve-example" $schema }}
7785
{{ if $response.examples }}
7886
{{ $example = partial "json-schema/resolve-refs" (dict "schema" $response.examples "path" $path) }}

0 commit comments

Comments
 (0)