|
| 1 | +# API Documentation |
| 2 | + |
| 3 | +The server can expose protected OpenAPI documentation for internal development. |
| 4 | +The documentation covers the server's active Express API endpoints across |
| 5 | +public, authenticated, admin-only, request-body, and path-parameter flows. |
| 6 | + |
| 7 | +## Enable Locally |
| 8 | + |
| 9 | +From the `server` directory, set `ENABLE_API_DOCS=true` before starting the |
| 10 | +server: |
| 11 | + |
| 12 | +```bash |
| 13 | +cd server |
| 14 | +ENABLE_API_DOCS=true npm start |
| 15 | +``` |
| 16 | + |
| 17 | +The interactive Swagger UI is available at: |
| 18 | + |
| 19 | +```text |
| 20 | +http://localhost:5000/api-docs |
| 21 | +``` |
| 22 | + |
| 23 | +The raw OpenAPI JSON is available at: |
| 24 | + |
| 25 | +```text |
| 26 | +http://localhost:5000/api-docs.json |
| 27 | +``` |
| 28 | + |
| 29 | +Both routes require an authenticated `isAdmin` user. The API accepts JWT auth |
| 30 | +from either the `jwt` cookie or an `Authorization: Bearer <token>` header. |
| 31 | + |
| 32 | +## Adding Endpoint Docs |
| 33 | + |
| 34 | +Reusable request schemas live in `server/app/schemas` and are exposed as |
| 35 | +OpenAPI components from `server/app/docs/openapi.js`. The complete endpoint |
| 36 | +catalog is assembled in `server/app/docs/openapi-paths.js`; route-adjacent |
| 37 | +`@openapi` JSDoc blocks in `server/app/routes/*.routes.js` are also supported |
| 38 | +for endpoints that are easier to document beside the route. |
| 39 | + |
| 40 | +When documenting a new endpoint, include: |
| 41 | + |
| 42 | +- route path under the `/api` base path |
| 43 | +- method, summary, and tag |
| 44 | +- path parameters when present |
| 45 | +- request body schema for write endpoints |
| 46 | +- auth requirements matching the route middleware |
| 47 | +- expected success and error responses |
| 48 | + |
| 49 | +Keep docs close to the route that owns the behavior so future route changes are |
| 50 | +easy to review with their OpenAPI changes. |
0 commit comments