jsonschema_diff.core.tools

Submodules

Classes

LogicCombinerHandler

Group items by user-defined rules and merge their inner fields.

CompareRules

Pick an appropriate comparator class according to rule precedence.

RenderContextHandler

Expand context comparators based on pair- and directed-dependency rules.

RenderTool

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',
) Dict[Tuple[str, Ellipsis], Dict[str, Any]][source]

Build an OrderedDict that groups subset items per rules.

Returns:

(k1, k2, …) -> {inner_key_field: common_key, inner_value_field: [v1, v2, …]}

Return type:

dict

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(
rules: COMPARE_RULES_TYPE,
default: type[Compare],
key: str,
old: Any,
new: Any,
) type[Compare][source]

Wrapper that resolves comparator from values.

static get_comparator(
rules: COMPARE_RULES_TYPE,
default: type[Compare],
key: str,
old: type,
new: type,
) type[Compare][source]

Resolve a comparator class according to the following lookup order:

  1. (key, old_type, new_type)

  2. key

  3. (old_type, new_type)

  4. old_type or new_type (if one of them is NoneType)

  5. default

Parameters:
  • rules (dict) – Precedence map.

  • default (Compare subclass) – Fallback comparator.

  • key (str) – Field name.

  • old (type) – Types being compared.

  • new (type) – Types being compared.

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],
) Dict[str, jsonschema_diff.core.parameter_base.Compare][source]

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,
) str[source]

Return indentation string.

Parameters:
  • config (Config) – Application config that owns the TAB constant.

  • tab_level (int) – Indentation depth.

Returns:

config.TAB repeated tab_level times.

Return type:

str

static make_prefix(
status: jsonschema_diff.core.abstraction.Statuses,
) str[source]

Convert a Statuses enum value to its printable form.

Parameters:

status (Statuses) – Validation status.

Returns:

status.value as plain text.

Return type:

str

static make_path(
schema_path: Sequence[Any],
json_path: Sequence[Any],
ignore: PATH_MAKER_IGNORE_RULES_TYPE = ('properties',),
) str[source]

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.

    1. Otherwise the token exists only in schema → emit as .token and – advance i.

  • 4. After the schema is exhausted, append remaining elements ofjson_path.

  • Integer‑like tokens are rendered as [n]; everything else as

  • ["key"].