Automatic, comprehensive API documentation generation with multi-language support, versioning, and interactive browsing.
# Generate OpenAPI spec
npm run docs:generate
# Generate multi-language code examples
npm run docs:generate:examples
# Or do both at once
npm run docs:checkOption A: Interactive Runtime Docs
npm run start:dev
# Open http://localhost:3000/api/docsOption B: Static Documentation Site
npm run docs:view
# Open http://localhost:8080npm run docs:version
# Creates docs/versions/v1.0.0/- ✅ OpenAPI/Swagger - Auto-generated from code
- ✅ Code Examples - 7 programming languages
- ✅ Interactive Docs - ReDoc viewer
- ✅ Version Tracking - Changelog and comparisons
- ✅ Schema Validation - Consistent responses
- cURL - Command line testing
- TypeScript - Modern async/await
- Python - Requests library
- JavaScript - Fetch API
- Go - Native http
- Java - HttpURLConnection
- C# - HttpClient
- TypeScript/JavaScript SDK
- Python SDK
- Auto-generated from OpenAPI spec
- Archive documentation per release
- Compare API changes between versions
- Detect breaking changes
- Generate CHANGELOG automatically
After modifying an API endpoint:
npm run docs:generate
npm run docs:generate:examples# See what changed
git diff openapi-spec.json
# Compare API versions
npm run docs:versions:diff v1.0 v1.1# Validate OpenAPI spec
npm run docs:checkTypeScript:
import { SearchApi } from './sdk/typescript';
const api = new SearchApi();
const courses = await api.searchContent('javascript');Python:
from openapi_client.apis.tags import search_api
api = search_api.SearchApi()
courses = api.search_content(q='javascript')See API_DOCUMENTATION_BEST_PRACTICES.md for:
- How to document endpoints
- Swagger decorator examples
- Error response patterns
- Authentication documentation
- Testing documentation
# Before release
npm run docs:check # Verify docs are current
# On release
npm run docs:version # Archive documentation
git add docs/versions/
git commit -m "docs: archive API v1.0.0"
git pushdocs/
├── api/ # Generated API reference
│ ├── openapi-spec.json # OpenAPI 3.0 spec
│ └── examples.md # cURL examples
├── site/ # Interactive documentation site
│ ├── index.html # ReDoc viewer
│ ├── openapi-spec.json # Spec for viewer
│ └── styles.css # Styling
├── examples/ # Multi-language code examples
│ ├── README.md # Examples index
│ ├── 1_login.ts
│ ├── 1_login.py
│ ├── 1_login.js
│ ├── 1_login.go
│ ├── 1_login.java
│ ├── 1_login.cs
│ ├── 2_register.ts
│ └── ... (one set per endpoint)
├── versions/ # Version archive
│ ├── VERSIONS.md # Version index
│ ├── CHANGELOG.md # API changelog
│ ├── v1.0.0/
│ │ ├── openapi-spec.json
│ │ ├── examples/
│ │ └── metadata.json
│ └── v1.1.0/
│ └── ...
└── *.md # This guide & best practices
openapi-spec.json # Root OpenAPI spec
sdk/
├── typescript/ # Generated TypeScript SDK
└── python/ # Generated Python SDK
# Generation
npm run docs:generate # Generate OpenAPI spec from code
npm run docs:generate:examples # Generate examples in 7 languages
npm run docs:check # Generate everything + validate
# Viewing
npm run docs:view # Serve docs locally on port 8080
# Versioning
npm run docs:version # Archive current docs as version
npm run docs:versions:list # List all archived versions
npm run docs:versions:compare # Compare two versions
npm run docs:versions:diff # Show detailed endpoint changes
# SDK Generation
npm run sdk:generate # Generate all SDKs (TS, Python)
npm run sdk:generate:ts # TypeScript SDK only
npm run sdk:generate:python # Python SDK only
npm run sdk:generate:spec # Refresh spec for SDKsopenapi-spec.json- Root spec (primary)docs/api/openapi-spec.json- API docs copydocs/site/openapi-spec.json- Site viewer copydocs/versions/v1.0.0/openapi-spec.json- Version archive
docs/examples/README.md- Examples indexdocs/examples/1_login.ts- TypeScript exampledocs/examples/1_login.py- Python exampledocs/examples/1_login.js- JavaScript exampledocs/examples/1_login.go- Go exampledocs/examples/1_login.java- Java exampledocs/examples/1_login.cs- C# example
docs/versions/VERSIONS.md- Version indexdocs/versions/CHANGELOG.md- API changelogdocs/versions/v1.0.0/openapi-spec.json- Versioned specdocs/versions/v1.0.0/examples/- Versioned examples
-
Auto-run (if CI/CD configured)
npm run docs:generate npm run docs:generate:examples
-
Changes auto-committed
openapi-spec.jsondocs/site/docs/api/docs/examples/
-
Archive version
npm run docs:version
-
Commit version
git add docs/versions/ git commit -m "docs: archive API v1.0.0" -
View changelog
npm run docs:versions:list
-
Compare versions
npm run docs:versions:diff v1.0 v2.0
-
Check changelog
cat docs/versions/CHANGELOG.md
npm run start:dev
# Open http://localhost:3000/api/docsFeatures:
- "Try it out" button for testing
- Request/response examples
- Parameter validation
- Bearer token authentication
- Real-time API testing
npm run docs:view
# Open http://localhost:8080Features:
- Beautiful, interactive documentation
- Sidebar navigation
- Search across endpoints
- Code samples in multiple languages
- No external dependencies
All endpoints documented with:
GET /courses
├── Summary: List courses
├── Description: Retrieve paginated list of courses
├── Parameters: page, limit, category
├── Request Body: (none)
├── Response (200): Courses found
├── Response (400): Invalid parameters
├── Auth: Optional
└── Examples:
├── cURL
├── TypeScript
├── Python
├── JavaScript
├── Go
├── Java
└── C#
# View all versions
npm run docs:versions:list
# Compare two versions
npm run docs:versions:compare v1.0 v1.1
# Show detailed changes
npm run docs:versions:diff v1.0 v1.1Output includes:
- ✅ Added endpoints
- ❌ Removed endpoints (breaking)
- 🔄 Modified endpoints
- Parameter changes
- Response changes
Changelog is auto-generated in docs/versions/CHANGELOG.md:
## v2.0.0
### ✅ Added
- POST /courses/publish
### ❌ Breaking Changes
- Removed: DELETE /courses/{id}
### 🔄 Modified
- GET /courses (added pagination)npm run docs:checkThis will:
- Generate OpenAPI spec
- Generate examples
- Validate OpenAPI spec format
- Compare with git for changes
The system includes validation for:
- Valid OpenAPI 3.0 spec
- Required endpoints documented
- Consistent error responses
- Authentication requirements
Optional in .env:
API_VERSION=1.0.0
API_TITLE=TeachLink API
API_DESCRIPTION=Learning platform APIConfigured in scripts/generate-api-docs.js:
servers: [
{ url: 'http://localhost:3000', description: 'Local development' },
{ url: 'https://api.staging.teachlink.com', description: 'Staging' },
{ url: 'https://api.teachlink.com', description: 'Production' },
]Configured in spec:
bearerAuth: HTTP Bearer (JWT)
apiKeyAuth: Optional API key
npm run docs:generate
npm run docs:generate:examples
ls -la docs/ # Check timestampsnpm install -g swagger-cli
swagger-cli validate openapi-spec.json# Check file exists
test -f docs/site/index.html && echo "✅ File exists"
# Check permissions
ls -la docs/site/
# Serve locally
npm run docs:viewnpm run docs:generate:examples
ls -la docs/examples/# Validate spec first
swagger-cli validate openapi-spec.json
# Try generate with verbose
npm run sdk:generate -- --verbose✅ Do:
- Run
npm run docs:checkbefore committing - Use
@ApiTagsand@ApiOperationin controllers - Document all response codes
- Include examples in decorators
- Archive versions on release
- Keep docs in git
❌ Don't:
- Manually edit generated files
- Forget to update examples
- Skip error response documentation
- Leave controllers without tags
- Generate docs without testing
To auto-generate and publish docs on every commit:
- Create
.github/workflows/api-docs.yml(template provided in implementation) - Configure GitHub Pages or CDN
- Add Slack notifications (optional)
Benefits:
- Automatic doc generation
- Version archival on release
- GitHub Pages publishing
- Change notifications
- Breaking change detection
# Docs published to: https://yourusername.github.io/teachLink_backend/# docs/site/ deployed to your domain
# Example: https://api-docs.teachlink.comaws s3 sync docs/site/ s3://your-bucket/- Guide: API_DOCUMENTATION_GUIDE.md
- Best Practices: API_DOCUMENTATION_BEST_PRACTICES.md
- Implementation Details: IMPLEMENTATION_SUMMARY.md
- OpenAPI Spec: openapi-spec.json
- Official Docs: https://docs.nestjs.com/openapi/introduction
- ✅ Run
npm run docs:generateto generate initial docs - ✅ Run
npm run docs:viewto preview - ✅ Review generated files in
docs/ - ✅ Add decorators to controllers for better docs (optional)
- ✅ Set up CI/CD for automation (optional)
- ✅ Archive first version:
npm run docs:version
Questions? Check the troubleshooting section or review the detailed guides linked above.