Coverage for src/lexigram/web/docs/decorators.py: 36%
11 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1"""OpenAPI decorators for lexigram-web."""
2from __future__ import annotations
4from typing import Any
6from lexigram.web.routing.types import RoutableProtocol
9def openapi(
10 summary: str | None = None,
11 description: str | None = None,
12 tags: list[str] | None = None,
13 operation_id: str | None = None,
14 responses: dict[int | str, Any] | None = None,
15 deprecated: bool = False,
16 **kwargs: Any,
17) -> Any:
18 """Decorator to add OpenAPI metadata to an endpoint."""
20 def decorator(func: RoutableProtocol) -> RoutableProtocol:
21 # Initialise route config dict if it doesn't exist yet
22 if not hasattr(func, "_route_config") or func._route_config is None:
23 func._route_config = {}
25 # Merge new metadata; _route_config is guaranteed to be a dict here
26 route_config: dict[str, Any] = func._route_config
27 route_config.update(
28 {
29 "summary": summary,
30 "description": description,
31 "tags": tags,
32 "operation_id": operation_id,
33 "responses": responses,
34 "deprecated": deprecated,
35 **kwargs,
36 },
37 )
38 return func
40 return decorator