55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any, Generic, Literal, TypeVar
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
DataT = TypeVar("DataT")
|
|
|
|
|
|
class Envelope(BaseModel, Generic[DataT]):
|
|
data: DataT
|
|
|
|
|
|
class ItemList(BaseModel, Generic[DataT]):
|
|
items: list[DataT]
|
|
total: int
|
|
|
|
|
|
class PaginatedEnvelope(ItemList[DataT], Generic[DataT]):
|
|
limit: int
|
|
offset: int
|
|
|
|
|
|
class PaginationEnvelope(BaseModel):
|
|
items: list
|
|
total: int
|
|
limit: int = Field(default=50)
|
|
offset: int = Field(default=0)
|
|
|
|
|
|
class ApiErrorItem(BaseModel):
|
|
code: str
|
|
message: str
|
|
details: dict = Field(default_factory=dict)
|
|
|
|
|
|
class ApiErrorEnvelope(BaseModel):
|
|
error: str
|
|
message: str
|
|
details: dict | list = Field(default_factory=dict)
|
|
request_id: str | None = None
|
|
|
|
|
|
class GeoJsonFeature(BaseModel):
|
|
type: Literal["Feature"]
|
|
id: str | int | None = None
|
|
geometry: dict[str, Any] | None
|
|
properties: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class GeoJsonFeatureCollection(BaseModel):
|
|
type: Literal["FeatureCollection"]
|
|
features: list[GeoJsonFeature]
|