Skip to content

Commit cc19775

Browse files
committed
feat: add usage documentation
1 parent 7fc5457 commit cc19775

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The city will benefit by having more time to review edge cases for building deve
4242
- To help with user research, find other cities' TDM calculators. For example, check out [SF's TDM Tool](https://sfplanninggis.org/tdm_v3/)
4343

4444
- To contribute to the code, see [Contributing](https://github.com/hackforla/tdm-calculator/wiki/Contributing-Code)
45+
- For internal server API docs, see [API Documentation](docs/api-documentation.md).
4546

4647
### Working with issues
4748

docs/api-documentation.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)