Files
brojs-task-6a1d75e5fd30e81c…/models.py
T

28 lines
967 B
Python

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"]