Skip to content

Commit 4bae746

Browse files
committed
update documentation to include instructions about how to use the API docs
1 parent 3c83abd commit 4bae746

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CLAUDE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ Each module contains:
147147
- Auth endpoints via Djoser: `/auth/`
148148
- JWT token lifetime: 60 minutes (access), 1 day (refresh)
149149

150+
#### API Documentation
151+
- Auto-generated using **drf-spectacular** (OpenAPI 3.0)
152+
- **Swagger UI**: `http://localhost:8000/api/docs/` — interactive API explorer
153+
- **ReDoc**: `http://localhost:8000/api/redoc/` — readable reference docs
154+
- **Raw schema**: `http://localhost:8000/api/schema/`
155+
- Configuration in `SPECTACULAR_SETTINGS` in `settings.py`
156+
- Views use `@extend_schema` decorators and `serializer_class` attributes for schema generation
157+
- JWT auth is configured in the schema — use `JWT <token>` (not `Bearer`) in Swagger UI's Authorize dialog
158+
- To document a new endpoint: add `serializer_class` to the view if it has one, or add `@extend_schema` with `inline_serializer` for views returning raw dicts
159+
150160
#### Key Data Models
151161
- **Medication** (`api.views.listMeds.models`) - Medication catalog with benefits/risks
152162
- **MedRule** (`api.models.model_medRule`) - Include/Exclude rules for medications based on patient history

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ df = pd.read_sql(query, engine)
7474
#### Django REST
7575
- The email and password are set in `server/api/management/commands/createsu.py`
7676

77+
## API Documentation
78+
79+
Interactive API docs are auto-generated using [drf-spectacular](https://drf-spectacular.readthedocs.io/) and available at:
80+
81+
- **Swagger UI**: [http://localhost:8000/api/docs/](http://localhost:8000/api/docs/) — interactive explorer with "Try it out" functionality
82+
- **ReDoc**: [http://localhost:8000/api/redoc/](http://localhost:8000/api/redoc/) — clean, readable reference docs
83+
- **Raw schema**: [http://localhost:8000/api/schema/](http://localhost:8000/api/schema/) — OpenAPI 3.0 JSON/YAML
84+
85+
### Testing authenticated endpoints
86+
87+
Most endpoints require JWT authentication. To test them in Swagger UI:
88+
89+
1. **Get a token**: Find the `POST /auth/jwt/create/` endpoint in Swagger UI, click **Try it out**, enter an authorized `email` and `password`, and click **Execute**. Copy the `access` token from the response.
90+
2. **Authorize**: Click the **Authorize** button (lock icon) at the top of the page. Enter `JWT <your-access-token>` in the value field. The prefix must be `JWT`, not `Bearer`.
91+
3. **Test endpoints**: All subsequent requests will include your token. Use **Try it out** on any protected endpoint.
92+
4. **Token refresh**: Access tokens expire after 60 minutes. Use `POST /auth/jwt/refresh/` with your `refresh` token, or repeat step 1.
93+
7794
## Architecture
7895

7996
The Balancer website is a Postgres, Django REST, and React project. The source code layout is:

0 commit comments

Comments
 (0)