-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathbody_field_table.j2
18 lines (18 loc) · 1.54 KB
/
body_field_table.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{% 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= " " * 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) | trim }} |
{% endfor %}{{ notes.render() }}{{ enums.field_tables(ns.flat | map(attribute="field") | selectattr("type", "eq", "enum"), notes) -}}
{%- endif %}{% endmacro %}