#json-schema #breaking #diff

bin+lib json-schema-diff

Diff changes between JSON schema files

8 releases

0.1.7 Jun 6, 2023
0.1.6 May 16, 2023
0.1.4 Apr 7, 2023
0.1.2 Mar 29, 2023

#444 in Database interfaces

Download history 334/week @ 2024-07-29 310/week @ 2024-08-05 507/week @ 2024-08-12 337/week @ 2024-08-19 374/week @ 2024-08-26 372/week @ 2024-09-02 561/week @ 2024-09-09 397/week @ 2024-09-16 492/week @ 2024-09-23 939/week @ 2024-09-30 433/week @ 2024-10-07 492/week @ 2024-10-14 309/week @ 2024-10-21 628/week @ 2024-10-28 686/week @ 2024-11-04 281/week @ 2024-11-11

1,906 downloads per month
Used in 2 crates

Apache-2.0

40KB
881 lines

json-schema-diff

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.

Usage via CLI

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.

Usage as library

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 }
        }
    ]
);

License

Licensed under Apache 2.0

Dependencies

~2–3.5MB
~62K SLoC