File tree Expand file tree Collapse file tree 4 files changed +200
-84
lines changed
Expand file tree Collapse file tree 4 files changed +200
-84
lines changed Original file line number Diff line number Diff line change 22name = " json-schema-diff"
33version = " 0.1.0"
44edition = " 2021"
5+ license = " Apache 2.0"
56
67[lib ]
78name = " json_schema_diff"
Original file line number Diff line number Diff line change 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 `
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ use clap::Parser;
22use std:: fs:: File ;
33use std:: path:: PathBuf ;
44
5-
65use 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}
You can’t perform that action at this time.
0 commit comments