jsonschema_diff.core.tools¶
Submodules¶
Classes¶
Group items by user-defined rules and merge their inner fields. |
|
Pick an appropriate comparator class according to rule precedence. |
|
Expand context comparators based on pair- and directed-dependency rules. |
|
Small helper utilities used by the rendering subsystem. |
Package Contents¶
- class LogicCombinerHandler[source]¶
Group items by user-defined rules and merge their inner fields.
- static combine(
- subset: Dict[str, Any],
- rules: List[List[str]],
- inner_key_field: str = 'comparator',
- inner_value_field: str = 'to_compare',
Build an
OrderedDict
that groups subset items per rules.- Returns:
(k1, k2, …) -> {inner_key_field: common_key, inner_value_field: [v1, v2, …]}
- Return type:
Note
Keys not covered by rules stay as single-element groups.
Inner keys in the same group must match or
ValueError
is raised.
- class CompareRules[source]¶
Pick an appropriate comparator class according to rule precedence.
- static get_comparator_from_values( ) type[Compare] [source]¶
Wrapper that resolves comparator from values.
- class RenderContextHandler[source]¶
Expand context comparators based on pair- and directed-dependency rules.
- static resolve(
- *,
- pair_context_rules: PAIR_CONTEXT_RULES_TYPE,
- context_rules: CONTEXT_RULES_TYPE,
- for_render: Mapping[str, jsonschema_diff.core.parameter_base.Compare],
- not_for_render: Mapping[str, jsonschema_diff.core.parameter_base.Compare],
Build the final ordered context for rendering.
- Parameters:
pair_context_rules (Sequence[Sequence[RULE_KEY]]) – Undirected groups: if one member is rendered, pull the rest (order preserved).
context_rules (Mapping[RULE_KEY, Sequence[RULE_KEY]]) – Directed dependencies:
source → [targets...]
.for_render (Mapping[str, Compare]) – Initial items, order defines primary screen order.
not_for_render (Mapping[str, Compare]) – Optional items that may be added by the rules.
- Returns:
dict – Ordered
{name -> Compare}
ready for UI.Algorithm (high-level)
———————-
* Walk through *for_render keys.*
* While iterating, append new candidates to the tail of the scan list.
* A candidate is added once when first matched by any rule.
- class RenderTool[source]¶
Small helper utilities used by the rendering subsystem.
- static make_tab(
- config: jsonschema_diff.core.config.Config,
- tab_level: int,
Return indentation string.
- static make_prefix(
- status: jsonschema_diff.core.abstraction.Statuses,
Convert a
Statuses
enum value to its printable form.
- static make_path(
- schema_path: Sequence[Any],
- json_path: Sequence[Any],
- ignore: PATH_MAKER_IGNORE_RULES_TYPE = ('properties',),
Compose a human‑readable path by synchronising two parallel paths.
The function walks through schema_path (tokens from JSON Schema) and json_path (real path in the JSON instance) and emits a short textual representation such as
["items"][0].extra
.- Parameters:
schema_path (Sequence[Any]) – Tokens encountered while traversing the schema.
json_path (Sequence[Any]) – Path tokens from the actual JSON document.
ignore (Sequence[str], default (
"properties"
,)) – Schema‑only service tokens to skip.
- Returns:
str – Compact path string.
Algorithm
———
i — index in *schema_path, j — index in json_path.*
1. If *schema_path[i] is in ignore and differs from* – json_path[j] → skip it.
2. If tokens are equal → emit as property/index and advance both.
Otherwise the token exists only in schema → emit as
.token
and – advance i.
4. After the schema is exhausted, append remaining elements of – json_path.
Integer‑like tokens are rendered as
[n]
; everything else as["key"]
.