mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-01-11 10:03:43 +01:00
* Remove redundant call to resolve-allof All of the callers to resolve-additional-types already call resolve-allof (or if not, they should), so this is redundant. * Update `resolve-additional-types` to take a dict I want to add more params to this, so first make it take a dict. * `render-object-table`: take a "title" rather than a "caption" ... which means we can use the result from resolve-additional-types directly. * render-object-table: support adding an anchor to generated tables. * resolve-additional-types: generate an id for each returned type * render-event: pass an anchor_base into resolve-additional-types This means that it will generate an anchor for each type, whihc will then be passed into render-object-table and used as an `id` for the table. * render-operation: pass an anchor_base into resolve-additional-types * newsfiles
102 lines
3.2 KiB
HTML
102 lines
3.2 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"
|
|
* `anchor_base`: a prefix to add to the HTML anchors generated for each object
|
|
|
|
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 }}
|
|
{{ $anchor_base := .anchor_base }}
|
|
|
|
<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 }}
|
|
|
|
<h3>{{$code}} response</h3>
|
|
|
|
{{ $schema := partial "json-schema/resolve-refs" (dict "schema" $response.schema "path" $path) }}
|
|
{{ $schema := partial "json-schema/resolve-allof" $schema }}
|
|
|
|
{{/*
|
|
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 }}
|
|
|
|
|
|
{{/*
|
|
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" (dict "schema" $schema "anchor_base" $anchor_base) }}
|
|
{{ $additional_types = uniq $additional_types }}
|
|
{{ range $additional_types }}
|
|
{{ partial "openapi/render-object-table" . }}
|
|
{{ 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) }}
|
|
{{ $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 }}
|