From 0cc43ea669dd971496b809bf98446bb0baa3265f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B8=D0=BD=D0=B0=D1=80=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=D1=82=D0=BE=D0=B2?= Date: Wed, 10 Jun 2026 09:57:03 +0000 Subject: [PATCH] Initial solution: add models.py --- models.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 models.py 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"]