docs-matrix-spec/layouts/partials/openapi/render-operation.html
Kévin Commaille 5fbfdd6821
Fix generated HTML (#1880)
* Add tr as child of thead in HTML tables

It is invalid HTML for th to be the direct children of thead

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Remove unnecessary HTML code end tag

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Avoid nesting p HTML elements

A p HTML element cannot contain other block elements,
so the "parent" element is closed when the first "child" one is opened.

We need to use Page.RenderString with options
to force Hugo to keep the wrapping p elements
even if the content contains a single paragraph.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Add missing HTML details end tags

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Replace HTML a self-closing tag with start and end tags

The a element start and end tags are mandatory.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Replace obsolete HTML name attribute with id

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Add changelog

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-20 09:42:40 +01:00

87 lines
2.8 KiB
HTML

{{/*
Render a single HTTP API operation: that is, a method+endpoint combination, given:
* `method`: the method, e.g. GET, PUT
* `endpoint`: the endpoint
* `operation_data`: the OpenAPI data for the operation
This template renders the operation as a `<section>` containing:
* an `<h1>` heading containing the method and endpoint
* a `<details>` element containing the details, including:
* operation description
* basic info about the operation
* request details
* response details
*/}}
{{ $method := .method }}
{{ $endpoint := .endpoint }}
{{ $operation_data := .operation_data }}
{{ $anchor := anchorize $endpoint }}
<section class="rendered-data http-api {{ $method }}">
<details {{ if not site.Params.ui.rendered_data_collapsed }}open{{ end }}>
<summary>
<h1 id="{{ lower $method }}{{ $anchor }}">
<span class="http-api-method {{ $method }}">{{ $method }}</span>
<span class="endpoint{{ if $operation_data.deprecated }} deprecated-inline{{ end }}">{{ $endpoint }}</span>
</h1>
</summary>
<hr/>
{{ if $operation_data.deprecated }}
{{ partial "alert" (dict "type" "warning" "omit_title" "true" "content" "This API is deprecated and will be removed from a future release.") }}
{{ end }}
{{ if (index $operation_data "x-addedInMatrixVersion") }}
{{ partial "added-in" (dict "v" (index $operation_data "x-addedInMatrixVersion")) }}
{{ end }}
{{ if (index $operation_data "x-changedInMatrixVersion") }}
{{ partial "changed-in" (dict "changes_dict" (index $operation_data "x-changedInMatrixVersion")) }}
{{ end -}}
{{ $operation_data.description | page.RenderString (dict "display" "block") }}
<table class="basic-info">
<tr>
<th>Rate-limited:</th>
{{ $rate_limited := index $operation_data.responses "429" }}
<td>{{ if $rate_limited }}Yes{{ else }}No{{ end }}</td>
</tr>
<tr>
<th>Requires authentication:</th>
{{/*
Authentication is defined with the `security` key. We assume that the
key is not set if no authentication is necessary. If the key is set,
authentication is required unless it contains an item that is an empty
object.
*/}}
{{ $requires_authentication := "Yes" }}
{{ if $operation_data.security }}
{{ range $operation_data.security }}
{{ if eq (len (index $operation_data.security 0)) 0 }}
{{ $requires_authentication = "Optional" }}
{{ end }}
{{ end }}
{{ else }}
{{ $requires_authentication = "No" }}
{{ end }}
<td>{{ $requires_authentication }}</td>
</tr>
</table>
<hr/>
{{ partial "openapi/render-request" (dict "parameters" $operation_data.parameters "request_body" $operation_data.requestBody "anchor_base" $anchor ) }}
<hr/>
{{ partial "openapi/render-responses" (dict "responses" $operation_data.responses "anchor_base" $anchor ) }}
</details>
</section>