python-fastapi.model.mustache Maven / Gradle / Ivy
# coding: utf-8
from __future__ import annotations
from datetime import date, datetime # noqa: F401
import re # noqa: F401
from typing import Any, Dict, List, Optional # noqa: F401
from pydantic import AnyUrl, BaseModel, EmailStr, Field, validator # noqa: F401
{{#models}}
{{#model}}
{{#pyImports}}
{{import}}
{{/pyImports}}
{{/model}}
{{/models}}
{{#models}}
{{#model}}
class {{classname}}(BaseModel):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
{{classname}} - a model defined in OpenAPI
{{#vars}}
{{name}}: The {{name}} of this {{classname}}{{^required}} [Optional]{{/required}}.
{{/vars}}
"""
{{#vars}}
{{name}}: {{#required}}{{>model_field_type}}{{/required}}{{^required}}Optional[{{>model_field_type}}]{{/required}} = Field(alias="{{baseName}}"{{^required}}, default=None{{/required}})
{{/vars}}
{{#vars}}
{{#maximum}}
@validator("{{name}}")
def {{name}}_max(cls, value):
assert value <= {{maximum}}
return value
{{/maximum}}
{{#minimum}}
@validator("{{name}}")
def {{name}}_min(cls, value):
assert value >= {{minimum}}
return value
{{/minimum}}
{{#minLength}}
@validator("{{name}}")
def {{name}}_min_length(cls, value):
assert len(value) >= {{minLength}}
return value
{{/minLength}}
{{#maxLength}}
@validator("{{name}}")
def {{name}}_max_length(cls, value):
assert len(value) <= {{maxLength}}
return value
{{/maxLength}}
{{#pattern}}
@validator("{{name}}")
def {{name}}_pattern(cls, value):
assert value is not None and re.match(r"{{pattern}}", value)
return value
{{/pattern}}
{{/vars}}
{{/model}}
{{/models}}
{{classname}}.update_forward_refs()