* Use the resolve-refs partial as soon as possible Call it right after accessing the site.Data, since it is recursing it will solve all references in the tree. That way we don't need to wonder where to call it, we trust the validators that the refs will be used in the right place. * Enable strict $ref rule in OpenAPI validator * Document use of $ref to compose examples * Fix schema path in event-fields shortcode Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
115 lines
3.8 KiB
HTML
115 lines
3.8 KiB
HTML
{{/*
|
|
|
|
Render the response part of a single HTTP API operation, given:
|
|
|
|
* `responses`: OpenAPI data specifying the responses
|
|
* `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 }}
|
|
{{ $anchor_base := .anchor_base }}
|
|
|
|
<h2>Responses</h2>
|
|
|
|
<table class="response-table">
|
|
<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.content }}
|
|
<h3>{{$code}} response</h3>
|
|
{{/*
|
|
A response can have several content types.
|
|
*/}}
|
|
{{ $json_body := index $response.content "application/json" }}
|
|
{{ if $json_body }}
|
|
{{/*
|
|
Display the JSON schemas
|
|
*/}}
|
|
|
|
{{ $schema := partial "json-schema/resolve-allof" $json_body.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 $schema.items.anyOf }}
|
|
{{ $types := slice }}
|
|
{{ range $schema.items.anyOf }}
|
|
{{ 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) }}
|
|
{{ 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 $json_body.examples }}
|
|
{{ $example = $json_body.examples.response.value }}
|
|
{{ end }}
|
|
|
|
{{ $example_json := jsonify (dict "indent" " ") $example }}
|
|
{{ $example_json = replace $example_json "\\u003c" "<" }}
|
|
{{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }}
|
|
|
|
```json
|
|
{{ $example_json }}
|
|
```
|
|
{{ end }}
|
|
{{ else }}
|
|
{{/*
|
|
Show the content types and description.
|
|
*/}}
|
|
{{ $mimes := slice }}
|
|
{{ $descriptions := slice }}
|
|
{{ range $mime, $body := $response.content }}
|
|
{{ $mimes = $mimes | append $mime }}
|
|
{{ $descriptions = $descriptions | append $body.schema.description }}
|
|
{{ end }}
|
|
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions) }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|