json-schema-diff
json-schema-diff copied to clipboard
feat: Add string validation support (pattern, minLength, maxLength)
Summary
Implements detection of JSON Schema string validation constraints: pattern, minLength, and maxLength.
Changes
Pattern Support
- PatternAdd/Remove/Change change types
- Pattern changes conservatively treated as breaking (determining if one regex is a subset of another requires complex AST analysis or fuzzing, which is out of scope per issue discussion)
MinLength Support
- MinLengthAdd/Remove/Change change types
- Smart breaking logic:
- Increasing minLength: breaking (rejects previously valid shorter strings)
- Decreasing minLength: non-breaking (accepts more strings)
MaxLength Support
- MaxLengthAdd/Remove/Change change types
- Smart breaking logic:
- Decreasing maxLength: breaking (rejects previously valid longer strings)
- Increasing maxLength: non-breaking (accepts more strings)
Test Coverage
14 comprehensive test fixtures covering:
- Pattern: add, remove, change, unchanged
- MinLength: add, remove, increase (breaking), decrease (non-breaking), unchanged
- MaxLength: add, remove, decrease (breaking), increase (non-breaking), unchanged
Examples
# Pattern add (breaking)
{"path":"","change":{"PatternAdd":{"added":"^[a-z]+$"}},"is_breaking":true}
# MinLength increase 3→5 (breaking)
{"path":"","change":{"MinLengthChange":{"old_value":3,"new_value":5}},"is_breaking":true}
# MinLength decrease 5→3 (non-breaking)
{"path":"","change":{"MinLengthChange":{"old_value":5,"new_value":3}},"is_breaking":false}
# MaxLength decrease 10→5 (breaking)
{"path":"","change":{"MaxLengthChange":{"old_value":10,"new_value":5}},"is_breaking":true}
Fixes #23 Fixes #50