Documentation Generation
All documentation in /docs/reference/ is automatically generated from schemas and should never be edited manually.
What's Auto-Generated
Metrics Reference
Source: schemas/metrics/metrics.json and registry files
Output: docs/reference/metrics/
Generator: tools/Voltimax.Iot.Tools/Schema/Metrics/
Generates comprehensive metrics documentation including:
- Metric definitions by category
- Units and data types
- Descriptions and examples
- Cross-references between related metrics
OCPP 2.1 Messages
Source: schemas/standards/ocpp/OCPP-2.1_all_files-3.zip
Output: docs/reference/ocpp/
Generator: tools/Voltimax.Iot.Tools/Schema/Ocpp/
Generates OCPP protocol documentation including:
- Message schemas by category
- Request/response pairs
- Field definitions
- Protocol requirements
SunSpec Models
Source: schemas/standards/sunspec/*.xml (SMDX files)
Output: docs/reference/sunspec/
Generator: tools/Voltimax.Iot.Tools/Schema/SunSpec/
Generates SunSpec model documentation including:
- Model definitions by category
- Register layouts
- Data point specifications
- Scale factors and units
Modbus Devices
Source: schemas/assets/modbus/*.yaml
Output: docs/reference/modbus/
Generator: tools/Voltimax.Iot.Tools/Schema/Asset/
Generates device-specific documentation including:
- Register maps
- Supported metrics
- Connection parameters
- Device-specific notes
How to Regenerate Documentation
Regenerate All Reference Docs
.\cli.ps1 generate --ocpp-by-category --sunspec-by-categoryThis regenerates all reference documentation from current schemas.
Regenerate Specific Schemas
Metrics only:
.\cli.ps1 schema metrics docsOCPP only:
.\cli.ps1 schema ocpp docs --by-categorySunSpec only:
.\cli.ps1 schema sunspec docs --by-categoryModbus only:
.\cli.ps1 schema asset docsConfiguration
Output paths are defined in tools/Voltimax.Iot.Tools/Shared/Constants.cs:
public const string MetricsDocsOutput = "docs/reference/metrics";
public const string OcppDocsOutput = "docs/reference/ocpp";
public const string SunSpecDocsOutput = "docs/reference/sunspec";
public const string ModbusDocsOutput = "docs/reference/modbus";Generator dependencies are configured in GenerateAllCommand.cs.
When to Regenerate
Regenerate documentation whenever schemas change:
Schema File Changes
If you update any of these files, regenerate docs:
schemas/metrics/**/*.jsonschemas/standards/ocpp/**/*schemas/standards/sunspec/**/*.xmlschemas/assets/modbus/**/*.yaml
After Schema Updates
Update the schema:
bash# Example: Update battery metrics vim schemas/metrics/registries/battery.jsonRegenerate documentation:
bash.\cli.ps1 generate --ocpp-by-category --sunspec-by-categoryReview changes:
bashgit diff docs/reference/Commit both schema and docs:
bashgit add schemas/ docs/reference/ git commit -m "feat: add new battery metrics"
Generator Implementation
Each generator follows a similar pattern:
1. Schema Parser
Reads and validates the source schema:
// Example: MetricsSchemaParser.cs
public class MetricsSchemaParser
{
public MetricsSchema Parse(string schemaPath)
{
// Read JSON schema
// Validate structure
// Return typed model
}
}2. Documentation Generator
Transforms schema into Markdown:
// Example: MetricsDocsGenerator.cs
public class MetricsDocsGenerator
{
public void Generate(MetricsSchema schema, string outputPath)
{
// Group metrics by category
// Generate markdown files
// Create navigation
}
}3. CLI Command
Exposes generation via CLI:
// Example: GenerateMetricsCommand.cs
[Command("metrics", Description = "Generate metrics documentation")]
public class GenerateMetricsCommand
{
public int OnExecute()
{
var parser = new MetricsSchemaParser();
var generator = new MetricsDocsGenerator();
var schema = parser.Parse(Constants.MetricsSchemaPath);
generator.Generate(schema, Constants.MetricsDocsOutput);
return 0;
}
}Adding a New Generator
To add documentation generation for a new protocol:
1. Add Schema Files
mkdir -p schemas/standards/[protocol]/
# Add schema files2. Create Generator
mkdir -p tools/Voltimax.Iot.Tools/Schema/[Protocol]/
# Add parser and generator classes3. Update Constants
Edit tools/Voltimax.Iot.Tools/Shared/Constants.cs:
public const string ProtocolDocsOutput = "docs/reference/[protocol]";
public const string ProtocolSchemaPath = "schemas/standards/[protocol]";4. Create CLI Command
Add command in tools/Voltimax.Iot.Tools/Schema/[Protocol]/:
[Command("[protocol]", Description = "Generate [protocol] documentation")]
public class GenerateProtocolCommand
{
// Implementation
}5. Update GenerateAllCommand
Edit GenerateAllCommand.cs to include new generator:
public int OnExecute()
{
// ... existing generators
var protocolCmd = new GenerateProtocolCommand();
protocolCmd.OnExecute();
return 0;
}6. Create Sidebar
Add docs/.vitepress/sidebar/[protocol].ts:
export default [
{
text: '[Protocol] Reference',
items: [
{ text: 'Overview', link: '/reference/[protocol]/' },
// Auto-populated by generator
]
}
]7. Update Reference Sidebar
Edit docs/.vitepress/sidebar/reference.ts:
import protocol from './[protocol]'
export default [
// ... existing sections
{
text: '[Protocol]',
collapsed: true,
items: protocol
}
]Best Practices
Do ✅
- Regenerate docs immediately after schema changes
- Commit both schema and generated docs together
- Review generated output before committing
- Keep generators idempotent (same input = same output)
- Use consistent Markdown formatting
- Generate navigation automatically
- Include cross-references
Don't ❌
- Edit files in
/docs/reference/manually - Commit schema changes without regenerating docs
- Create generators with side effects
- Hardcode output paths
- Generate documentation for hand-written content
- Skip validation of schema files
Troubleshooting
Generated docs out of date
# Regenerate all reference documentation
.\cli.ps1 generate --ocpp-by-category --sunspec-by-categoryGenerator fails
Check:
- Schema files are valid (JSON/YAML syntax)
- Output directory exists and is writable
- All dependencies are installed
- Generator code compiles
Navigation not showing
Verify:
- Sidebar file exists and is imported
- Links match generated file paths
config.mtsincludes sidebar mapping
Output path incorrect
Check Constants.cs has correct path definitions.
Resources
- iot-tools CLI Reference
- Schema documentation is located in the
schemas/directory - Generator Source Code