- Add support for tag-based article generation with operations metadata - Generate articles.yml data files with tag, menuName, and isConceptual fields - Include operations array in frontmatter for tag pages |
||
|---|---|---|
| .. | ||
| dist | ||
| openapi-paths-to-hugo-data | ||
| README.md | ||
| generate-openapi-articles.ts | ||
| tsconfig.json | ||
README.md
API Documentation Generation Scripts
TypeScript-based scripts for generating Hugo data files and content pages from OpenAPI specifications.
Overview
These scripts convert OpenAPI v3 specifications into Hugo-compatible data files and content pages for all InfluxDB products.
What Gets Generated
For each product, the scripts generate:
-
OpenAPI Spec Copies (static directory):
influxdb-{product}.yml- YAML version of the specinfluxdb-{product}.json- JSON version of the spec
-
Path Group Fragments (static/openapi/{product}/paths/):
- Separate YAML and JSON files for each API path group
- Example:
ref-api-v2-buckets.yamlandref-api-v2-buckets.json
-
Article Metadata (data/article-data/influxdb/{product}/):
articles.yml- Hugo data file with article metadataarticles.json- JSON version for programmatic access
-
Hugo Content Pages (content/{product}/api/):
- Markdown files generated from article data
- One page per API path group
Quick Start
Build Scripts
Compile TypeScript to JavaScript (required before running):
yarn build:api-scripts
Generate API Pages
Generate all products:
yarn build:api-pages
Generate specific product(s):
yarn build:api-pages:product cloud-v2
yarn build:api-pages:product cloud-v2 oss-v2
Supported Products
| Product ID | Description | Spec File | Content Path |
|---|---|---|---|
cloud-v2 |
InfluxDB Cloud (v2 API) | api-docs/cloud/v2/ref.yml |
content/influxdb/cloud/api/v2 |
oss-v2 |
InfluxDB OSS v2 | api-docs/v2/ref.yml |
content/influxdb/v2/api/v2 |
influxdb3-core |
InfluxDB 3 Core | api-docs/influxdb3/core/v3/ref.yml |
content/influxdb3/core/reference/api |
influxdb3-enterprise |
InfluxDB 3 Enterprise | api-docs/influxdb3/enterprise/v3/ref.yml |
content/influxdb3/enterprise/reference/api |
cloud-dedicated |
InfluxDB Cloud Dedicated | api-docs/influxdb3/cloud-dedicated/v2/ref.yml |
content/influxdb/cloud-dedicated/api |
cloud-serverless |
InfluxDB Cloud Serverless | api-docs/influxdb3/cloud-serverless/v2/ref.yml |
content/influxdb/cloud-serverless/api |
clustered |
InfluxDB Clustered | api-docs/influxdb3/clustered/v2/ref.yml |
content/influxdb/clustered/api |
Architecture
TypeScript Files
api-docs/scripts/
├── tsconfig.json # TypeScript configuration
├── generate-openapi-articles.ts # Main orchestration script
└── openapi-paths-to-hugo-data/
├── index.ts # Core conversion logic
└── package.json # Module dependencies
Compiled JavaScript
After running yarn build:api-scripts, compiled files are in:
api-docs/scripts/dist/
├── generate-openapi-articles.js
├── generate-openapi-articles.d.ts
└── openapi-paths-to-hugo-data/
├── index.js
└── index.d.ts
Script Details
generate-openapi-articles.ts
Main orchestration script that processes products.
For each product, it:
- Runs
getswagger.shto fetch/bundle the OpenAPI spec - Copies spec to
static/openapi/influxdb-{product}.yml - Generates JSON version at
static/openapi/influxdb-{product}.json - Generates path group fragments (YAML and JSON)
- Creates article metadata (YAML and JSON)
- Generates Hugo content pages
Usage:
node api-docs/scripts/dist/generate-openapi-articles.js [product-ids...]
# Examples:
node api-docs/scripts/dist/generate-openapi-articles.js # All products
node api-docs/scripts/dist/generate-openapi-articles.js cloud-v2 # Single product
node api-docs/scripts/dist/generate-openapi-articles.js cloud-v2 oss-v2 # Multiple products
Output:
📋 Processing all products...
================================================================================
Processing InfluxDB Cloud (v2 API)
================================================================================
Fetching OpenAPI spec for cloud-v2...
✓ Copied spec to static/openapi/influxdb-cloud-v2.yml
✓ Generated JSON spec at static/openapi/influxdb-cloud-v2.json
Generating OpenAPI path files in static/openapi/influxdb-cloud-v2/paths....
Generated: ref-api-v2-buckets.yaml and ref-api-v2-buckets.json
...
Generating OpenAPI article data in data/article-data/influxdb/cloud-v2...
Generated 32 articles in data/article-data/influxdb/cloud-v2
✅ Successfully processed InfluxDB Cloud (v2 API)
openapi-paths-to-hugo-data/index.ts
Core conversion library that processes OpenAPI specs.
Key Functions:
generateHugoData(options)- Main entry pointwritePathOpenapis()- Groups paths and writes fragmentscreateArticleDataForPathGroup()- Generates article metadata
Path Grouping Logic:
Paths are grouped by their base path (first 3-4 segments, excluding placeholders):
/api/v2/buckets → api-v2-buckets
/api/v2/buckets/{id} → api-v2-buckets (same group)
/api/v2/authorizations → api-v2-authorizations
Output Formats:
- YAML: Hugo-compatible data files
- JSON: Programmatic access and tooling
Development
Prerequisites
- Node.js >= 16.0.0
- Yarn package manager
- TypeScript installed (via root package.json)
Setup
# Install dependencies (from repo root)
yarn install
# Or install in the openapi-paths-to-hugo-data module
cd api-docs/scripts/openapi-paths-to-hugo-data
yarn install
TypeScript Configuration
The scripts use a dedicated tsconfig.json with CommonJS output:
{
"compilerOptions": {
"target": "ES2021",
"module": "CommonJS",
"outDir": "./dist",
"strict": true,
...
}
}
Making Changes
- Edit TypeScript files in
api-docs/scripts/ - Compile:
yarn build:api-scripts - Test:
yarn build:api-pages:product cloud-v2
Watch Mode
For active development:
cd api-docs/scripts/openapi-paths-to-hugo-data
yarn build:watch
Testing
Unit Test Example
const converter = require('./api-docs/scripts/dist/openapi-paths-to-hugo-data/index.js');
converter.generateHugoData({
specFile: 'api-docs/influxdb/cloud/v2/ref.yml',
dataOutPath: './test-output/paths',
articleOutPath: './test-output/articles'
});
Verify Output
After generation, check:
-
Path fragments exist:
ls -l static/openapi/influxdb-cloud-v2/paths/ -
Both formats generated:
ls -l static/openapi/influxdb-cloud-v2/paths/*.{yaml,json} -
Article data created:
cat data/article-data/influxdb/cloud-v2/articles.yml cat data/article-data/influxdb/cloud-v2/articles.json -
Hugo pages generated:
ls -l content/influxdb/cloud/api/v2/
Troubleshooting
TypeScript Compilation Errors
# Clean and rebuild
rm -rf api-docs/scripts/dist
yarn build:api-scripts
Missing Type Definitions
cd api-docs/scripts/openapi-paths-to-hugo-data
yarn add --dev @types/js-yaml @types/node
Spec File Not Found
Make sure to run getswagger.sh first:
cd api-docs
./getswagger.sh cloud-v2 -B
Path Grouping Issues
The script groups paths by their first 3-4 segments. If you need different grouping:
- Edit
writePathOpenapis()inopenapi-paths-to-hugo-data/index.ts - Modify the
key.slice(0, 4)logic - Rebuild:
yarn build:api-scripts
Migration from JavaScript
The original JavaScript files are preserved for reference:
api-docs/scripts/generate-openapi-articles.js(original)api-docs/scripts/openapi-paths-to-hugo-data/index.js(original)
Key Improvements
- TypeScript: Full type safety and IDE support
- Dual Formats: Generates both YAML and JSON
- All Products: Includes all 7 InfluxDB products
- Better Errors: Clear error messages with product validation
- CLI Arguments: Support for processing specific products
- Comprehensive Logging: Progress indicators and status messages
Related Documentation
- API Docs README:
api-docs/README.md- Complete API documentation workflow - OpenAPI Plugins:
api-docs/openapi/plugins/- Custom processing plugins - Hugo Data to Pages:
hugo-data-to-pages/- Page generation from data files
Examples
Generate Only Cloud Products
yarn build:api-pages:product cloud-v2 cloud-dedicated cloud-serverless
Generate Only InfluxDB 3 Products
yarn build:api-pages:product influxdb3-core influxdb3-enterprise
Process Single Product Manually
# Compile first
yarn build:api-scripts
# Run for specific product
node api-docs/scripts/dist/generate-openapi-articles.js oss-v2
API Reference
generateHugoData(options)
Generate Hugo data files from an OpenAPI specification.
Parameters:
options.specFile(string) - Path to the OpenAPI spec fileoptions.dataOutPath(string) - Output path for OpenAPI path fragmentsoptions.articleOutPath(string) - Output path for article metadata
Example:
const { generateHugoData } = require('./api-docs/scripts/dist/openapi-paths-to-hugo-data/index.js');
generateHugoData({
specFile: 'api-docs/influxdb/cloud/v2/ref.yml',
dataOutPath: 'static/openapi/influxdb-cloud-v2/paths',
articleOutPath: 'data/article-data/influxdb/cloud-v2'
});
productConfigs
Map of product configurations exported from generate-openapi-articles.ts.
Type:
type ProductConfig = {
specFile: string; // Path to OpenAPI spec
pagesDir: string; // Hugo content directory
description?: string; // Product description
};
const productConfigs: Record<string, ProductConfig>;
Usage:
const { productConfigs } = require('./api-docs/scripts/dist/generate-openapi-articles.js');
console.log(productConfigs['cloud-v2']);
// {
// specFile: 'api-docs/cloud/v2/ref.yml',
// pagesDir: 'content/influxdb/cloud/api/v2',
// description: 'InfluxDB Cloud (v2 API)'
// }
License
Same as parent docs-v2 repository (MIT).