Check one JSON schema is a subset of another
Project description
isjsonschemasubset
Check one JSONSchema is a subset of another. Plays nicely with Pydantic
.
Install
pip install isjsonschemasubset
Currently in an Alpha.
Usage
from pathlib import Path
from isjsonschemasubset import dump, issubset, load
path_to_a = Path(__file__).parent / "a.json"
path_to_b = Path(__file__).parent / "b.json"
dump(A, path_to_a) # where A is a `type[pydantic.BaseModel]`
dump(B, path_to_b) # where B is a `type[pydantic.BaseModel]`
json_schema_a = load(path_to_a)
json_schema_b = load(path_to_b)
for error in issubset(json_schema_a, json_schema_b):
...
Yields errors if type A
is not a subset of B
.
In this context, "is a subset of" means that if we were to do:
B(**a.model_dump(mode="json"))
We would not get an error. This is very important when deserializing data from JSON columns in the database and for writing backwards compatible APIs.
See tests/test_schema_versions.py for further example usage. In this case, every time we change Foo
(or anything that Foo
refers to recursively), we dump a new schema in tests/schemas/Foo and check all of the schemas are backwards compatible.
Dev install
git clone git@github.com:leontrolski/isjsonschemasubset.git
pip install -r requirements-dev.txt
pytest
mypy src tests --strict
Upload to pypi
# bump version
python -m pip install build twine
python -m build
twine check dist/*
twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for isjsonschemasubset-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d16ed09ece947205c9e824b776ea9f880c67ebce52219dad9b13a539539f174 |
|
MD5 | 16c64056754e82d81135d54069eb28b0 |
|
BLAKE2b-256 | dd992289bd8be3057ea21e5c4299052ef6f32b1e687efc5bab1bac0da2f6ef20 |