Add models module
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-31 17:10:18 +00:00
parent da56f82ff5
commit 8bddc8353a

View File

@@ -0,0 +1,85 @@
"""Endpoint models for API documentation."""
from enum import Enum
from typing import Optional, Any
from pydantic import BaseModel, Field
class HTTPMethod(str, Enum):
"""HTTP methods supported by endpoints."""
GET = "GET"
POST = "POST"
PUT = "PUT"
PATCH = "PATCH"
DELETE = "DELETE"
OPTIONS = "OPTIONS"
HEAD = "HEAD"
class ParameterIn(str, Enum):
"""Parameter location."""
PATH = "path"
QUERY = "query"
HEADER = "header"
COOKIE = "cookie"
BODY = "body"
class Parameter(BaseModel):
"""API parameter model."""
name: str
type: str = "string"
required: bool = False
description: str = ""
location: ParameterIn = ParameterIn.QUERY
default: Optional[str] = None
example: Optional[str] = None
class Response(BaseModel):
"""API response model."""
status_code: int = 200
description: str = ""
content_type: str = "application/json"
example: Optional[dict[str, Any]] = None
response_schema: Optional[str] = Field(None, alias="schema")
class Endpoint(BaseModel):
"""API endpoint model."""
path: str
method: HTTPMethod
summary: str = ""
description: str = ""
tags: list[str] = Field(default_factory=list)
parameters: list[Parameter] = Field(default_factory=list)
request_body: Optional[Parameter] = None
responses: list[Response] = Field(default_factory=list)
deprecated: bool = False
operation_id: Optional[str] = None
security: list[str] = Field(default_factory=list)
file_path: Optional[str] = None
line_number: Optional[int] = None
def get_full_path(self, base_path: str = "") -> str:
"""Get the full endpoint path with base path."""
full = f"{base_path.rstrip('/')}/{self.path.lstrip('/')}"
return full
def get_method_color(self) -> str:
"""Get color for HTTP method badge."""
colors = {
HTTPMethod.GET: "#61affe",
HTTPMethod.POST: "#49cc90",
HTTPMethod.PUT: "#fca130",
HTTPMethod.PATCH: "#50e3c2",
HTTPMethod.DELETE: "#f93e3e",
HTTPMethod.OPTIONS: "#0d5aa7",
HTTPMethod.HEAD: "#9012fe",
}
return colors.get(self.method, "#999999")