{% import 'requirement.j2' as requirement %}
{% import 'stability.j2' as stability %}
{% import 'notes.j2' as notes %}
{% import 'enum_macros.j2' as enums %}
{% import 'examples_macros.j2' as examples %}
{% macro flatten(fields, ns, depth) %}{% if fields %}{% for f in fields | sort(attribute="id") %}
{% set ns.flat = [ns.flat, [{'field':f,'depth':depth}]] | flatten %}{% if f.fields %}{% set _= flatten(f.fields, ns, depth + 1) %}{% endif %}
{% endfor %}{% endif %}{% endmacro %}
{% macro field_name(field, depth) -%}
{%- set name= "&nbsp;" * 2 * depth ~ '`' ~ field.id ~ '`' -%}
{%- if (field.type == "map") or (field.type == "map[]") %}{{ name ~ ":"}}{% else -%}
{{ name }}{% endif %}{% endmacro %}
{#- Macro for creating body table -#}
{% macro generate(fields) %}{% if (fields | length > 0) %}{% set ns = namespace(flat=[])%}{% set _ = flatten(fields, ns, 0) %}| Body Field  | Type | Description  | Examples  | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
|---|---|---|---|---|---|
{% for f in ns.flat %}| {{ field_name(f.field, f.depth) }} | {{ f.field.type }} | {{ f.field.brief | trim }}{{ notes.add({"note": f.field.note}) }} | {{ examples.format(f.field) | trim }} | {{ requirement.render({"level": f.field.requirement_level, "name": f.field.id}, notes) | trim }} | {{ stability.badge(f.field.stability, f.field.deprecated, f.field.brief) | trim }} |
{% endfor %}{{ notes.render() }}{{ enums.field_tables(ns.flat | map(attribute="field") | selectattr("type", "eq", "enum"), notes) -}}
{%- endif %}{% endmacro %}
