lavkach3
1from typing import Any, Type2
3from pydantic import BaseModel, model_validator4from typing import Optional, List5
6
7class GenericListSchema(BaseModel):8"""9example
10class CompanyListSchema(BaseListSchame):
11data: List[CompanyScheme] = []
12"""
13size: int = 014cursor: int = 015prevcursor: int = 016data: Optional[List] = []17
18
19@model_validator(mode='before')20def mixin(cls: Type['Model'], data: Any) -> 'Model':21if data['data']:22if not getattr(data['data'][0], 'lsn'):23cursor = 9999924else:25cursor = max([i.lsn for i in data['data']])26return {27'size': len(data['data']),28'data': data['data'],29'cursor': cursor,30}31return data32
33class Config:34from_attributes = False35arbitrary_types_allowed = True36extra = 'allow'37
38