-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
it is fine if you dont want to type python. But tying the fastapi endpoints is important for ts typesafety.
We can add a checking script like this
import inspect
import sys
from fastapi.routing import APIRoute
from app.main import app
def check_endpoint_signatures():
violations = []
for route in app.routes:
# We only care about user-defined API routes, not internal router logic
if isinstance(route, APIRoute):
endpoint = route.endpoint
name = f"{endpoint.__module__}.{endpoint.__name__}"
sig = inspect.signature(endpoint)
# 1. Check Return Type
if sig.return_annotation is inspect.Signature.empty:
violations.append(f"{name}: Missing return type annotation")
# 2. Check Arguments
for param_name, param in sig.parameters.items():
if param_name == "self": continue # Skip self for class-based views
if param.annotation is inspect.Signature.empty:
violations.append(f"{name}: Argument '{param_name}' missing type annotation")
if violations:
print("\n".join(violations))
sys.exit(1)
if __name__ == "__main__":
check_endpoint_signatures()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels