fix: code-driven OpenAPI docs — replace static JSON with swagger-jsdoc
Some checks failed
Deploy to Staging / build-and-deploy (push) Failing after 10m13s

BREAKING: OpenAPI spec is now generated from JSDoc annotations on route
handlers at startup, eliminating drift between code and documentation.

What was wrong:
- Static public/openapi.json was manually maintained and could drift
- Missing endpoints: signup, billing (checkout/success/webhook)
- Signup route was imported but never mounted (dead code)

What was fixed:
- Added swagger-jsdoc to generate OpenAPI spec from JSDoc on route files
- Every route handler now has @openapi JSDoc annotation as source of truth
- Spec served dynamically at GET /openapi.json (no static file)
- Deleted public/openapi.json
- Documented all missing endpoints (signup, billing x3)
- Mounted /v1/signup route
- All 9 screenshot params documented with types, ranges, defaults
This commit is contained in:
SnapAPI CEO 2026-02-20 07:32:37 +00:00
parent a70157d0ae
commit 713cc30ac7
10 changed files with 700 additions and 124 deletions

View file

@ -16,6 +16,73 @@ const playgroundLimiter = rateLimit({
keyGenerator: (req) => req.ip || req.socket.remoteAddress || "unknown",
});
/**
* @openapi
* /v1/playground:
* post:
* tags: [Playground]
* summary: Free demo screenshot (watermarked)
* description: >
* Take a watermarked screenshot without authentication.
* Limited to 5 requests per hour per IP, max 1920×1080 resolution.
* Perfect for evaluating the API before purchasing a plan.
* operationId: playgroundScreenshot
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required: [url]
* properties:
* url:
* type: string
* format: uri
* description: URL to capture
* example: "https://example.com"
* format:
* type: string
* enum: [png, jpeg, webp]
* default: png
* description: Output image format
* width:
* type: integer
* minimum: 320
* maximum: 1920
* default: 1280
* description: Viewport width (clamped to 1920 max)
* height:
* type: integer
* minimum: 200
* maximum: 1080
* default: 800
* description: Viewport height (clamped to 1080 max)
* responses:
* 200:
* description: Watermarked screenshot image
* content:
* image/png:
* schema: { type: string, format: binary }
* image/jpeg:
* schema: { type: string, format: binary }
* image/webp:
* schema: { type: string, format: binary }
* 400:
* description: Invalid request
* content:
* application/json:
* schema: { $ref: "#/components/schemas/Error" }
* 429:
* description: Rate limit exceeded (5/hr)
* content:
* application/json:
* schema: { $ref: "#/components/schemas/Error" }
* 503:
* description: Service busy
* content:
* application/json:
* schema: { $ref: "#/components/schemas/Error" }
*/
playgroundRouter.post("/", playgroundLimiter, async (req, res) => {
const { url, format, width, height } = req.body;