Skip to content

Commit 70a9d41

Browse files
committed
wip
1 parent 131ff77 commit 70a9d41

File tree

4 files changed

+200
-84
lines changed

4 files changed

+200
-84
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "json-schema-diff"
33
version = "0.1.0"
44
edition = "2021"
5+
license = "Apache 2.0"
56

67
[lib]
78
name = "json_schema_diff"

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# json-schema-diff
2+
3+
A work-in-progress tool to diff changes between code schemas. A lot of JSON schema features are not implemented and therefore ignored, such as:
4+
5+
* `required`
6+
* `patternProperties` (entirely ignored)
7+
* `const` (changes from `{"const": "foo"}` to `{"type": "string"}` are not detected)
8+
9+
Use this tool as a best-effort to find obviously breaking changes in CI, but not for much more.
10+
11+
This crate is used with draft-07 but even that is work in progress.
12+
13+
## Usage via CLI
14+
15+
```bash
16+
cargo run --features=build-binary -- \
17+
schema-old.json \
18+
schema-new.json
19+
```
20+
21+
## Usage as library
22+
23+
```rust
24+
use json_schema_diff::*;
25+
26+
let lhs = serde_json::json! {{
27+
"type": "string",
28+
}};
29+
let rhs = serde_json::json! {{
30+
"type": "boolean",
31+
}};
32+
33+
assert_eq!(
34+
json_schema_diff::diff(lhs, rhs).unwrap(),
35+
vec![
36+
Change {
37+
path: "".to_owned(),
38+
change: ChangeKind::TypeRemove { removed: SimpleJsonSchemaType::String }
39+
},
40+
Change {
41+
path: "".to_owned(),
42+
change: ChangeKind::TypeAdd { added: SimpleJsonSchemaType::Boolean }
43+
}
44+
]
45+
);
46+
```
47+
48+
## License
49+
50+
Licensed under Apache 2.0, see `./LICENSE`

src/bin/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use clap::Parser;
22
use std::fs::File;
33
use std::path::PathBuf;
44

5-
65
use anyhow::Error;
76

87
/// Compare old and new schema, and print differences
@@ -24,7 +23,7 @@ fn main() -> Result<(), Error> {
2423
let changes = json_schema_diff::diff(lhs, rhs)?;
2524

2625
for change in changes {
27-
println!("{:?}", change);
26+
println!("{}", serde_json::to_string(&change)?);
2827
}
2928
Ok(())
3029
}

0 commit comments

Comments
 (0)