Skip to content

Commit

Permalink
Add schema diff to the output (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
spchit authored Oct 31, 2024
1 parent 0dd49b9 commit 934b193
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/rpdk/guard_rail/core/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
"""
from dataclasses import dataclass, field
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

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

compliant: List[str] = field(default_factory=list)
non_compliant: Dict[str, List[GuardRuleResult]] = field(default_factory=dict)
warning: Dict[str, List[GuardRuleResult]] = field(default_factory=dict)
skipped: List[str] = field(default_factory=list)
schema_difference: Optional[dict] = field(default_factory=dict)

def merge(self, guard_ruleset_result: Any):
"""Merges the result into a nice mutual set.
Expand Down
9 changes: 5 additions & 4 deletions src/rpdk/guard_rail/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ def __execute__(schema_exec, ruleset):
output = schema_exec(rules)
return output

schema_to_execute = __exec_rules__(
schema=schema_diff(
previous_json=payload.previous_schema, current_json=payload.current_schema
)
schema_difference = schema_diff(
previous_json=payload.previous_schema, current_json=payload.current_schema
)

schema_to_execute = __exec_rules__(schema=schema_difference)
output = __execute__(schema_exec=schema_to_execute, ruleset=ruleset)
output.schema_difference = schema_difference
compliance_output.append(output)

return compliance_output
2 changes: 1 addition & 1 deletion tests/unit/core/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def test_success_result_str():
}
)
)
== "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
== "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
)

0 comments on commit 934b193

Please sign in to comment.