Crates.io | json-schema-diff |
lib.rs | json-schema-diff |
version | 0.1.7 |
source | src |
created_at | 2023-03-28 19:15:51.532082 |
updated_at | 2023-06-06 10:15:37.775859 |
description | Diff changes between JSON schema files. |
homepage | |
repository | https://github.com/getsentry/json-schema-diff |
max_upload_size | |
id | 823373 |
size | 91,356 |
A work-in-progress tool to diff changes between JSON schemas. A lot of JSON schema features are not implemented and therefore ignored, see the issue tracker.
Use this tool as a best-effort to find obviously breaking changes in CI, but not for much more.
This crate is used with draft-07 but even that is work in progress.
Install Rust and:
cargo install json-schema-diff
cat schema-old.json schema-new.json
# {"type": "string"}
# {"type": "boolean"}
cargo run --features=build-binary -- \
schema-old.json \
schema-new.json
# {"path":"","change":{"TypeRemove":{"removed":"string"}},"is_breaking":true}
# {"path":"","change":{"TypeAdd":{"added":"boolean"}},"is_breaking":false}
Sentry uses this tool in
sentry-kafka-schemas
to
annotate pull requests with breaking changes made to schema definitions. It
invokes the CLI tool on the schema from master vs the schema in the PR, and
post-processes the output using a Python script for human consumption.
is_breaking
is just a suggestion. You may choose to ignore it entirely and
instead define which kinds of changes are breaking to you in wrapper scripts.
use json_schema_diff::*;
let lhs = serde_json::json! {{
"type": "string",
}};
let rhs = serde_json::json! {{
"type": "boolean",
}};
assert_eq!(
json_schema_diff::diff(lhs, rhs).unwrap(),
vec![
Change {
path: "".to_owned(),
change: ChangeKind::TypeRemove { removed: JsonSchemaType::String }
},
Change {
path: "".to_owned(),
change: ChangeKind::TypeAdd { added: JsonSchemaType::Boolean }
}
]
);
Licensed under Apache 2.0