diff --git a/models.py b/models.py new file mode 100644 index 0000000..ce31de1 --- /dev/null +++ b/models.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import Annotated, Literal, Union + +from pydantic import BaseModel, Field + + +class HttpOkEvent(BaseModel): + kind: Literal["ok"] = Field("ok", description="Discriminator for OK events") + status: Literal[200] = Field(200, description="HTTP status code for success") + path: str = Field(..., description="Requested path") + duration_ms: int = Field(..., description="Duration of the request in milliseconds") + + +class HttpErrorEvent(BaseModel): + kind: Literal["error"] = Field("error", description="Discriminator for error events") + status: int = Field(..., description="HTTP status code for error (4xx/5xx)") + path: str = Field(..., description="Requested path") + error_message: str = Field(..., description="Error message returned by the server") + + +ApiEvent = Annotated[ + Union[HttpOkEvent, HttpErrorEvent], + Field(discriminator="kind") +] + +__all__ = ["HttpOkEvent", "HttpErrorEvent", "ApiEvent"]