{#-
API Authentication Component

Renders authentication and security information for the API.
Handles different authentication schemes safely.
-#}

{% from 'macros/safe_macros.md.jinja2' import safe_section, safe_render, safe_for %}

{% if element.metadata.security_schemes %}
{% call safe_section("api_authentication") %}
## Authentication

{% call(auth_scheme) safe_for(element.metadata.security_schemes, "*No authentication schemes defined.*") %}
{% call safe_render("security_scheme", auth_scheme) %}
### {{ auth_scheme.name | default('Authentication') }}

{% if auth_scheme.type %}
**Type:** {{ auth_scheme.type | title }}
{% endif %}

{% if auth_scheme.description %}
{{ item.description }}
{% endif %}

{% if item.type == 'http' %}
{% if item.scheme %}
**Scheme:** `{{ item.scheme }}`
{% endif %}
{% if item.bearer_format %}
**Bearer Format:** `{{ item.bearer_format }}`
{% endif %}
{% elif item.type == 'apiKey' %}
{% if item.in %}
**Location:** {{ item.in | title }}
{% endif %}
{% if item.name %}
**Parameter Name:** `{{ item.name }}`
{% endif %}
{% elif item.type == 'oauth2' %}
{% if item.flows %}
**OAuth2 Flows:**
{% for flow_type, flow in item.flows.items() %}
- **{{ flow_type | title }}**{% if flow.authorization_url %}: {{ flow.authorization_url }}{% endif %}
{% endfor %}
{% endif %}
{% endif %}

{% endcall %}
{% endcall %}
{% endcall %}
{% endif %}
