This project uses Sphinx-Needs Schema Validation to enforce data quality and consistency across all needs objects.
Schema validation is configured in two files:
The following settings in docs/ubproject.toml enable schema validation:
# docs/ubproject.toml
[needs]
schema_definitions_from_json = "schemas.json"
schema_severity = "warning"
schema_debug_active = falseschema_definitions_from_json: Points to the JSON file containing schema definitionsschema_severity: Minimum severity level to report (options:violation,warning,info)schema_debug_active: Enable detailed debugging output for schema validation
The docs/schemas.json file contains all validation rules organized by:
- ID Patterns: Ensures consistent ID naming conventions
- Status Validation: Enforces valid status values
- Link Validation: Validates relationships between need types
- Required Fields: Enforces mandatory fields for specific contexts
Ensures consistent naming patterns for different need types:
- Requirements:
R_*,SWREQ_*, orREQ_*(e.g.,REQ_001,SWREQ_042) - Specifications:
S_*orSPEC_*(e.g.,SPEC_100) - Implementations:
I_*,IMPL_*, orGH_PR_*(e.g.,IMPL_005,GH_PR_3) - Tests:
T_*orTEST_*(e.g.,TEST_001) - Persons:
P_*or uppercase names (e.g.,P_JOHN,PETER) - SW Architecture:
SWARCH_*(e.g.,SWARCH_001) - SW Requirements:
SWREQ_*orGH_ISSUE_*(e.g.,SWREQ_001,GH_ISSUE_12)
For requirements in the automotive-adas documentation:
- Status Required: Must have a valid status (
open,in progress,closed,passed,failed) - Release Required: Must be linked to at least one release
Validates proper linking between need types:
- Specifications → Requirements: Specs should link to requirements via
reqs - Implementations → Specifications: Implementations should link to specs via
implements - Tests → Specs/Implementations: Test cases should link to specs or implementations
- Persons: Should have a
roledefined - Teams: Should have at least one person assigned via
persons
Validation warnings appear during sphinx-build:
cd docs
uv run sphinx-build -b html . _build/htmlLook for an output like:
WARNING: Need 'REQ_005' has validation errors:
Severity: warning
Field: release
Need path: REQ_005
Schema path: automotive-req-release-required[8] > local > required
User message: Requirements in automotive-adas must be linked to a release
Schema message: 'release' is a required property
Schema violations are also exported to _build/html/schema_violations.json for programmatic analysis.
- Edit
docs/schemas.json - Add a new schema object to the
"schemas"array:
{
"id": "my-new-rule",
"severity": "warning",
"message": "Custom validation message",
"select": {
"$ref": "#/$defs/type-req"
},
"validate": {
"local": {
"properties": {
"my_field": {
"type": "string",
"minLength": 1
}
},
"required": ["my_field"]
}
}
}Use $defs section for reusable components:
{
"$defs": {
"my-common-pattern": {
"properties": {
"status": { "enum": ["open", "closed"] }
}
}
}
}Reference with "$ref": "#/$defs/my-common-pattern"
violation: Critical issues that should block buildswarning: Important issues that need attentioninfo: Informational messages for best practices
Change the global minimum severity in ubproject.toml:
schema_severity = "violation" # Only show violations, suppress warnings/info- Sphinx-Needs Schema Validation Documentation
- JSON Schema Reference
- Project's
schemas.jsonfor examples