Skip to content

Commit 934b193

Browse files
authored
Add schema diff to the output (#73)
1 parent 0dd49b9 commit 934b193

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/rpdk/guard_rail/core/data_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
"""
2121
from dataclasses import dataclass, field
22-
from typing import Any, Dict, List
22+
from typing import Any, Dict, List, Optional
2323

2424
from rich.console import Console
2525
from rich.table import Table
@@ -78,12 +78,14 @@ class GuardRuleSetResult:
7878
non_compliant: rules, that schema(s) failed
7979
warning: rules, that schema(s) failed but it's not a hard requirement
8080
skipped: rules, that are not applicable to the schema(s)
81+
schema_difference: optional dictionary containing schema difference
8182
"""
8283

8384
compliant: List[str] = field(default_factory=list)
8485
non_compliant: Dict[str, List[GuardRuleResult]] = field(default_factory=dict)
8586
warning: Dict[str, List[GuardRuleResult]] = field(default_factory=dict)
8687
skipped: List[str] = field(default_factory=list)
88+
schema_difference: Optional[dict] = field(default_factory=dict)
8789

8890
def merge(self, guard_ruleset_result: Any):
8991
"""Merges the result into a nice mutual set.

src/rpdk/guard_rail/core/runner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ def __execute__(schema_exec, ruleset):
183183
output = schema_exec(rules)
184184
return output
185185

186-
schema_to_execute = __exec_rules__(
187-
schema=schema_diff(
188-
previous_json=payload.previous_schema, current_json=payload.current_schema
189-
)
186+
schema_difference = schema_diff(
187+
previous_json=payload.previous_schema, current_json=payload.current_schema
190188
)
189+
190+
schema_to_execute = __exec_rules__(schema=schema_difference)
191191
output = __execute__(schema_exec=schema_to_execute, ruleset=ruleset)
192+
output.schema_difference = schema_difference
192193
compliance_output.append(output)
193194

194195
return compliance_output

tests/unit/core/test_data_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def test_success_result_str():
3737
}
3838
)
3939
)
40-
== "GuardRuleSetResult(compliant=[], non_compliant={'ensure_old_property_not_turned_immutable': {GuardRuleResult(check_id='MI007', message='cannot remove minimum from properties', path='/minimum/removed')}}, warning={}, skipped=[])" # pylint: disable=C0301
40+
== "GuardRuleSetResult(compliant=[], non_compliant={'ensure_old_property_not_turned_immutable': {GuardRuleResult(check_id='MI007', message='cannot remove minimum from properties', path='/minimum/removed')}}, warning={}, skipped=[], schema_difference={})" # pylint: disable=C0301
4141
)

0 commit comments

Comments
 (0)