Skip to content

Commit 49fda4a

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 b7a5586 commit 49fda4a

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

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

0 commit comments

Comments
 (0)