Skip to content

Commit e0d25a0

Browse files
Stevengreclaude
andcommitted
Add comprehensive JSON schema for Stable MIR JSON format
- Implement complete JSON Schema for stable-mir-json output (#98) - Add schema validation script with comprehensive error reporting - Create detailed documentation for schema usage and structure - Update README with schema integration information - Include examples and best practices for schema validation Features: - Full coverage of all Stable MIR data structures - Type safety with detailed constraints and validation - Compatible with standard JSON Schema tools (ajv, jsonschema) - Comprehensive field descriptions and documentation - Validation script for development and CI/CD workflows Files added: - schema/stable-mir.schema.json: Main JSON Schema definition - scripts/validate-schema.sh: Validation script with options - docs/schema.md: Complete schema documentation - Updated README.md: Integration and usage instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0cc08e4 commit e0d25a0

File tree

4 files changed

+1124
-48
lines changed

4 files changed

+1124
-48
lines changed

README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Rust Stable MIR Pretty Printing
1+
# Rust Stable MIR JSON Generator
22

3-
This package provides a program that will emit a JSON serialisation of the Stable MIR of a Rust program
3+
This package provides a program that will emit a JSON serialisation of the Stable MIR of a Rust program, along with a comprehensive JSON schema for validation and tooling integration.
44

55
## Building
66

@@ -77,4 +77,53 @@ cargo run --bin cargo_stable_mir_json -- $PWD [OPTIONAL-PATH-FOR-DIR]
7777
```bash
7878
RUSTC=<PATH-TO-.stable_mir_json>/<PROFILE>.sh cargo build
7979
```
80-
NOTE: by default `<PATH-TO-.stable_mir_json>` is `~/.stable_mir_json`
80+
NOTE: by default `<PATH-TO-.stable_mir_json>` is `~/.stable_mir_json`
81+
82+
## JSON Schema
83+
84+
This repository includes a comprehensive JSON schema for the Stable MIR JSON format, enabling validation, tooling integration, and documentation.
85+
86+
### Schema Location
87+
88+
- **Schema file**: [`schema/stable-mir.schema.json`](schema/stable-mir.schema.json)
89+
- **Documentation**: [`docs/schema.md`](docs/schema.md)
90+
91+
### Validation
92+
93+
Validate your generated JSON files against the schema:
94+
95+
```shell
96+
# Validate all test files
97+
./scripts/validate-schema.sh
98+
99+
# Validate specific files
100+
./scripts/validate-schema.sh path/to/your/file.smir.json
101+
102+
# Verbose validation with detailed output
103+
./scripts/validate-schema.sh --verbose
104+
```
105+
106+
### Schema Features
107+
108+
- **Complete coverage** of all Stable MIR data structures
109+
- **Type safety** with detailed type definitions and constraints
110+
- **Documentation** with descriptions for all fields and structures
111+
- **Validation support** for development and CI/CD pipelines
112+
- **Tool integration** compatible with standard JSON Schema validators
113+
114+
### Using with External Tools
115+
116+
```shell
117+
# Using ajv-cli (npm install -g ajv-cli)
118+
ajv validate -s schema/stable-mir.schema.json -d "file.smir.json"
119+
120+
# Using Python jsonschema (pip install jsonschema)
121+
python -c "
122+
import json, jsonschema
123+
schema = json.load(open('schema/stable-mir.schema.json'))
124+
data = json.load(open('file.smir.json'))
125+
jsonschema.validate(data, schema)
126+
"
127+
```
128+
129+
For detailed schema documentation, see [`docs/schema.md`](docs/schema.md).

0 commit comments

Comments
 (0)