2021-01-30 00:30:39 +01:00
|
|
|
{{/*
|
|
|
|
|
|
2023-09-19 19:26:07 +02:00
|
|
|
This template is used to render an HTTP API, given an OpenAPI definition.
|
2021-01-30 00:30:39 +01:00
|
|
|
|
|
|
|
|
It expects to be passed two parameters:
|
|
|
|
|
|
|
|
|
|
* a `spec` parameter identifying the spec, which must be the name of
|
|
|
|
|
a directory under /data/api
|
2023-09-19 19:26:07 +02:00
|
|
|
* an `api` parameter, identifying an OpenAPI definition,
|
2021-01-30 00:30:39 +01:00
|
|
|
which is the name of a schema file under "data/api/$spec".
|
|
|
|
|
The file extension is omitted. For example:
|
|
|
|
|
|
|
|
|
|
{{% http-api spec="server-server" api="public_rooms" %}}
|
2024-06-20 17:39:50 +02:00
|
|
|
* an optional `anchor_base` parameter, which should be used as a
|
|
|
|
|
prefix for the HTML IDs generated by this template. It should only
|
|
|
|
|
be necessary to provide one for duplicate endpoints.
|
2021-01-30 00:30:39 +01:00
|
|
|
|
|
|
|
|
This template replaces the old {{*_http_api}} template.
|
|
|
|
|
|
|
|
|
|
*/}}
|
|
|
|
|
|
|
|
|
|
{{ $spec := .Params.spec}}
|
|
|
|
|
{{ $api := .Params.api}}
|
2024-06-20 17:39:50 +02:00
|
|
|
{{ $anchor_base := .Params.anchor_base}}
|
2021-01-30 00:30:39 +01:00
|
|
|
|
2025-12-18 15:59:18 +01:00
|
|
|
{{/*
|
|
|
|
|
|
|
|
|
|
Figure out which Page object to pass to the `openapi/render-api` partial.
|
|
|
|
|
Either our own, or one stored under `endpoint_page` in the Scratch, if one
|
|
|
|
|
exists.
|
|
|
|
|
|
|
|
|
|
*/}}
|
|
|
|
|
{{ $target_page := .Page }}
|
|
|
|
|
{{ with .Page.Scratch.Get "endpoint_page" }}
|
|
|
|
|
{{ $target_page = . }}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ $module_name := .Page.Scratch.Get "endpoint_module" }}
|
|
|
|
|
|
2021-01-30 00:30:39 +01:00
|
|
|
{{ $api_data := index .Site.Data.api .Params.spec .Params.api }}
|
2023-06-07 14:16:29 +02:00
|
|
|
{{ $base_url := (index $api_data.servers 0).variables.basePath.default }}
|
2024-03-19 15:50:49 +01:00
|
|
|
{{ $path := delimit (slice "api" $spec $api) "/" }}
|
2021-01-30 00:30:39 +01:00
|
|
|
|
2024-04-09 19:06:53 +02:00
|
|
|
{{ $api_data = partial "json-schema/resolve-refs" (dict "schema" $api_data "path" $path) }}
|
2024-04-17 10:29:34 +02:00
|
|
|
{{ $api_data = partial "json-schema/resolve-allof" $api_data }}
|
2024-04-09 19:06:53 +02:00
|
|
|
|
2025-12-18 15:59:18 +01:00
|
|
|
{{ partial "openapi/render-api" (dict "api_data" $api_data "base_url" $base_url "anchor_base" $anchor_base "page" $target_page "module" $module_name) }}
|