d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
59 lines
1.7 KiB
Markdown
59 lines
1.7 KiB
Markdown
---
|
|
paths:
|
|
- "**/app/**/*.py"
|
|
- "**/fastapi/**/*.py"
|
|
- "**/*_api.py"
|
|
---
|
|
# FastAPI Rules
|
|
|
|
Use these rules for FastAPI projects alongside the general Python rules.
|
|
|
|
## Structure
|
|
|
|
- Put app construction in `create_app()`.
|
|
- Keep routers thin; move persistence and business behavior into services or CRUD helpers.
|
|
- Keep request schemas, update schemas, and response schemas separate.
|
|
- Keep database sessions and auth in dependencies.
|
|
|
|
## Async
|
|
|
|
- Use `async def` for endpoints that perform I/O.
|
|
- Use async database and HTTP clients from async endpoints.
|
|
- Do not call `requests`, sync SQLAlchemy sessions, or blocking file/network operations from async routes.
|
|
|
|
## Dependency Injection
|
|
|
|
```python
|
|
@router.get("/users/{user_id}")
|
|
async def get_user(
|
|
user_id: str,
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
...
|
|
```
|
|
|
|
Do not create `SessionLocal()` or long-lived clients inside route handlers.
|
|
|
|
## Schemas
|
|
|
|
- Never include passwords, password hashes, access tokens, refresh tokens, or internal auth state in response models.
|
|
- Use `response_model` on endpoints that return application data.
|
|
- Use field constraints instead of hand-written validation when Pydantic can express the rule.
|
|
|
|
## Security
|
|
|
|
- Keep CORS origins environment-specific.
|
|
- Do not combine wildcard origins with credentialed CORS.
|
|
- Validate JWT expiry, issuer, audience, and algorithm.
|
|
- Rate-limit auth and write-heavy endpoints.
|
|
- Redact credentials, cookies, authorization headers, and tokens from logs.
|
|
|
|
## Testing
|
|
|
|
- Override the exact dependency used by `Depends`.
|
|
- Clear `app.dependency_overrides` after tests.
|
|
- Prefer async test clients for async applications.
|
|
|
|
See skill: `fastapi-patterns`.
|