A Wagtail StreamField JSON validation provider.
This is a very early project, and it is not yet ready for production use. It is a work in progress.
This project seeks to address/implement wagtail/wagtail#6495.
The goal of this project is to provide a way to validate the JSON structure of a Wagtail StreamField. This is useful when you want to generate or modify StreamField content programmatically, and you want to ensure that the content is valid before saving it to the database.
The immediate next steps for the project are:
- Ability to generate a JSON schema from a StreamField definition.
- Ability to validate a JSON object against the generated schema.
- Ability to install the JSON schema as a validator on the StreamField's model JSONField.
- Ability to install the JSON schema as a validator on a rest_framework endpoint.
The project should be built in a way that it can be used to produce other validation formats than JSON schema. For example, one might like to generate a Pydantic model to use for programmatic validation of the StreamField content.
This project might potentially use the following packages:
Also note these
- Python 3.10, 3.11, 3.12
- Django 4.2, 5.0, 5.1
- Wagtail 4.1, 5.2, 6.0, 6.1
python -m pip install wagtail-streamfield-validator
- ...
To make changes to this project, first clone this repository:
git clone https://github.com/wagtail/wagtail-streamfield-validator.git
cd wagtail-streamfield-validator
With your preferred virtualenv activated, install testing dependencies:
python -m pip install --upgrade pip>=21.3
python -m pip install -e '.[testing]' -U
python -m pip install flit
flit install
Note that this project uses pre-commit. It is included in the project testing requirements. To set up locally:
# go to the project directory
$ cd wagtail-streamfield-validator
# initialize pre-commit
$ pre-commit install
# Optional, run all checks once for this, then the checks will run only on the changed files
$ git ls-files --others --cached --exclude-standard | xargs pre-commit run --files
Now you can run tests as shown below:
tox
or, you can run them for a specific environment tox -e python3.11-django4.2-wagtail5.1
or specific test
tox -e python3.11-django4.2-wagtail5.1-sqlite wagtail-streamfield-validator.tests.test_file.TestClass.test_method
To run the test app interactively, use tox -e interactive
, visit http://127.0.0.1:8020/admin/
and log in with admin
/changeme
.