diff and openapi only.Expand description
Schema diffing — compare two JSON Schemas to find breaking changes.
Useful for API versioning: detect when a schema change will break existing consumers.
Requires the diff feature. It works on plain serde_json::Value JSON
Schemas (e.g. from json_schema() with the openapi feature, or any other
source).
Direction: the classification assumes request / input schemas — a change is breaking when the new schema rejects input the old one accepted (stricter), non-breaking when it only accepts more. For response schemas read it the other way round.
Nullable wrappers (anyOf/oneOf of [X, {"type": "null"}], as emitted
by .optional() / .nullable()) are unwrapped and X is compared;
gaining null is non-breaking, losing it is breaking. anyOf / oneOf /
allOf branches are compared position by position, $ref targets by name.
§Example
use serde_json::json;
use vld::diff::{diff_schemas, ChangeKind};
let old = json!({
"type": "object",
"required": ["name", "email"],
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
}
});
let new = json!({
"type": "object",
"required": ["name", "email", "age"],
"properties": {
"name": { "type": "string" },
"email": { "type": "string" },
"age": { "type": "integer" }
}
});
let changes = diff_schemas(&old, &new);
assert!(changes.has_breaking());Structs§
- Schema
Change - A single schema change.
- Schema
Diff - Result of diffing two schemas.
Enums§
- Change
Kind - Severity of a schema change.
Functions§
- diff_
schemas - Compare two JSON Schemas and return a list of changes.