You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
681 B
Python
27 lines
681 B
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, ConfigDict, field_serializer
|
|
|
|
|
|
def to_camel(value: str) -> str:
|
|
head, *tail = value.split("_")
|
|
return head + "".join(item[:1].upper() + item[1:] for item in tail)
|
|
|
|
|
|
class ItiModel(BaseModel):
|
|
model_config = ConfigDict(
|
|
alias_generator=to_camel,
|
|
populate_by_name=True,
|
|
from_attributes=True,
|
|
use_enum_values=True,
|
|
)
|
|
|
|
@field_serializer("*", when_used="json")
|
|
def serialize_datetime(self, value: Any) -> Any:
|
|
if isinstance(value, datetime):
|
|
return value.isoformat()
|
|
return value
|