@dryv/pydantic-modelsv0.1.0
Standalone Pydantic v2 schema and validation package.
dryv pack add @dryv/pydantic-modelsfrom enum import Enum
import json
{% macro py_json(text) -%}
{%- if text == 'true' -%}True
{%- elif text == 'false' -%}False
{%- elif text == 'null' -%}None
{%- else -%}{{ text }}
{%- endif -%}
{%- endmacro %}
class {{ file.symbol }}(Enum):
{% for item in property.enum.values %}
{{ item.name.constant }} = {{ py_json(item.value_json) }}
{% endfor %}
def __str__(self) -> str:
if isinstance(self.value, str):
return self.value
return json.dumps(self.value, separators=(",", ":"))