{#
Bengal OpenAPI Component Library (Kida)
=======================================
Self-contained {% def %} components for the OpenAPI endpoint template. Each
component receives all data it needs through explicit parameters instead of
ambient {% let %} context, so they are importable and isolated.
Migrated from (kept as reference/fallback partials):
- partials/endpoint-header.html -> endpoint_header(element, section)
- partials/param-row.html -> param_row(param)
- partials/request-body.html -> request_body(req_body)
- partials/responses.html -> responses(responses, response_scope=...)
- partials/code-samples.html -> code_samples(method, path, ...)
Usage:
{% from 'autodoc/openapi/_components.html' import
endpoint_header, param_row, request_body, responses, code_samples %}
Kida Features (confirmed against installed kida-templates 0.6.0):
- {% def name(param=default) %} with default values
- {% match %}/{% case %} for status code dispatch
- {% with %} for nil-safe optional sections
- {% spaceless %} for compact badge output
- {% from %} import of the recursive schema_viewer component
- Optional chaining (?.) and null coalescing (??)
#}
{% from 'autodoc/openapi/_schema.html' import schema_viewer %}
{# =============================================================================
ENDPOINT HEADER
Displays: breadcrumb, title, operation id, description, auth + tag badges.
Ported from partials/endpoint-header.html.
============================================================================= #}
{% def endpoint_header(element, section) %}
{% let meta = element.typed_metadata %}
{% let method = meta?.method ?? 'GET' %}
{% let path = meta?.path ?? '/unknown' %}
{% let summary = meta?.summary ?? element.name %}
{% let operation_id = meta?.operation_id %}
{% let tags = meta?.tags ?? () %}
{% let security = meta?.security ?? () %}
{# Section context: the endpoint's parent section is its FIRST tag's section,
whose parent is the REST API root. The endpoint has a single canonical page
(under its first tag), but it may carry secondary tags that each have their
own tag section ({root}/tags/{tag}/). Derive every tag's section URL from the
API root so secondary-tag chips cross-link to the right section rather than
all pointing at the current (first-tag) section. Link from real section hrefs
rather than named routes (this engine resolves url_for() string targets as
literal paths, not Flask-style endpoints). #}
{% let tag_section = section %}
{# The API root href already carries a trailing slash (section snapshot href),
so per-tag section URLs join as {root}tags/{tag-slug}/, matching the
{prefix}/tags/{tag} sections that section_builders.py creates. #}
{% let api_home_href = section?.parent?.href ?? section?.href ?? '/' %}
{% let tag_href = tag_section?.href ?? api_home_href %}
{{ summary }}
{# Operation ID (for developers) #}
{% with operation_id as op_id %}
{{ op_id }}
{{ default }}
{{ val }}{% if not loop.last %} {% end %}
{% end %}
{% end %}
{{ ex }}
{{ schema_name }}
{{ code }}
{% if description %}
{{ description }}
{% end %}
{{ ct }}
{{ schema_name }}
{{ ex | tojson(indent=2) }}
{{ generate_code_sample('curl', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ generate_code_sample('python', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ generate_code_sample('javascript', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ generate_code_sample('go', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ generate_code_sample('ruby', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ generate_code_sample('php', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}
{{ example | tojson(indent=2) }}