Schema Testing and Deployment¶
This guide covers testing and deploying JSON Schema changes.
Schema Development Guide
This page covers testing and deployment of schema changes. For information on adding, modifying, or removing schema fields, see Maintaining the Schema.
Validation Testing¶
Multiple test suites verify schema correctness.
Schema Completeness Test¶
The test pkg/config/schema_test.go:TestSchemaStructSync verifies two things:
- All Go struct fields exist in schema
- Each field has
typeanddescription
Run the test:
Schema Metaschema Test¶
This test validates the schema against JSON Schema Draft 2020-12 specification.
Run the test:
Runtime Validation Test¶
The test pkg/config/validate_test.go covers runtime validation. It tests three scenarios:
- Valid configs (should pass)
- Invalid configs (should fail with helpful errors)
- Edge cases (boundary values, missing fields, etc.)
Run the test:
Integration Test¶
This test ensures that config files in examples validate. Run it:
Pre-commit Hooks¶
Pre-commit hooks run automatically before commits. They validate two things:
-
Schema metaschema:
-
Config file:
Set up pre-commit hooks:
Run hooks manually:
pre-commit run validate-json-schema --all-files
pre-commit run validate-readability-config --all-files
CI Validation¶
The CI workflow includes a validate-schema job. It runs these steps:
- name: Validate schema against JSON Schema Draft 2020-12
run: check-jsonschema --check-metaschema docs/schemas/config.json
- name: Validate .readability.yml against schema
run: check-jsonschema --schemafile docs/schemas/config.json .readability.yml
This validation runs on every PR.
Performance Benchmarks¶
The file pkg/config/validate_bench_test.go measures validation performance.
Run benchmarks:
These are the expected results:
- Schema compilation: < 5ns (cached via
sync.Once) - Valid config validation: < 10µs
- Invalid config validation: < 20µs
- Error formatting: < 20µs
Investigate if benchmarks regress by more than 2x.
Schema Publishing¶
MkDocs publishes the schema to this URL:
How It Works¶
The publishing process has four steps:
- MkDocs build includes
docs/schemas/directory - mike deploys to gh-pages branch
- GitHub Pages serves at
readability.adaptive-enforcement-lab.com /latest/points to current stable version
Versioning¶
Schema URLs support two versioning styles:
- Latest:
/latest/schemas/config.json(recommended) - Specific version:
/v1.11.0/schemas/config.json
Users should reference /latest/ to get automatic updates.
Testing Published Schema¶
Verify the schema is accessible after deployment:
You should see this response:
Common Pitfalls¶
Watch out for these common mistakes.
Forgetting to Update Overrides¶
When you add a field to thresholds, add a $ref in overrides.items.properties.thresholds:
{
"properties": {
"thresholds": {
"properties": {
"new_field": { /* definition */ }
}
},
"overrides": {
"items": {
"properties": {
"thresholds": {
"properties": {
"new_field": {
"$ref": "#/properties/thresholds/properties/new_field"
}
}
}
}
}
}
}
}
Missing Description¶
Every field needs a description for IDE tooltips:
{
"max_grade": {
"type": "number",
"description": "Maximum Flesch-Kincaid grade level" // Required!
}
}
Wrong Type Mapping¶
Go types map to specific JSON Schema types:
| Go Type | JSON Schema Type |
|---|---|
int, int64, uint |
"integer" |
float64 |
"number" |
string |
"string" |
bool |
"boolean" |
[]T |
"array" with items |
struct |
"object" with properties |
Here is a wrong example:
Here is the correct version:
Forgetting Examples¶
Always provide 2-3 realistic examples:
{
"max_grade": {
"type": "number",
"examples": [12, 14, 16] // Helps users understand typical values
}
}
Not Setting additionalProperties: false¶
This setting prevents typos from passing validation:
{
"properties": {
"thresholds": {
"type": "object",
"additionalProperties": false, // Reject unknown fields
"properties": { /* ... */ }
}
}
}
Review Checklist¶
Review this checklist before submitting a schema change:
- [ ] Schema matches Go struct fields (yaml tags)
- [ ] All fields have
typeanddescription - [ ] Range constraints match validation logic
- [ ] Examples provided for each field
- [ ] Overrides section includes
$reffor new fields - [ ]
additionalProperties: falseset on objects - [ ]
TestSchemaStructSyncpasses - [ ] Metaschema validation passes
- [ ] Runtime validation tests pass
- [ ] Benchmarks don't regress
- [ ] Documentation updated
- [ ] Pre-commit hooks pass
- [ ] CI validates successfully
Getting Help¶
If you need help with a schema change, try these resources:
- Check JSON Schema documentation
- Look at existing field definitions for examples
- Ask in PR review
- Run tests early and often
Next Steps¶
- Maintaining the Schema: Adding, modifying, or removing schema fields
- Schema Reference: Complete schema documentation
- Validation Guide: Common error examples and fixes
- Validation Workflow: Step-by-step validation process
- IDE Setup: Configure validation in editors