Skip to content

Generate API docs#472

Merged
sahilds1 merged 5 commits into
CodeForPhilly:developfrom
amahuli03:460/generate-api-documentation
Mar 11, 2026
Merged

Generate API docs#472
sahilds1 merged 5 commits into
CodeForPhilly:developfrom
amahuli03:460/generate-api-documentation

Conversation

@amahuli03
Copy link
Copy Markdown
Collaborator

@amahuli03 amahuli03 commented Feb 27, 2026

Description

  • Adds drf-spectacular for automatic OpenAPI 3.0 schema generation and interactive API docs
  • Serves Swagger UI at /api/docs/ and ReDoc at /api/redoc/ for browsing and testing endpoints
  • Adds @extend_schema annotations and serializer_class attributes across all API views so request bodies, response schemas, and parameters are fully documented
  • Configures JWT authentication in Swagger UI so developers can authorize and test protected endpoints directly

Changes

Configuration

  • Added drf-spectacular to requirements.txt
  • Added drf_spectacular to INSTALLED_APPS and set DEFAULT_SCHEMA_CLASS in settings.py
  • Added SPECTACULAR_SETTINGS with project metadata, JWT security scheme, and Swagger UI config

URL Routes

  • /api/schema/ — raw OpenAPI JSON/YAML schema
  • /api/docs/ — Swagger UI
  • /api/redoc/ — ReDoc UI

Schema Annotations

Added @extend_schema with inline_serializer for views that return raw dicts:

  • listMeds — GetMedication, DeleteMedication
  • risk — RiskWithSourcesView
  • uploadFile — file upload (multipart), delete, PDF retrieval
  • conversations — continue_conversation, update_title
  • embeddings — AskEmbeddingsAPIView (with query params)
  • text_extraction — RuleExtractionAPIView, RuleExtractionAPIOpenAIView
  • assistant — Assistant
  • version — VersionView
  • medRules — MedRules POST

Added serializer_class for auto-detection on:

  • ListOrDetailMedication, AddMedication, UploadFileView, MedRules, FeedbackView

Added @extend_schema referencing existing serializers on function-based views:

  • ai_promptStorage — store_prompt, get_all_prompts
  • ai_settings — settings_view

Fixed @extend_schema_field on MedRuleSerializer.get_medication_sources to resolve type hint warning.

How to Use

SwaggerUI is found at localhost:8000/api/docs
To test endpoints that require auth, follow this flow:

  1. Send a POST request to /auth/jwt/create/ with email and password in the request body (Can do this in Swagger UI itself with the "try it out" feature)
  2. Copy the access token from the response
  3. At the top right of the docs page, click the authorize button and enter the access token in this format:
    JWT <access_token>
  4. Subsequent requests from here (For the next 60 minutes) will include your token.

Related Issue

Closes #470

Manual Tests

  • Rebuilt backend container
  • Visited /api/docs/ to confirm Swagger UI loads with all endpoints listed
  • Visited '/api/redoc/` to confirm ReDoc also loads with all endpoints listed
  • Added auth and tested that works as well (got token, authorized it, and tested a protected endpoint all within the docs)
  • Added schema annotations and verified all endpoints have correct query params, request body, and/or response schema

Documentation

I can add a line or two about accessing and using the API docs in the local development section of the README if that would be useful.
Edit 3/10: Added this documentation

Reviewers

@sahilds1

@sahilds1 sahilds1 self-requested a review March 5, 2026 20:34
Copy link
Copy Markdown
Collaborator

@sahilds1 sahilds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sahilds1 sahilds1 merged commit 9fa287b into CodeForPhilly:develop Mar 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate API documentation

2 participants