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
File details
Details for the file isjsonschemasubset-0.0.2.tar.gz
.
File metadata
- Download URL: isjsonschemasubset-0.0.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fd22abf1963c51bcd301f6cb0be484a1a0b440a83f2eb52889483ca880c6979 |
|
MD5 | 0ff0b499a88bc02b0c5b49915a764cd8 |
|
BLAKE2b-256 | 5d8e66e5f11ac5dc6c12551b5f85ec223c871a8228a7ed88bd46d09fd16ae5c8 |
File details
Details for the file isjsonschemasubset-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: isjsonschemasubset-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d16ed09ece947205c9e824b776ea9f880c67ebce52219dad9b13a539539f174 |
|
MD5 | 16c64056754e82d81135d54069eb28b0 |
|
BLAKE2b-256 | dd992289bd8be3057ea21e5c4299052ef6f32b1e687efc5bab1bac0da2f6ef20 |