{#-
Request Body Component

Renders request body information including content types, schemas, and examples.
Handles different content types and complex request structures safely.
-#}

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

{% if element.metadata.request_body %}
{% call safe_section("request_body") %}
## Request Body

{% set request_body = element.metadata.request_body %}

{% if request_body.description %}
{{ request_body.description }}
{% endif %}

{% if request_body.required %}
:::{note}
Request body is required.
:::
{% else %}
:::{info}
Request body is optional.
:::
{% endif %}

{% if request_body.content %}
### Content Types

{% call(item) safe_for(request_body.content.items(), "*No content types defined.*") %}
{% set content_type = item[0] %}
{% set content_info = item[1] %}

#### `{{ content_type }}`

{% if content_info.schema %}
**Schema:**

{{ code_block(content_info.schema | tojson(indent=2), 'json', 'Request Schema') }}
{% endif %}

{% if content_info.example %}
**Example:**

{{ code_block(content_info.example | tojson(indent=2), 'json', 'Request Example') }}
{% endif %}

{% if content_info.examples %}
**Examples:**

{% call(item) safe_for(content_info.examples.items(), "*No examples provided.*") %}
{% set example_name = item[0] %}
{% set example_data = item[1] %}

##### {{ example_name | title }}

{% if example_data.summary %}
{{ example_data.summary }}
{% endif %}

{% if example_data.description %}
{{ example_data.description }}
{% endif %}

{{ code_block(example_data.value | tojson(indent=2), 'json') }}

{% endcall %}
{% endif %}

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