Skip to main content
This cookbook shows how to automatically update documentation when code changes, ensure docs stay current, and generate API documentation from code.

How it works

Documentation sync hooks can:
  1. Update API docs: Generate documentation from code annotations
  2. Sync code examples: Keep examples in docs matching actual code
  3. Validate doc references: Ensure docs reference correct code paths
  4. Update changelogs: Auto-generate changelog entries
  5. Check doc completeness: Require documentation for new features

Prerequisites

Install documentation tools:

Basic documentation automation

Auto-generate API docs

Generate API documentation when code changes. Create .factory/hooks/generate-api-docs.sh:
Add to .factory/hooks.json:

Update README on project changes

Keep README in sync with project structure. Create .factory/hooks/update-readme.sh:

Sync code examples in documentation

Ensure code examples in docs match actual code: Create .factory/hooks/sync-doc-examples.py:

Advanced documentation automation

OpenAPI/Swagger spec validation

Ensure API documentation matches implementation: Create .factory/hooks/validate-openapi.sh:

JSDoc/TSDoc enforcement

Require documentation comments for public APIs: Create .factory/hooks/enforce-jsdoc.sh:

Generate changelog from commits

Automatically build changelog from git history: Create .factory/hooks/generate-changelog.sh:

Docs coverage report

Track which code has documentation: Create .factory/hooks/docs-coverage.py:
Run on session end:

Best practices

1

Automate but don't auto-commit

Generate docs but let users review before committing:
2

Keep doc examples testable

Extract examples from actual tests:
3

Version documentation

Tag docs with version info:
4

Link docs to code

Include source file references:
5

Use doc generation tools

Don’t manually maintain API docs:

Troubleshooting

Problem: Can’t generate documentation Solution: Check tool configuration:
Problem: Doc examples don’t match code Solution: Extract examples from tests:
Then extract programmatically:
Problem: Doc generation takes too long Solution: Build incrementally:

See also