paste-bin/ui/openapi.json
Jarian 985e070757 port: FastAPI rewrite built by the arch-llm spec pipeline
Spec-first port of the Flask app (still on main):
- schema.arch: signed arch-llm spec (single source of truth)
- paste_bin/: generated FastAPI backend, verified 51/51 frozen owner
  tests, 92.5% coverage (build r3, 2026-11-18)
- ui/: SPA + emitted OpenAPI contract (openapi.json + generated
  client.js); the app calls only window.PasteBinAPI
- 7 old bugs fixed (file raw 500, silent expiry, AVI-as-webp,
  stripped content, limiter leak, trusted mimetype, stale tmp)
- 62/62 live probe green; /health + JSON index added; JSON API

Full report on the wiki: 'FastAPI port (arch-llm pipeline)'.
2026-11-18 23:00:23 +00:00

452 lines
15 KiB
JSON

{
"openapi": "3.1.0",
"info": {
"title": "paste_bin",
"version": "1.0.0",
"description": "JSON API contract for paste_bin. Emitted deterministically from the signed arch-llm spec; error literals and defaults are pinned in the source descs."
},
"servers": [
{
"url": "/",
"description": "same-origin (serve UI + API under one origin)"
}
],
"paths": {
"/pastes": {
"post": {
"operationId": "postPastes",
"description": "multipart/form-data fields; ALL form fields have defaults so file-only uploads work without a content field (paste_type default 'text', title default '', expiry default '1d', content default '') and file is an optional UploadFile; rate limit FIRST: _limiter.allow(client IP) False -> 429 {error: 'Too many uploads. Please wait.'}; then parse_expiry(expiry), ValueError -> 400 {error: 'Invalid expiry'}; paste_type 'text': content must be non-empty after strip else 400 {error: 'Content cannot be empty'}; STORE content verbatim, never stripped (old app stripped stored content \u2014 fixed); paste_type 'image': no file -> 400 {error: 'No file selected'}; sanitize_filename, empty -> 400 same; extension must be an allowed image extension else 400 {error: 'Invalid image format'}; check_image_magic on the first 12 bytes else 400 {error: 'File content does not match image type.'}; read all bytes, len > MAX_UPLOAD_BYTES -> 413 {error: 'File too large. Maximum size is 20 MB.'}; write_upload; meta type 'image', title or original filename, mimetype derive_mimetype(ext), created_at ISO UTC, expires_at from parse_expiry; paste_type 'file': same no-file/sanitize checks; if is_text_ext: read bytes, decode utf-8 errors=replace, store as a 'text' paste WITH filename in meta; else: 20MB check, write_upload, meta type 'file', mimetype derive_mimetype(ext); any other paste_type -> 400 {error: 'Invalid paste type'}; the meta dict passed to save_meta uses EXACTLY the Paste record field names as keys (type, title, created_at, expires_at, filename, mimetype, filepath \u2014 never 'path'); success 201 PasteOut {id, title, type, created_at, expires_at, view: '/pastes/<id>', raw: '/pastes/<id>/raw', download: '/pastes/<id>/download'}",
"x-error-literals": {
"400": [
"Content cannot be empty",
"File content does not match image type.",
"Invalid expiry",
"Invalid image format",
"Invalid paste type",
"No file selected"
],
"413": [
"File too large. Maximum size is 20 MB."
],
"429": [
"Too many uploads. Please wait."
]
},
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"paste_type": {
"type": "string",
"default": "text"
},
"title": {
"type": "string",
"default": ""
},
"expiry": {
"type": "string",
"default": "1d"
},
"content": {
"type": "string",
"default": ""
},
"file": {
"type": "string",
"format": "binary"
}
}
}
}
}
},
"responses": {
"201": {
"description": "201",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PasteOut"
}
}
}
},
"400": {
"description": "Content cannot be empty",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
},
"413": {
"description": "File too large. Maximum size is 20 MB.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
},
"429": {
"description": "Too many uploads. Please wait.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
}
}
}
},
"/pastes/{paste_id}": {
"get": {
"operationId": "getPastesPaste_id",
"description": "load_meta None -> 404 {error: 'Paste not found'}; expired -> store.delete then 404 same body; text pastes: ViewOut with content read_content or '', filename from meta (set when the paste was created from an uploaded text file, else None), mimetype None; image/file: content None, filename and mimetype from meta",
"x-error-literals": {
"404": [
"Paste not found"
]
},
"responses": {
"200": {
"description": "200",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ViewOut"
}
}
}
},
"404": {
"description": "Paste not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
}
}
},
"parameters": [
{
"name": "paste_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^[a-f0-9]{16}$"
}
}
]
},
"/pastes/{paste_id}/download": {
"get": {
"operationId": "getPastesPaste_idDownload",
"description": "same 404/expiry-delete handling (uploaded file path read from meta['filepath']); text -> the content utf-8 bytes as an attachment, filename meta['filename'] or 'paste.txt', media type text/plain; image/file -> the uploaded file's bytes as an attachment, filename meta['filename'], media type meta['mimetype']; uploaded file missing on disk -> 404 {error: 'Paste not found'}",
"x-error-literals": {
"404": [
"Paste not found"
]
},
"responses": {
"200": {
"description": "200",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"404": {
"description": "Paste not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
}
}
},
"parameters": [
{
"name": "paste_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^[a-f0-9]{16}$"
}
}
]
},
"/pastes/{paste_id}/raw": {
"get": {
"operationId": "getPastesPaste_idRaw",
"description": "same 404/expiry-delete handling (uploaded file path read from meta['filepath']); text -> content utf-8 bytes, media type text/plain; charset=utf-8, no attachment; image -> uploaded file bytes, media type meta['mimetype']; file -> uploaded file bytes, media type meta['mimetype'] (old app fell through and 500'd for file pastes \u2014 fixed); uploaded file missing on disk -> 404 {error: 'Paste not found'}",
"x-error-literals": {
"404": [
"Paste not found"
]
},
"responses": {
"200": {
"description": "200",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"404": {
"description": "Paste not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrOut"
}
}
}
}
}
},
"parameters": [
{
"name": "paste_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^[a-f0-9]{16}$"
}
}
]
},
"/health": {
"get": {
"operationId": "getHealth",
"description": "{status: 'ok'}",
"responses": {
"200": {
"description": "200",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HealthOut"
}
}
}
}
}
}
},
"/": {
"get": {
"operationId": "getIndex",
"description": "{service: 'paste-bin', endpoints: ['/pastes', '/health']}",
"responses": {
"200": {
"description": "200",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/IndexOut"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Paste": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"title": {
"type": "string"
},
"created_at": {
"type": "string"
},
"expires_at": {
"type": "string",
"nullable": true
},
"filename": {
"type": "string",
"nullable": true
},
"mimetype": {
"type": "string",
"nullable": true
},
"filepath": {
"type": "string",
"nullable": true
}
},
"required": [
"type",
"title",
"created_at"
],
"description": "one paste's metadata, stored as JSON at store_dir/<id>; the on-disk JSON keys are EXACTLY these field names; type is 'text' | 'image' | 'file'; filepath set for image/file pastes (absolute path in upload_dir), None for text"
},
"ErrOut": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
},
"required": [
"error"
]
},
"PasteOut": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"created_at": {
"type": "string"
},
"expires_at": {
"type": "string",
"nullable": true
},
"view": {
"type": "string"
},
"raw": {
"type": "string"
},
"download": {
"type": "string"
}
},
"required": [
"id",
"title",
"type",
"created_at",
"view",
"raw",
"download"
]
},
"ViewOut": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"title": {
"type": "string"
},
"created_at": {
"type": "string"
},
"expires_at": {
"type": "string",
"nullable": true
},
"content": {
"type": "string",
"nullable": true
},
"filename": {
"type": "string",
"nullable": true
},
"mimetype": {
"type": "string",
"nullable": true
}
},
"required": [
"id",
"type",
"title",
"created_at"
]
},
"HealthOut": {
"type": "object",
"properties": {
"status": {
"type": "string"
}
},
"required": [
"status"
]
},
"IndexOut": {
"type": "object",
"properties": {
"service": {
"type": "string"
},
"endpoints": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"service",
"endpoints"
]
}
}
},
"x-contract-notes": {
"modules": {
"validate": "pure validation helpers: paste ids, expiry parsing, filename sanitizing, image magic-byte checks, mimetype derivation; no I/O, no state\nmodule constants: ALLOWED_IMAGE_EXTENSIONS = {png, jpg, jpeg, gif, bmp, webp, tiff}; ALLOWED_TEXT_EXTENSIONS = {txt, py, js, ts, c, cpp, h, java, rb, go, rs, md, json, xml, yaml, yml, html, css, sh, log, csv, sql, ini, cfg, toml, lua, php, swift, kt, scala, r, pl, hs, zig, nix}; MAX_UPLOAD_BYTES = 20 * 1024 * 1024",
"store": "file-backed paste persistence: store_dir holds JSON metadata at <id> and text content at <id>.txt; upload_dir holds binary uploads at <id>.<ext>; all metadata writes are atomic\nis_valid_paste_id is imported from paste_bin.validate at module top level \u2014 the single source of truth, never redefined or reimplemented locally",
"ratelimit": "per-IP sliding-window rate limiter for paste uploads, in-process state",
"headers": "security response headers for every response",
"api": "FastAPI multipart router over the store; at import time build a module-level PasteStore named _store from env STORE_FOLDER (default 'store') and env UPLOAD_FOLDER (default 'uploads') and call _store.start_cleanup_loop() on it; also a module-level UploadRateLimiter named _limiter constructed with bare class defaults \u2014 exactly `_limiter = UploadRateLimiter()` (10 attempts per 60s window; NO config indirection, NO inflated limits); every route merges security_headers(is_secure=<request scheme is https>) into the response headers\nerrors are JSON {error: str} with the pinned status; success bodies are the records below\nFlask compatibility: every GET route must also accept HEAD \u2014 same status code and headers as the GET, empty body (declare each GET endpoint with methods=['GET','HEAD']); FastAPI does not auto-add HEAD",
"app": "app entry: create the FastAPI app and mount paste_router"
},
"signoff": "07e1c8b9e27e/ce3bef1efa30 (signed 2026-11-18T18:52:46+00:00)"
}
}