json-schema-diff 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +10 -0
- data/lib/json/schema/diff/comparer.rb +17 -3
- data/lib/json/schema/diff/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5fdcc51e044c305681f029f2a2cb6c4d5cd94bd1d365b03f2d9d5a9c8d10af92
|
|
4
|
+
data.tar.gz: 1756f0add39577e56a580217e23af84f85577af1377aaa43767202ade1aba638
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c30871c0d847945072f3038f358482131ccc4ca146e0391753e7ff14e107bdf4744988148cbbfe1a64330ae9ac3ad8405aca5c7de87d45a06414735b887c2371
|
|
7
|
+
data.tar.gz: e827e13873598a337d2337c0039514e8f4db86485d029532bf82586f64aeac0e57df9f2694a7af3d5f2c6ec167d538d31f2dd8fc5a5b0418f0941f9a2d1e8f94
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.2] - 2025-10-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Support for ignoring fields using regular expression patterns (contributed by @icnagy in #1)
|
|
15
|
+
|
|
10
16
|
## [0.2.1] - 2025-01-26
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -159,6 +159,16 @@ formatter = Json::Schema::Diff::Formatter.new('pretty', true)
|
|
|
159
159
|
puts formatter.format(changes)
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
+
#### Ignoring fields using regular expression
|
|
163
|
+
|
|
164
|
+
Fields can be ignored by using regular expressions:
|
|
165
|
+
|
|
166
|
+
```ruby
|
|
167
|
+
comparer = Json::Schema::Diff::Comparer.new(schema, [%r{List\[.*\]\.field}])
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This can be helpful when the field to be ignored is embedded in a list.
|
|
171
|
+
|
|
162
172
|
## Schema Features
|
|
163
173
|
|
|
164
174
|
### Supported JSON Schema Properties
|
|
@@ -11,10 +11,10 @@ module Json
|
|
|
11
11
|
# Initialize a new Comparer
|
|
12
12
|
#
|
|
13
13
|
# @param schema_parser [SchemaParser] Parser for the JSON Schema
|
|
14
|
-
# @param ignore_fields [Array<String>] List of field paths to ignore during comparison
|
|
14
|
+
# @param ignore_fields [Array<String|Regexp>] List of field paths and patterns to ignore during comparison
|
|
15
15
|
def initialize(schema_parser, ignore_fields = [])
|
|
16
16
|
@schema_parser = schema_parser
|
|
17
|
-
@ignore_fields = ignore_fields
|
|
17
|
+
@ignore_fields = ignore_fields
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Compares two JSON objects and returns a list of changes
|
|
@@ -30,9 +30,23 @@ module Json
|
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
|
|
33
|
+
def ignored?(path)
|
|
34
|
+
@ignore_fields
|
|
35
|
+
.any? { |pattern| matching?(path, pattern) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def matching?(path, pattern)
|
|
39
|
+
case pattern
|
|
40
|
+
when Regexp
|
|
41
|
+
pattern.match?(path)
|
|
42
|
+
else
|
|
43
|
+
path == pattern
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
33
47
|
def compare_recursive(old_val, new_val, path, changes)
|
|
34
48
|
# Skip ignored fields
|
|
35
|
-
return if
|
|
49
|
+
return if ignored?(path)
|
|
36
50
|
|
|
37
51
|
field_info = @schema_parser.get_field_info(path)
|
|
38
52
|
|