1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
{% if base_class != "BaseModel" and "," not in base_class and not fields and not config and not description -%}
{# if this is just going to be `class Foo(Bar): pass`, then might as well just make Foo
an alias for Bar: every pydantic model class consumes considerable memory. #}
{{ class_name }} = {{ base_class }}
{% else -%}
{% for decorator in decorators -%}
{{ decorator }}
{% endfor -%}
class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comment }}{% endif %}
{%- if description %}
"""
{{ description | escape_docstring | indent(4) }}
"""
{%- endif %}
{%- if schema_id is defined and schema_id %}
__schema_id__ = "{{ schema_id }}"
{%- endif %}
{%- if path is defined and path %}
__path__ = "{{ path }}"
{%- endif %}
{%- if not fields and not description and not config and not (schema_id is defined and schema_id) %}
pass
{%- endif %}
{%- if config %}
{%- filter indent(4) %}
{% include 'ConfigDict.jinja2' %}
{%- endfilter %}
{%- endif %}
{%- for field in fields %}
{%- if not field.annotated and field.field %}
{{ field.name }}: {{ field.type_hint }} = {{ field.field }}
{%- else %}
{%- if field.annotated %}
{{ field.name }}: {{ field.annotated }}
{%- else %}
{{ field.name }}: {{ field.type_hint }}
{%- endif %}
{%- if not field.has_default_factory_in_field and not field.required and (field.represented_default != 'None' or not field.strip_default_none or field.data_type.is_optional)
%} = {{ field.represented_default }}
{%- endif -%}
{%- endif %}
{%- if field.docstring %}
"""
{{ field.docstring | escape_docstring | indent(4) }}
"""
{%- if field.use_inline_field_description and not loop.last %}
{% endif %}
{%- elif field.inline_field_docstring %}
{{ field.inline_field_docstring }}
{%- if not loop.last %}
{% endif %}
{%- endif %}
{%- for method in methods -%}
{{ method }}
{%- endfor -%}
{%- endfor -%}
{%- endif %}
|