Good API documentation is one of those things everyone agrees matters and almost nobody keeps up to date.
The README gets written during the launch sprint, then drifts from reality as endpoints change, parameters shift, and the intern who wrote the original docs has moved on.
Here's a way to fix that without writing anything by hand.
The problem with manual docs
The standard approach to API documentation looks like this:
- Write docs by hand during initial development
- Forget to update them when the API changes
- Get bug reports from users who followed the now-wrong docs
- Repeat
The alternative — auto-generating docs from code — has existed for years (Swagger/OpenAPI, JSDoc, etc.), but it requires you to annotate your code first. Which is also a thing nobody keeps up to date.
A different approach: generate from the code itself
What if you could point a tool at any GitHub repo and get back a full README, API reference, and usage examples — with no annotations required?
That's what the Code Documentation Generator API does. It fetches your repository, analyzes the actual code structure, and generates contextual documentation.
How it works
The API has three endpoints:
-
/generate/full— generates a complete README + API reference in one shot -
/generate/readme— README only (project overview, installation, usage, examples) -
/generate/api-reference— API reference only (endpoints, parameters, return types, error codes)
Basic usage
curl -X POST "https://code-docs-api.peakline-ops.workers.dev/generate/readme" \
-H "Content-Type: application/json" \
-d '{
"repo_url": "https://github.com/your-org/your-repo",
"doc_type": "readme"
}'
Response:
{
"success": true,
"documentation": "# Your Project
A REST API for...",
"repo": "your-org/your-repo",
"type": "readme",
"cached": false
}
Results are cached for 24 hours, so regenerating docs on a CI run is fast after the first call.
Automate it in CI
The real value comes from wiring this into your deployment pipeline. There's a GitHub Action that does this automatically on every push to main:
# .github/workflows/docs.yml
name: Auto-generate docs
on:
push:
branches: [main]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: peaklineops/code-docs-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
rapidapi_key: ${{ secrets.RAPIDAPI_KEY }}
repo_url: "https://github.com/${{ github.repository }}"
doc_type: full
output_file: README.md
Every merge to main triggers a fresh README. The Action auto-commits the updated file back to the repo.
What the generated docs look like
For a typical REST API project, the output includes:
- Project overview — what the service does, who it's for
- Prerequisites and installation — inferred from package.json, requirements.txt, etc.
- Endpoint reference — routes detected from the codebase, with request/response examples
- Authentication — detected from auth middleware patterns
- Error codes — inferred from error handling logic
- Examples — working code samples in multiple languages
It won't replace hand-crafted narrative documentation for complex systems, but it's an excellent baseline that's always synchronized with the current code.
Getting started
The API is available on RapidAPI with a free tier (5 requests/day, no credit card required):
- Subscribe on RapidAPI
- Grab your API key from the RapidAPI dashboard
- Make your first call with the curl above
- Set up the GitHub Action for continuous generation
What do you use for keeping docs in sync with your codebase? Curious if anyone has found a better workflow.
Top comments (0)