-
Notifications
You must be signed in to change notification settings - Fork 0
Development
Logan McDuffie edited this page Dec 23, 2025
·
1 revision
Guide for contributing to the api-docs CLI.
- Node.js 20.0.0 or higher
- npm
- Git
-
Clone the repository:
git clone https://github.com/TidalStudio/api-docs-cli.git cd api-docs-cli -
Install dependencies:
npm install
-
Run the CLI locally:
node bin/api-docs.js --help
api-docs-cli/
bin/
api-docs.js # CLI entry point (yargs commands)
src/
browser.js # Puppeteer browser lifecycle
cache.js # Local spec caching with TTL
discovery.js # APITracker.io provider lookup
formatter.js # Terminal output formatting
extractors/
apitracker.js # APITracker.io search
docs-scraper.js # DOM scraping (Scalar, Redoc, generic)
openapi.js # Direct OpenAPI/Swagger fetch
redoc.js # Redoc-specific extraction
swagger-ui.js # Swagger UI extraction via Puppeteer
wiki/ # Wiki documentation
package.json
eslint.config.js
.prettierrc
Main CLI entry point using yargs. Defines all commands and orchestrates extraction.
Handles local caching of API specs with SHA256-based keys and TTL expiration.
Looks up provider names via APITracker.io with 7-day cache.
Multiple extraction strategies that are tried in order:
-
openapi.js- Direct fetch for.json/.yamlURLs -
docs-scraper.js- DOM scraping for Scalar/Redoc/generic pages -
swagger-ui.js- Puppeteer extraction for JS-rendered Swagger UI
Formats endpoints for terminal output with color-coded HTTP methods.
Singleton pattern for Puppeteer browser management.
| Script | Description |
|---|---|
npm start |
Run CLI |
npm run lint |
Run ESLint |
npm run lint:fix |
Fix ESLint issues |
npm run format |
Format with Prettier |
npm run format:check |
Check formatting |
npm test |
Run tests |
npm run test:smoke |
Basic smoke test |
npm run release |
Publish new version |
- ESLint for linting
- Prettier for formatting
- ES Modules (
"type": "module")
Run before committing:
npm run lint:fix
npm run format# Run all tests
npm test
# Smoke test (CLI loads correctly)
npm run test:smoke-
Create a feature branch:
git checkout -b feature/your-feature
-
Make your changes
-
Run linting and formatting:
npm run lint:fix npm run format
-
Test your changes:
npm test node bin/api-docs.js endpoints stripe -
Commit and push:
git add . git commit -m "Add your feature" git push origin feature/your-feature
-
Open a pull request
- Create a new file in
src/extractors/ - Export an extraction function and error class
- Add the extractor to the fallback chain in
bin/api-docs.js - Update tests
Example structure:
export class MyExtractorError extends Error {
constructor(message, cause) {
super(message);
this.name = 'MyExtractorError';
this.cause = cause;
}
}
export async function extractFromMySource(url, options = {}) {
// Implementation
return {
spec: openApiSpec,
format: 'json',
specInfo: { title, type, version }
};
}Releases are managed via npm run release. This:
- Bumps version in package.json
- Creates a git tag
- Publishes to npm
Elastic License 2.0. See LICENSE.