|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +### Development Commands |
| 8 | +- `npm run lint` - Run ESLint for code linting |
| 9 | +- `npm run lint:fix` - Run ESLint with automatic fixes |
| 10 | +- `npm run test` - Run Jest tests with experimental VM modules support |
| 11 | + |
| 12 | +### Testing the CLI Tool |
| 13 | +- `npx openapi-generate-html -i openapi.json` - Generate HTML from OpenAPI spec |
| 14 | +- `npx openapi-generate-html -i openapi.json --theme=dark` - Generate with dark theme |
| 15 | +- `npx openapi-generate-html -i openapi.json --ui=swagger --output=custom.html` - Generate with Swagger UI |
| 16 | + |
| 17 | +## Architecture |
| 18 | + |
| 19 | +This is a Node.js CLI tool that generates standalone HTML documentation from OpenAPI specifications. The tool creates self-contained HTML files with all assets embedded. |
| 20 | + |
| 21 | +### Core Components |
| 22 | + |
| 23 | +**Main Entry Point (`src/index.js`)** |
| 24 | +- CLI argument parsing using Commander.js |
| 25 | +- Interactive prompts using Inquirer.js |
| 26 | +- Three-phase workflow: get options → render HTML → write file |
| 27 | + |
| 28 | +**Template System (`resources/*/`)** |
| 29 | +- Three UI options: Stoplight Elements, Swagger UI, Redoc |
| 30 | +- Each UI has: `template.ejs`, `index.css`, `index.js` |
| 31 | +- Templates use EJS with embedded CSS/JS content and OpenAPI data |
| 32 | + |
| 33 | +**Validation (`src/utils/validate.js`)** |
| 34 | +- Input validation for CLI commands and interactive prompts |
| 35 | +- Supports JSON/YAML files and URLs |
| 36 | +- Enforces HTML output format |
| 37 | + |
| 38 | +**Constants (`src/constants/index.js`)** |
| 39 | +- UI types: `['stoplight', 'swagger', 'redoc']` |
| 40 | +- Themes: `['light', 'dark']` |
| 41 | +- File extensions: `['.json', '.yaml', '.yml']` |
| 42 | + |
| 43 | +### Key Processing Steps |
| 44 | + |
| 45 | +1. **Input Resolution**: Accepts file paths or URLs, validates format |
| 46 | +2. **$ref Resolution**: Uses `@apidevtools/json-schema-ref-parser` to bundle external references |
| 47 | +3. **Template Rendering**: EJS templates embed CSS, JS, and OpenAPI data into single HTML file |
| 48 | +4. **Output Generation**: Creates standalone HTML with no external dependencies |
| 49 | + |
| 50 | +### File Structure Logic |
| 51 | + |
| 52 | +- `src/index.js` - Main orchestration and rendering logic |
| 53 | +- `src/utils/validate.js` - All input validation functions |
| 54 | +- `src/constants/index.js` - Configuration constants |
| 55 | +- `resources/{ui}/` - UI-specific templates and assets |
| 56 | +- Tests are co-located with source files (e.g., `validate.test.js`) |
| 57 | + |
| 58 | +### Testing |
| 59 | + |
| 60 | +Uses Jest with ES modules (`--experimental-vm-modules` flag required). Tests focus on validation functions and CLI argument handling. |
0 commit comments