{# Bengal OpenAPI Schema Viewer ============================ Recursive component for displaying JSON Schema / OpenAPI schema objects. Supports nested objects, arrays, enums, and examples. Context: - schema: OpenAPISchemaMetadata or dict with: - schema_type: Type (object, array, string, etc.) - properties: Dict of property definitions - required: Tuple of required property names - enum: Enum values (optional) - example: Example value (optional) - items: Array item schema (for arrays) - description: Schema description - name: Schema name (optional, for display) - depth: Nesting depth (for indentation, default 0) Kida Features: - {% cache %} for expensive recursive rendering (500+ endpoint specs) - {% with %} for nil-safe optional sections - Recursive {% include %} for nested objects - Optional chaining (?.) and null coalescing (??) #} {% let schema_type = schema?.schema_type ?? 'object' %} {% let properties = schema?.properties ?? {} %} {% let required_props = schema?.required ?? () %} {% let enum_vals = schema?.enum ?? none %} {% let example_val = schema?.example ?? none %} {% let items_schema = schema?.items ?? none %} {% let description = schema?.description ?? '' %} {% let current_depth = depth ?? 0 %} {% let max_depth = 4 %} {% cache 'schema-viewer-' ~ (name ?? 'anon') ~ '-' ~ current_depth %}
{# Schema Header #} {% if name %}
{{ name }} {{ schema_type }}
{% end %} {# Description #} {% if description %}
{{ description | markdownify | safe }}
{% end %} {# Object Properties #} {% if schema_type == 'object' and properties | length > 0 %}
{% for prop_name, prop_schema in properties |> items %} {% let is_required = prop_name in required_props %} {% let prop_type = prop_schema?.type ?? prop_schema?.schema_type ?? 'any' %} {% let prop_desc = prop_schema?.description ?? '' %} {% let prop_enum = prop_schema?.enum %} {% let prop_default = prop_schema?.default %}
{{ prop_name }} {{ prop_type }} {% if is_required %} required {% end %}
{% if prop_desc %}
{{ prop_desc }}
{% end %} {# Nested object (recursive, with depth limit) #} {% if prop_type == 'object' and current_depth < max_depth %} {% let schema=prop_schema %} {% let depth=current_depth + 1 %} {% include 'autodoc/openapi/partials/schema-viewer.html' %} {% end %} {# Array items #} {% if prop_type=='array' and prop_schema?.items and current_depth < max_depth %}
Items: {% let schema = prop_schema.items %} {% let depth = current_depth + 1 %} {% include 'autodoc/openapi/partials/schema-viewer.html' %}
{% end %} {# Property enum #} {% with prop_enum as enums %} {% if enums | length > 0 %}
Allowed: {% for val in enums %} {{ val }} {% end %}
{% end %} {% end %} {# Property default #} {% with prop_default as default %}
Default: {{ default }}
{% end %}
{% end %}
{% end %} {# Array Items Schema #} {% if schema_type == 'array' and items_schema %}
Array of: {% if current_depth < max_depth %} {% let schema=items_schema %} {% let depth=current_depth + 1 %} {% include 'autodoc/openapi/partials/schema-viewer.html' %} {% else %} {{ items_schema?.type ?? items_schema?.schema_type ?? 'any' }} {% end %}
{% end %} {# Enum Values (top-level) #} {% with enum_vals as enums %} {% if enums | length > 0 %}
Allowed values: {% for val in enums %} {{ val }} {% end %}
{% end %} {% end %} {# Example Value #} {% with example_val as example %}
Example
{{ example | tojson(indent=2) }}
{% end %}
{% end %}