schemaDiff()
Diff two JSON Schema documents.
Signature
php
JsonFast::schemaDiff(
string $beforeSchema,
string $afterSchema,
?int $output = OUTPUT_ARRAY
): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$beforeSchema | string | — | Original schema JSON |
$afterSchema | string | — | Updated schema JSON |
$output | ?int | OUTPUT_ARRAY | Output mode |
Returns
Structural difference between the two schemas — same general shape as diff() (added, removed, changed with JSON Pointer-style paths).
Use when reviewing API version bumps or generating changelog entries for contract changes.
Examples
Compare v1 and v2 API schemas:
php
$changes = JsonFast::schemaDiff(
file_get_contents('schemas/v1.json'),
file_get_contents('schemas/v2.json')
);
if (!empty($changes['removed'])) {
notifyBreakingChange($changes['removed']);
}CI check — schema must not drift unexpectedly:
php
$drift = JsonFast::schemaDiff($committedSchema, $generatedSchema);
assert(empty($drift['added']) && empty($drift['removed']) && empty($drift['changed']));Related
diff()— diff data documentsgetSchema()— infer schema from JSON
