pub fn normalise(schema: &Value) -> ValueExpand description
Reduce a JSON Schema to the part of it a caller can break against.
Two normalisations, and no more, because every one of them is a place a real contract change could hide:
- the prose keys above are dropped, at every depth;
- object keys are rebuilt in sorted order, so that a generator that emitted them differently produces the same value.
Array order is kept. A schema’s required list, its enum and its oneOf are sets in
meaning but the comparison in super::compat treats them as sets explicitly, where it
knows what they mean. Sorting them here would also silently reorder prefixItems, where
order is the contract.
use majordomus_cli::release::surface::normalise;
use serde_json::json;
let one = json!({"type": "object", "description": "one wording"});
let other = json!({"type": "object", "description": "another, at length"});
assert_eq!(normalise(&one), normalise(&other), "prose is not contract");
// and it is a fixed point, so normalising twice changes nothing further
let once = normalise(&one);
assert_eq!(normalise(&once), once);