@@ -34,7 +34,7 @@ <h1 class="title">Package <code>schemadiff</code></h1>
3434from schemadiff.diff.schema import Schema
3535from schemadiff.schema_loader import SchemaLoader
3636from schemadiff.formatting import print_diff, format_diff
37- from schemadiff.validation import validate_diff
37+ from schemadiff.validation import validate_changes
3838
3939
4040SDL = str # Alias for string describing schema through schema definition language
@@ -67,7 +67,7 @@ <h1 class="title">Package <code>schemadiff</code></h1>
6767 'diff_from_file',
6868 'format_diff',
6969 'print_diff',
70- 'validate_diff ',
70+ 'validate_changes ',
7171 'Change',
7272]</ code > </ pre >
7373</ details >
@@ -182,13 +182,13 @@ <h2 id="returns">Returns</h2>
182182 print(format_diff(changes))</ code > </ pre >
183183</ details >
184184</ dd >
185- < dt id ="schemadiff.validate_diff "> < code class ="name flex ">
186- < span > def < span class ="ident "> validate_diff </ span > </ span > (< span > diff, rules: List[str]) ‑>  bool </ span >
185+ < dt id ="schemadiff.validate_changes "> < code class ="name flex ">
186+ < span > def < span class ="ident "> validate_changes </ span > </ span > (< span > diff: List[ < a title =" schemadiff.changes.Change " href =" changes/index.html#schemadiff.changes.Change " > Change </ a > ] , rules: List[str], allowed_changes: Dict[str, Any] = None ) ‑>  < a title =" schemadiff.validation.ValidationResult " href =" validation.html#schemadiff.validation.ValidationResult " > ValidationResult </ a > </ span >
187187</ code > </ dt >
188188< dd >
189- < div class ="desc "> < p > Given a diff between schemas and a list of rules
190- names, it looks up for all rules matching the list
191- and evaluates the changes against that list. </ p >
189+ < div class ="desc "> < p > Given a list of changes between schemas and a list of rules,
190+ it runs all rules against the changes, to detect invalid changes.
191+ It also admits an allowlist of accepted invalid changes to document exceptions to the rules </ p >
192192< h2 id ="returns "> Returns</ h2 >
193193< dl >
194194< dt > < code > bool</ code > </ dt >
@@ -199,24 +199,30 @@ <h2 id="returns">Returns</h2>
199199< summary >
200200< span > Expand source code</ span >
201201</ summary >
202- < pre > < code class ="python "> def validate_diff (diff, rules: List[str]) -> bool :
203- """Given a diff between schemas and a list of rules
204- names, it looks up for all rules matching the list
205- and evaluates the changes against that list.
202+ < pre > < code class ="python "> def validate_changes (diff: List[Change] , rules: List[str], allowed_changes: Dict[str, Any] = None ) -> ValidationResult :
203+ """Given a list of changes between schemas and a list of rules,
204+ it runs all rules against the changes, to detect invalid changes.
205+ It also admits an allowlist of accepted invalid changes to document exceptions to the rules
206206
207207 Returns:
208208 bool: True if there is at least one restricted change,
209209 False otherwise.
210210 """
211- is_restricted = False
211+ allowed_changes = allowed_changes or {}
212+ is_valid = True
213+ errors = []
212214 rules = ValidationRule.get_subclasses_by_names(rules)
213215 for change in diff:
214216 for rule in rules:
215217 if not rule(change).is_valid():
218+ if change.checksum() in allowed_changes:
219+ continue
220+
216221 change.restricted = rule(change).message
217- is_restricted = True
222+ is_valid = False
223+ errors.append(ValidationError(rule.name, change.restricted, change))
218224
219- return is_restricted </ code > </ pre >
225+ return ValidationResult(is_valid, errors) </ code > </ pre >
220226</ details >
221227</ dd >
222228</ dl >
@@ -497,7 +503,7 @@ <h1>Index</h1>
497503< li > < code > < a title ="schemadiff.diff_from_file " href ="#schemadiff.diff_from_file "> diff_from_file</ a > </ code > </ li >
498504< li > < code > < a title ="schemadiff.format_diff " href ="#schemadiff.format_diff "> format_diff</ a > </ code > </ li >
499505< li > < code > < a title ="schemadiff.print_diff " href ="#schemadiff.print_diff "> print_diff</ a > </ code > </ li >
500- < li > < code > < a title ="schemadiff.validate_diff " href ="#schemadiff.validate_diff " > validate_diff </ a > </ code > </ li >
506+ < li > < code > < a title ="schemadiff.validate_changes " href ="#schemadiff.validate_changes " > validate_changes </ a > </ code > </ li >
501507</ ul >
502508</ li >
503509< li > < h3 > < a href ="#header-classes "> Classes</ a > </ h3 >
0 commit comments