diff --git a/src/models.py b/src/models.py new file mode 100644 index 0000000..cc25303 --- /dev/null +++ b/src/models.py @@ -0,0 +1,24 @@ +"""Pydantic models for API events.""" +from __future__ import annotations + +from typing import Literal, Union + +from pydantic import BaseModel, Field, Annotated + +class HttpOkEvent(BaseModel): + """Successful HTTP event with status 200.""" + kind: Literal["ok"] = Field("ok", description="Event kind: ok") + status: Literal[200] = Field(200, description="HTTP status code") + path: str = Field(..., description="Request path") + duration_ms: int = Field(..., description="Duration in milliseconds") + +class HttpErrorEvent(BaseModel): + """Failed HTTP event with 4xx or 5xx status.""" + kind: Literal["error"] = Field("error", description="Event kind: error") + status: int = Field(..., description="HTTP status code (4xx/5xx)") + path: str = Field(..., description="Request path") + error_message: str = Field(..., description="Error message") + +ApiEvent = Annotated[Union[HttpOkEvent, HttpErrorEvent], Field(discriminator="kind")] + +__all__ = ["HttpOkEvent", "HttpErrorEvent", "ApiEvent"] \ No newline at end of file