You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
matrix-spec-proposals/layouts/partials/openapi/render-responses.html

92 lines
3.0 KiB
HTML

{{/*
Render the response part of a single HTTP API operation, given:
* `responses`: OpenAPI/Swagger data specifying the responses
* `path`: the path where this definition was found, to enable us to resolve "$ref"
This template renders:
* a summary of all the different responses
* details of the body for each response code
* body parameters, which may be more complex, containing nested objects
* response body examples
*/}}
{{ $responses := .responses }}
{{ $path := .path }}
<h2>Responses</h2>
<table class>
<thead>
<th class="col-status">Status</th>
<th class="col-status-description">Description</th>
</thead>
{{ range $code, $response := $responses }}
<tr>
<td><code>{{ $code }}</code></td>
<td>{{ $response.description | markdownify }}</td>
</tr>
{{ end }}
</table>
{{ range $code, $response := $responses }}
{{ if $response.schema }}
{{ $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") }}
<h3>{{ $code}} response</h3>
{{/*
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 }}
{{ end }}
{{ $type_of = delimit $types ", "}}
{{ else }}
{{ $type_of = $schema.items.title }}
{{ end }}
<p>Array of <code>{{ $type_of }}</code>.</p>
{{ 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 }}
{{ $example := partial "json-schema/resolve-example" $schema }}
{{ if $response.examples }}
{{ $example = partial "json-schema/resolve-refs" (dict "schema" $response.examples "path" $path) }}
{{ $example = index $example "application/json" }}
{{ end }}
{{ $example_json := jsonify (dict "indent" " ") $example }}
{{ $example_json = replace $example_json "\\u003c" "<" }}
{{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }}
```json
{{ $example_json }}
```
{{ end }}
{{ end }}
{{ end }}