{#
    The `--heading-offset` command line parameter is exposed as `heading_offset` variable.

    See https://github.com/samuelcolvin/pydantic/blob/master/pydantic/fields.py for field structure.
    Each `field` in `fields` is instance of `ModelField`.
    Extra parameters unknown to pydantic are stored in `field.field_info.extra`.

    To see all possible values, run this generator with `--format debug`.
#}
{% macro heading(level) -%}
    {{ '#' * (heading_offset + level) }}
{%- endmacro %}
{% for field in fields %}
{{ heading(1) }} `{{ field.field_info.extra["env_names"]|list|first|upper }}`

*{% if field.required %}*Required*{% else %}Optional{% endif %}*{% if field.default != None %}, default value: `{{ field.default }}`{% endif %}

{% if field.field_info.description %}

{{ field.field_info.description }}
{% endif %}
    {% if field.field_info.extra["example"] %}

{{ heading(2) }} Examples

{{ field.field_info.extra["example"] }}
    {% endif %}
    {% if field.field_info.extra["possible_values"] %}
        {% set possible_values = field.field_info.extra["possible_values"] %}
    {% elif field.type_.__class__.__name__ == "_LiteralGenericAlias" %}
        {% set possible_values = field.type_.__args__ %}
    {% endif %}
    {% if possible_values %}

{{ heading(2) }} Possible values

        {% if not is_values_with_descriptions(possible_values) %}
            {% if possible_values|join("`, `")|length + 2 <= 75 %}
`{{ possible_values|join("`, `") }}`

            {% else %}
                {% for value in possible_values %}
- `{{ value }}`

                {% endfor %}
            {% endif %}
        {% else %}
            {% for value in possible_values %}
                {% if value.__class__.__name__ == "tuple" and value|length <= 2 %}
                    {% if value|length == 2 %}
- `{{ value[0] }}`: {{ value[1] }}
                    {% else %}
- `{{ value[0] }}`
                    {% endif %}
                {% else %}
- `{{ value }}`
                {% endif %}
            {% endfor %}

        {% endif %}
    {% endif %}
{% endfor %}