Skip to content

Commit 64d0159

Browse files
feat: enforce openapi contract for admin audit APIs and add docs
Co-authored-by: MinecraftFuns <25814618+MinecraftFuns@users.noreply.github.com> Agent-Logs-Url: https://github.com/BTreeMap/OneShot/sessions/bdc10cae-a610-4dbe-be98-e85ae99c06a3
1 parent 5b95adf commit 64d0159

10 files changed

Lines changed: 728 additions & 21 deletions

File tree

AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ You are expected to execute these commands in your workspace terminal to verify
5858
2. **Test-Driven:** Write `pytest` or `vitest` tests for your new logic *before* or alongside the implementation.
5959
3. **Adversarial Testing:** When writing security or token logic, write tests that specifically attempt to bypass the mechanism (e.g., concurrent requests, invalid headers).
6060
4. **Self-Correction:** Run the formatters, linters, and test suites. If a test fails, read the error output and fix your code autonomously. Do not submit a Pull Request with failing tests.
61+
62+
## 6. OpenAPI Contract (MANDATORY)
63+
- The backend OpenAPI schema is the **single source of truth** for frontend API types.
64+
- Do not handwrite request/response interfaces for backend routes when generated OpenAPI types exist.
65+
- Regenerate schema and TS types whenever backend API shapes change:
66+
- `cd web && npm run gen`
67+
- Import route/schema types from `web/src/api/openapi.ts` (or curated exports in `web/src/api/types.ts`) and use them directly in page/service code.
68+
- Keep compile-time route assertions in `web/src/api/types.ts` up to date for newly added endpoints so type drift is caught by TypeScript.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# OneShot
22
OneShot is a zero-trust file transfer portal. It replaces user accounts with single-use links to eliminate credential liability. Files are anonymized and stripped of executable risks. Access tokens bypass server logs, and upload windows close instantly upon completion.
3+
4+
## API Contract and Type Safety
5+
6+
OneShot treats OpenAPI as the contract between backend and frontend.
7+
8+
- Backend schema source: `api/openapi.json`
9+
- Generated frontend contract: `web/src/api/openapi.ts`
10+
- Curated contract aliases/assertions: `web/src/api/types.ts`
11+
12+
When backend API shapes change, regenerate the contract and types:
13+
14+
```bash
15+
cd web
16+
npm run gen
17+
```
18+
19+
This flow prevents type drift by compiling frontend code against the generated schema-derived types.
20+
21+
## Documentation
22+
23+
Project documentation is organized under `docs/`:
24+
25+
- `docs/openapi-contract.md` – contract workflow and enforcement rules

api/alembic/versions/56fd3d38fe31_add_timestamps.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
def upgrade() -> None:
2222
"""Upgrade schema."""
2323
# ### commands auto generated by Alembic - please adjust! ###
24-
op.add_column('file_metadata', sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False))
25-
op.add_column('oneshot_tokens', sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False))
24+
op.add_column(
25+
"file_metadata",
26+
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
27+
)
28+
op.add_column(
29+
"oneshot_tokens",
30+
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
31+
)
32+
op.execute("UPDATE file_metadata SET created_at = CURRENT_TIMESTAMP WHERE created_at IS NULL")
33+
op.execute("UPDATE oneshot_tokens SET created_at = CURRENT_TIMESTAMP WHERE created_at IS NULL")
2634
# ### end Alembic commands ###
2735

2836

0 commit comments

Comments
 (0)