Hypothesis-jsonschema is a Python library that provides a Hypothesis strategy for generating test data that conforms to a given JSON schema. It is currently in version 0.23.1. As a 0.x release series, it may introduce backwards-incompatible changes before reaching 1.0. It supports JSONSchema drafts 04, 05, and 07, including resolving non-recursive references.
pip install hypothesis-jsonschemaVerified import paths — ran on the pinned version, not inferred.
Demonstrates the core usage of `from_schema` to generate data matching simple JSON schemas. It includes examples for integers, strings with formats, and a note on common `hypothesis.settings` usage.
Always pin to exact minor versions (e.g., `hypothesis-jsonschema==0.23.*`) and review changelogs carefully when upgrading between minor versions.
For schemas with recursive references, you might need to manually craft strategies for the recursive parts or consider alternative generation methods. Keep an eye on the project's issue tracker for updates on recursive `$ref` support.
Ensure your environment has the latest compatible versions of `hypothesis` and `jsonschema`. If encountering issues, try upgrading these dependencies first.
Install the library using pip: `pip install hypothesis-jsonschema`
Downgrade the `jsonschema` package to a compatible version, typically `pip install 'jsonschema<4.0'` if the dependent library requires older versions, or ensure all dependencies are updated to support `jsonschema` 4.0+ if that is the intended version.
Ensure that all `$ref` pointers are correct and resolvable. For internal references, make sure the definitions are correctly placed, typically under a `definitions` or `$defs` keyword, and the paths match. For external references, provide a `RefResolver` with appropriate base URIs or local mappings if fetching remote schemas. Upgrading `jsonschema` (e.g., to 4.3.2 or newer) can sometimes resolve bugs related to reference resolution.
While `hypothesis-jsonschema` might handle this internally, if you are directly catching `jsonschema.exceptions.RefResolutionError` in your tests or application code, you should update your exception handling to catch `referencing.exceptions.Unresolvable` instead (after importing it from `referencing.exceptions`). Alternatively, update `hypothesis-jsonschema` to a version that officially supports and handles these changes in `jsonschema`.