CODITECT License Management API - Documentation Guide
This directory contains comprehensive API documentation for the CODITECT License Management API.
Documentation Files
1. api-documentation.md
Complete API reference documentation including:
- Authentication guide (Firebase JWT)
- All endpoint specifications with request/response examples
- Error handling documentation
- Rate limiting information
- Client integration examples (Python, JavaScript)
- Complete session lifecycle workflows
Target Audience: Developers integrating with the API
Format: Markdown
2. OpenAPI Schema (openapi-schema.yaml)
Machine-readable API specification in OpenAPI 3.0 format.
Generated via drf-spectacular with comprehensive:
- Request/response schemas
- Authentication security schemes
- Error response examples
- Endpoint tags and descriptions
Target Audience: API clients, code generators, testing tools
Format: YAML (OpenAPI 3.0)
Accessing API Documentation
Interactive Documentation (Recommended)
The API includes live, interactive documentation powered by Swagger UI and ReDoc:
Swagger UI
URL: http://localhost:8000/api/docs/ (Development) URL: https://api.coditect.com/api/docs/ (Production)
Features:
- Interactive API explorer
- Try-it-out functionality with live requests
- Authentication testing with JWT bearer tokens
- Request/response examples for all endpoints
- Automatic request validation
Best For:
- Testing API endpoints during development
- Learning the API interactively
- Debugging integration issues
ReDoc
URL: http://localhost:8000/api/redoc/ (Development) URL: https://api.coditect.com/api/redoc/ (Production)
Features:
- Clean, readable documentation layout
- Three-panel design (navigation, content, examples)
- Automatic code samples in multiple languages
- Downloadable OpenAPI schema
- Search functionality
Best For:
- Reference documentation
- API overview and exploration
- Sharing with stakeholders
OpenAPI Schema Download
URL: http://localhost:8000/api/schema/ (Development) URL: https://api.coditect.com/api/schema/ (Production)
Format: JSON
Download the raw OpenAPI schema for:
- Code generation (client SDKs, server stubs)
- API testing tools (Postman, Insomnia)
- Documentation generators
- Contract testing
Generating OpenAPI Schema
Automatic Generation
The OpenAPI schema is automatically available at runtime via the /api/schema/ endpoint.
Manual Generation
To generate a static openapi-schema.yaml file:
# From project root
./scripts/generate-openapi-schema.sh
This script:
- Activates the virtual environment
- Runs database migrations if needed
- Generates openapi-schema.yaml using drf-spectacular
- Validates the schema
Requirements:
- Virtual environment (
venv/) must exist - Dependencies installed (
pip install -r requirements.txt) - Django settings configured
Output: openapi-schema.yaml in project root
Manual Command (Alternative)
# Activate virtual environment
source venv/bin/activate
# Set Django settings
export DJANGO_SETTINGS_MODULE=license_platform.settings.development
# Generate schema
python manage.py spectacular \
--file openapi-schema.yaml \
--format openapi \
--validate
Using the Documentation
For API Consumers
-
Start Here: Read api-documentation.md
- Understand authentication (Firebase JWT)
- Review session lifecycle (acquire → heartbeat → release)
- Study error handling
-
Interactive Testing: Use Swagger UI
- Navigate to http://localhost:8000/api/docs/
- Click "Authorize" and enter your JWT token
- Try endpoints with "Try it out"
-
Integration: Use client examples
- Python example in api-documentation.md
- JavaScript example in api-documentation.md
- Or generate client SDK from OpenAPI schema
For API Developers
-
Adding New Endpoints:
from drf_spectacular.utils import extend_schema, OpenApiExample
@extend_schema(
tags=['Your Feature'],
summary='Endpoint summary',
description='Detailed description...',
request=YourRequestSerializer,
responses={
200: OpenApiResponse(
response=YourResponseSerializer,
description='Success response',
examples=[
OpenApiExample(
'Example Name',
value={...},
response_only=True,
status_codes=['200']
)
]
),
400: OpenApiResponse(description='Validation error'),
},
auth=['JWTAuthentication']
)
class YourView(APIView):
... -
Updating Serializers:
from drf_spectacular.utils import extend_schema_field
from drf_spectacular.types import OpenApiTypes
class YourSerializer(serializers.ModelSerializer):
"""
Serializer description.
Example:
{
"field1": "value1",
"field2": 123
}
"""
computed_field = serializers.SerializerMethodField()
@extend_schema_field(OpenApiTypes.INT)
def get_computed_field(self, obj):
return obj.compute_value() -
Regenerating Documentation:
After making changes:
./scripts/generate-openapi-schema.shThen verify at:
For QA/Testing
-
Import into Postman:
- Download schema: http://localhost:8000/api/schema/
- Import into Postman: File → Import → Upload openapi-schema.yaml
- All endpoints auto-generated with examples
-
Import into Insomnia:
- Download schema: http://localhost:8000/api/schema/
- Import: Application → Preferences → Data → Import Data
- Select openapi-schema.yaml
-
Automated Testing:
# Install testing tools
pip install schemathesis
# Run automated API tests
schemathesis run http://localhost:8000/api/schema/ \
--checks all \
--header "Authorization: Bearer YOUR_JWT_TOKEN"
Documentation Standards
Endpoint Documentation Requirements
All API endpoints MUST include:
✅ @extend_schema decorator with:
tags: Category groupingsummary: Brief one-line descriptiondescription: Detailed explanation with markdownrequest: Request serializer (if applicable)responses: All possible HTTP status codes with examplesauth: Authentication requirement
✅ Request examples for all inputs
✅ Response examples for:
- Success responses (200, 201, etc.)
- Common errors (400, 401, 404, 409, etc.)
- Edge cases (410, 503, etc.)
✅ Error documentation with:
- Status code
- Error message format
- When this error occurs
Serializer Documentation Requirements
All serializers MUST include:
✅ Docstring with:
- Purpose description
- Example JSON in docstring
✅ Field descriptions via help_text
✅ @extend_schema_field for computed fields
Example Quality Standards
Examples MUST:
- Use realistic data (no "foo", "bar", "test123")
- Include all required fields
- Show actual UUID format
- Include ISO 8601 timestamps
- Demonstrate field validation
Validation and Quality Checks
Schema Validation
The spectacular command includes automatic validation:
python manage.py spectacular --validate
Checks:
- OpenAPI 3.0 compliance
- Schema completeness
- Reference integrity
- Type consistency
Documentation Linting
Check documentation quality:
# Install spectral (OpenAPI linter)
npm install -g @stoplight/spectral-cli
# Lint schema
spectral lint openapi-schema.yaml
Coverage Check
Ensure all endpoints are documented:
python manage.py spectacular --file - --format openapi | \
python -c "import sys, json; \
schema = json.load(sys.stdin); \
print(f'Endpoints: {len(schema[\"paths\"])}'); \
print(f'Schemas: {len(schema[\"components\"][\"schemas\"])}')"
Troubleshooting
Schema Generation Fails
Problem: ModuleNotFoundError when running spectacular
Solution:
- Ensure virtual environment is activated:
source venv/bin/activate - Install dependencies:
pip install -r requirements.txt - Install drf-spectacular:
pip install drf-spectacular
Missing Examples in Swagger UI
Problem: Endpoints show no examples
Solution:
- Check
@extend_schemadecorator includesexamples=[...] - Verify
OpenApiExamplehasresponse_only=True - Ensure
status_codesmatches response status
Authentication Not Working in Swagger UI
Problem: 401 Unauthorized when testing
Solution:
- Click "Authorize" button in Swagger UI
- Enter token in format:
Bearer YOUR_JWT_TOKEN(include "Bearer ") - Or just:
YOUR_JWT_TOKEN(Swagger adds "Bearer " automatically) - Verify token is not expired (15 minute lifetime)
ReDoc Shows Outdated Documentation
Problem: Changes not reflected in ReDoc
Solution:
- Clear browser cache (Cmd+Shift+R on Mac)
- Restart Django server:
python manage.py runserver - Regenerate schema:
./scripts/generate-openapi-schema.sh
Best Practices
For API Documentation
- Keep Examples Realistic: Use production-like data
- Document All Error Cases: Don't just show happy path
- Include Rate Limits: Document per-endpoint limits
- Show Complete Workflows: Demonstrate multi-step processes
- Update on Changes: Regenerate schema after any API changes
For API Consumers
- Use Interactive Docs First: Test in Swagger UI before coding
- Handle All Error Cases: Don't assume success
- Implement Retries: Network failures happen
- Respect Rate Limits: Implement backoff strategies
- Monitor Token Expiry: Refresh tokens before expiration
For API Maintainers
- Review Schema on PR: Ensure documentation matches code
- Test Examples: Verify all examples are valid
- Version API Changes: Use semantic versioning
- Announce Breaking Changes: Give consumers notice
- Monitor Usage: Track which endpoints are most used
Additional Resources
- drf-spectacular Documentation: https://drf-spectacular.readthedocs.io/
- OpenAPI Specification: https://spec.openapis.org/oas/v3.0.0
- Swagger UI Documentation: https://swagger.io/tools/swagger-ui/
- ReDoc Documentation: https://redocly.com/docs/redoc/
Last Updated: November 30, 2025 Maintained By: CODITECT Backend Team Contact: api-support@coditect.com