jsonschema_diff.core

Submodules

Classes

Statuses

Create a collection of name/value pairs.

ToCompare

Compare

CompareCombined

Config

Property

Package Contents

class Statuses(*args, **kwds)[source]

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ADDED = '+'
DELETED = '-'
REPLACED = 'r'
MODIFIED = 'm'
NO_DIFF = ' '
UNKNOWN = '?'
class ToCompare(
old_key: str | None,
old_value: Any,
new_key: str | None,
new_value: Any,
)[source]
old_key
old_value
new_key
new_value
__repr__() str[source]
class Compare(
config: jsonschema_diff.core.config.Config,
schema_path: COMPARE_PATH_TYPE,
json_path: COMPARE_PATH_TYPE,
to_compare: list[ToCompare],
)[source]
status
config
schema_path
json_path
to_compare
property my_config: dict
compare() jsonschema_diff.core.abstraction.Statuses[source]
get_name() str[source]
is_for_rendering() bool[source]
calc_diff() dict[str, int][source]

Basic implementation: counts its own status as 1 element. Complex comparators (e.g. CompareList) override this to return an aggregate.

render(
tab_level: int = 0,
with_path: bool = True,
to_crop: tuple[int, int] = (0, 0),
) str[source]
static legend() LEGEND_RETURN_TYPE[source]
class CompareCombined(*args: Any, **kwargs: Any)[source]
dict_compare: Dict[str, ToCompare]
dict_values: Dict[str, Any]
compare() jsonschema_diff.core.abstraction.Statuses[source]
calc_diff() dict[str, int][source]

Multiple implementation: counts its own status as the number of keys. Complex comparators (e.g. CompareList) override this to return an aggregate.

abstractmethod get_name() str[source]
abstractmethod render(
tab_level: int = 0,
with_path: bool = True,
to_crop: tuple[int, int] = (0, 0),
) str[source]
static legend() jsonschema_diff.core.compare_base.LEGEND_RETURN_TYPE[source]
Abstractmethod:

class Config(
tab: str = '  ',
all_for_rendering: bool = False,
crop_path: bool = True,
compare_rules: jsonschema_diff.core.tools.compare.COMPARE_RULES_TYPE = {},
combine_rules: jsonschema_diff.core.tools.combine.COMBINE_RULES_TYPE = [],
path_maker_ignore: jsonschema_diff.core.tools.render.PATH_MAKER_IGNORE_RULES_TYPE = ['properties', 'items'],
pair_context_rules: jsonschema_diff.core.tools.context.PAIR_CONTEXT_RULES_TYPE = [],
context_rules: jsonschema_diff.core.tools.context.CONTEXT_RULES_TYPE = {},
compare_config: COMPARE_CONFIG_TYPE = {},
property_key_groups: PROPERTY_KEY_GROUPS_TYPE = {dict: ['properties', '$defs'], list: ['prefixItems', 'items']},
)[source]
TAB: str = '  '
ALL_FOR_RENDERING = False
CROP_PATH = True
COMPARE_RULES: jsonschema_diff.core.tools.compare.COMPARE_RULES_TYPE
COMBINE_RULES: jsonschema_diff.core.tools.combine.COMBINE_RULES_TYPE = []
PATH_MAKER_IGNORE: jsonschema_diff.core.tools.render.PATH_MAKER_IGNORE_RULES_TYPE = ['properties', 'items']
PAIR_CONTEXT_RULES: jsonschema_diff.core.tools.context.PAIR_CONTEXT_RULES_TYPE = []
CONTEXT_RULES: jsonschema_diff.core.tools.context.CONTEXT_RULES_TYPE
COMPARE_CONFIG: COMPARE_CONFIG_TYPE

Configs for comparators. Can be obtained from Compare.my_config (content can be anything)

PROPERTY_KEY_GROUPS: PROPERTY_KEY_GROUPS_TYPE
class Property(
config: jsonschema_diff.core.config.Config,
schema_path: list[str | int],
json_path: list[str | int],
name: str | int | None,
old_schema: dict | None,
new_schema: dict | None,
)[source]
status: jsonschema_diff.core.abstraction.Statuses
parameters: dict[str, Compare]
propertys: dict[str | int, Property]
config
name
schema_path
json_path
old_schema
new_schema
property json_path_with_name: list[str | int]
property schema_path_with_name: list[str | int]
compare() None[source]
is_for_rendering() bool[source]
calc_diff() dict[str, int][source]

Summarizes the difference statistics: - all parameters (Compare.calc_diff) - child properties (Property.calc_diff) - plus the status of the current Property (as a single observation)

get_for_rendering() list[Compare][source]
self_render(
tab_level: int = 0,
to_crop: tuple[int, int] = (0, 0),
force_multiline: bool = False,
) tuple[str, list[type[Compare]]][source]
render(
tab_level: int = 0,
_to_crop: tuple[int, int] = (0, 0),
) tuple[list[str], list[type[Compare]]][source]