Repository navigation
Conversation
In draft 2019-09, minContains (default 1) and maxContains (default
unlimited) bound how many array items must be valid against contains.
They were ignored, so for example {"contains": {"type": "number"},
"maxContains": 1} accepted [1, 2], and minContains: 0 did not make an
array without matching items valid.
The draft-2019 generator now counts the matching items when either
keyword is set and checks both bounds; plain contains keeps the existing
short-circuit code. Both keywords must be non-negative integers. The
suite files minContains.json and maxContains.json are no longer ignored.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #81 (draft 2019-09 support): adds the
minContainsandmaxContainskeywords.In draft 2019-09,
minContains(default 1) andmaxContains(default unlimited) bound how many array items must be valid againstcontains(validation spec, section 6.4.4–6.4.5). Until now both keywords were ignored:Changes:
CodeGeneratorDraft2019.generate_contains: whenminContainsormaxContainsis set, the generated code counts the items valid againstcontainsand checks both bounds (rule='minContains'/rule='maxContains').contains: truecounts every item, andcontains: falsecounts none. Plaincontains(no bounds, orminContains: 1only) still uses the existing draft-06 code, which stops at the first match.2.0is accepted, as in the suite); otherwiseJsonSchemaDefinitionException. Booleans are rejected.tests/json_schema/test_draft2019.py:minContains.jsonandmaxContains.jsonare removed from the ignored suite files. Without the change, 16 of their 40 cases fail.tests/test_array.py: tests for both bounds,contains: true/falsewith bounds,minContains/maxContainsof 0, and invalid definitions.CHANGELOG.txt: one line under UNRELEASED.Test run (
pytest -m "not benchmark", as intox -e py, with the JSON-Schema-Test-Suite submodule at the pinned commit9fc880bf), Python 3.13:pylint fastjsonschemareports the same messages as on master; none are in the new code.The change and the tests were prepared with an AI assistant (Claude Code with Claude Opus 5.5).
I used an AI assistant to help prepare this change.