mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-03-13 15:04:10 +01:00
That way if we fix the rendering in one place, we fix it everywhere. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
83 lines
2.7 KiB
HTML
83 lines
2.7 KiB
HTML
{{/*
|
|
|
|
Render the request part of a single HTTP API operation, given:
|
|
|
|
* `parameters`: OpenAPI data specifying the parameters
|
|
* `request_body`: OpenAPI data specifying the request body
|
|
* `anchor_base`: a prefix to add to the HTML anchors generated for each object
|
|
|
|
This template renders:
|
|
* the "simple parameters" (header, path, query parameters)
|
|
* body parameters, which may be more complex, containing nested objects
|
|
* response body examples
|
|
|
|
*/}}
|
|
|
|
{{ $parameters := .parameters }}
|
|
{{ $request_body := .request_body }}
|
|
{{ $anchor_base := .anchor_base }}
|
|
{{ $anchor := printf "%s_request" $anchor_base }}
|
|
|
|
<h2>Request</h2>
|
|
|
|
{{ if or $parameters $request_body }}
|
|
|
|
{{ if $parameters }}
|
|
<h3>Request parameters</h3>
|
|
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $parameters "type" "header" "caption" "header parameters") }}
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $parameters "type" "path" "caption" "path parameters") }}
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $parameters "type" "query" "caption" "query parameters") }}
|
|
|
|
{{ end }}
|
|
|
|
{{ if $request_body }}
|
|
<h3>Request body</h3>
|
|
{{/*
|
|
A request can have several content types.
|
|
*/}}
|
|
{{ $json_body := index $request_body.content "application/json" }}
|
|
{{ if $json_body }}
|
|
{{/*
|
|
Display the JSON schemas
|
|
*/}}
|
|
{{ $schema := $json_body.schema }}
|
|
|
|
{{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema "anchor_base" $anchor) }}
|
|
{{ range $additional_types }}
|
|
{{ partial "openapi/render-object-table" . }}
|
|
{{ end }}
|
|
{{ else }}
|
|
{{/*
|
|
Show the content types and description.
|
|
*/}}
|
|
{{ partial "openapi/render-content-type" (dict "content_types" $request_body.content) }}
|
|
{{ end }}
|
|
|
|
<h3>Request body example</h3>
|
|
{{/*
|
|
Show all the examples.
|
|
*/}}
|
|
{{ range $mime, $body := $request_body.content }}
|
|
{{ $example := dict }}
|
|
|
|
{{ if $body.schema }}
|
|
{{ $example = partial "json-schema/resolve-example" $body.schema }}
|
|
{{ end }}
|
|
|
|
{{ if and (eq ($example | len) 0) $body.example }}
|
|
{{/*
|
|
If no example was generated from the schema, fallback to the
|
|
main example.
|
|
*/}}
|
|
{{ $example = $body.example }}
|
|
{{ end }}
|
|
|
|
{{ partial "render-example" (dict "example" $example "mime" $mime) }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ else }}
|
|
<p>No request parameters or request body.</p>
|
|
{{ end }}
|