|
| 1 | +# API Documentation Integration |
| 2 | + |
| 3 | +This project integrates API documentation with the Antora documentation site, providing two versions of API docs that are built during the main site build process and served alongside the main documentation. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +### Build Process |
| 8 | + |
| 9 | +1. **UI Build**: Antora UI bundle is created |
| 10 | +2. **Antora Build**: Main documentation site is generated |
| 11 | +3. **API Docs Build**: Both API v1 and v2 documentation are built and integrated |
| 12 | + |
| 13 | +### API Documentation Versions |
| 14 | + |
| 15 | +**API v1** - Static Documentation |
| 16 | + |
| 17 | +- Source: `api-v1/` directory (complete static site) |
| 18 | +- Build: Simple file copying |
| 19 | +- Output: `build/api/v1/` (preserves all assets: fonts, images, CSS, JS) |
| 20 | +- URL: `/api/v1/` |
| 21 | + |
| 22 | +**API v2** - Live Documentation |
| 23 | + |
| 24 | +- Source: Live CircleCI API (`https://circleci.com/api/v2/openapi.json`) |
| 25 | +- Build: Sophisticated pipeline with fetching, patching, bundling, and HTML generation |
| 26 | +- Output: `build/api/v2/index.html` |
| 27 | +- URL: `/api/v2/` |
| 28 | + |
| 29 | +## File Structure |
| 30 | + |
| 31 | +``` |
| 32 | +project-root/ |
| 33 | +├── api-v1/ # Static API v1 documentation |
| 34 | +│ ├── index.html # Main v1 docs (217KB) |
| 35 | +│ ├── fonts/ # Font assets |
| 36 | +│ ├── images/ # Image assets |
| 37 | +│ ├── javascripts/ # JS assets |
| 38 | +│ └── stylesheets/ # CSS assets |
| 39 | +├── openapi-patch.json # JSON patches for v2 API customization |
| 40 | +├── redocly.yaml # Redocly config (currently unused in build) |
| 41 | +├── gulp.d/tasks/ |
| 42 | +│ └── build-api-docs.js # API documentation build pipeline |
| 43 | +└── build/ # Generated output |
| 44 | + └── api/ |
| 45 | + ├── v1/ # Complete static v1 site |
| 46 | + └── v2/ # Generated v2 documentation |
| 47 | + └── index.html # Single-page API docs (1.6MB) |
| 48 | +``` |
| 49 | + |
| 50 | +## Build Pipeline Details |
| 51 | + |
| 52 | +### API v1 Build (Simple) |
| 53 | + |
| 54 | +1. Check if `api-v1/` directory exists |
| 55 | +2. Copy entire directory structure to `build/api/v1/` |
| 56 | +3. Preserve all assets (fonts, images, CSS, JS) |
| 57 | + |
| 58 | +### API v2 Build (Sophisticated) |
| 59 | + |
| 60 | +1. **Fetch**: Download live OpenAPI spec from CircleCI API |
| 61 | +2. **Prepare**: Ready spec for processing (future code sample enrichment) |
| 62 | +3. **Patch**: Apply JSON patches from `openapi-patch.json` |
| 63 | +4. **Bundle**: Optimize spec and remove unused components |
| 64 | +5. **Lint**: Quality check the processed spec |
| 65 | +6. **Build**: Generate HTML documentation with Redocly CLI |
| 66 | +7. **Cleanup**: Remove temporary processing files |
| 67 | + |
| 68 | +## Navigation Integration |
| 69 | + |
| 70 | +### Header Dropdown |
| 71 | + |
| 72 | +- "API Reference" button in main site header |
| 73 | +- Dropdown shows "API v1" and "API v2" options |
| 74 | +- Implemented in `ui/src/partials/header-content.hbs` |
| 75 | + |
| 76 | +### Sidebar Navigation |
| 77 | + |
| 78 | +- API links in component explorer navigation |
| 79 | +- Links appear in reference section sidebar |
| 80 | +- Implemented in `ui/src/partials/component-explorer-nav.hbs` |
| 81 | + |
| 82 | +### Content Page Links |
| 83 | + |
| 84 | +- Direct links from documentation pages |
| 85 | +- Uses relative paths `/api/v1/` and `/api/v2/` |
| 86 | +- Implemented in Antora content files |
| 87 | + |
| 88 | +## Build Commands |
| 89 | + |
| 90 | +```bash |
| 91 | +# Build everything (UI + Antora + API docs) |
| 92 | +npm run build:docs |
| 93 | + |
| 94 | +# Build just API documentation |
| 95 | +npm run build:api-docs |
| 96 | + |
| 97 | +# Development server with auto-rebuild |
| 98 | +npm run start:dev |
| 99 | +``` |
| 100 | + |
| 101 | +## Configuration and Customization |
| 102 | + |
| 103 | +### API v1 Customization |
| 104 | + |
| 105 | +- Edit files directly in `api-v1/` directory |
| 106 | +- Changes appear immediately on next build |
| 107 | +- Maintains complete static site structure |
| 108 | + |
| 109 | +### API v2 Customization |
| 110 | + |
| 111 | +- **Content**: Edit `openapi-patch.json` to modify the API spec |
| 112 | +- **Styling**: Modify Redocly CLI build command arguments |
| 113 | +- **Processing**: Edit pipeline steps in `gulp.d/tasks/build-api-docs.js` |
| 114 | + |
| 115 | +### JSON Patching System |
| 116 | + |
| 117 | +The `openapi-patch.json` file allows customizing the live CircleCI API spec: |
| 118 | + |
| 119 | +```json |
| 120 | +{ |
| 121 | + "info": { |
| 122 | + "description": "Custom description override" |
| 123 | + }, |
| 124 | + "paths": { |
| 125 | + "/custom-endpoint": { |
| 126 | + "get": { |
| 127 | + "summary": "Added custom endpoint" |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +## Dependencies |
| 135 | + |
| 136 | +### Required |
| 137 | + |
| 138 | +- `@redocly/cli`: OpenAPI processing and doc generation |
| 139 | +- `jq`: JSON processing (system dependency for patching) |
| 140 | +- `curl`: API fetching (system dependency) |
| 141 | + |
| 142 | +### Development |
| 143 | + |
| 144 | +- Redocly CLI automatically rebuilds during development |
| 145 | +- File watching triggers rebuilds for both versions |
| 146 | +- Browser auto-reloads when documentation changes |
| 147 | + |
| 148 | +## Troubleshooting |
| 149 | + |
| 150 | +### Common Issues |
| 151 | + |
| 152 | +1. **Build failures**: Check network connectivity for v2 API fetching |
| 153 | +2. **Missing v1 docs**: Ensure `api-v1/` directory exists with content |
| 154 | +3. **Patch errors**: Validate `openapi-patch.json` syntax with `jq` |
| 155 | +4. **Navigation issues**: Check relative paths in Antora content files |
| 156 | + |
| 157 | +### Debug Commands |
| 158 | + |
| 159 | +```bash |
| 160 | +# Test API v2 endpoint accessibility |
| 161 | +curl -s https://circleci.com/api/v2/openapi.json | head |
| 162 | + |
| 163 | +# Validate patch file syntax |
| 164 | +jq . openapi-patch.json |
| 165 | + |
| 166 | +# Lint API specification |
| 167 | +npx @redocly/cli lint [path-to-spec] |
| 168 | + |
| 169 | +# Build API docs in isolation |
| 170 | +gulp build:api-docs |
| 171 | +``` |
| 172 | + |
| 173 | +### Build Logs |
| 174 | + |
| 175 | +The build process provides detailed logging: |
| 176 | + |
| 177 | +- ✅ Success indicators for each pipeline step |
| 178 | +- ⚠️ Warnings for non-critical issues (continues build) |
| 179 | +- ❌ Errors that halt the build process |
| 180 | +- 📁 File operation details and sizes |
| 181 | + |
| 182 | +## Development Workflow |
| 183 | + |
| 184 | +### Adding New API Versions |
| 185 | + |
| 186 | +1. Create `buildApiV3()` function in `build-api-docs.js` |
| 187 | +2. Add directory creation logic |
| 188 | +3. Update main build orchestration |
| 189 | +4. Add navigation links to UI templates |
| 190 | +5. Update Antora content files |
| 191 | + |
| 192 | +### Modifying Build Pipeline |
| 193 | + |
| 194 | +1. Edit `gulp.d/tasks/build-api-docs.js` |
| 195 | +2. Test with `npm run build:api-docs` |
| 196 | +3. Verify output in `build/api/` directories |
| 197 | +4. Check integration with `npm run start:dev` |
| 198 | + |
| 199 | +### CI/CD Integration |
| 200 | + |
| 201 | +The build integrates with existing CircleCI pipeline: |
| 202 | + |
| 203 | +- No additional CI configuration needed |
| 204 | +- API docs build as part of main site build |
| 205 | +- Both versions deploy together to production |
| 206 | +- Automatic updates when CircleCI API changes (v2) |
| 207 | + |
| 208 | +## Performance Notes |
| 209 | + |
| 210 | +- **API v1**: Fast build (~1 second, file copying) |
| 211 | +- **API v2**: Slower build (~30 seconds, network + processing) |
| 212 | +- **Output sizes**: v1 maintains original assets, v2 generates 1.6MB HTML |
| 213 | +- **Caching**: v2 uses temporary files for efficient rebuilds |
| 214 | +- **Development**: Hot reload works for both versions |
0 commit comments