Skip to content

Keep minimum and maximum inclusive in draft 06 and later - #231

Open
wleeaf wants to merge 1 commit into
horejsek:masterfrom
wleeaf:fix-draft06-inclusive-min-max
Open

wleeaf wants to merge 1 commit into
horejsek:masterfrom
wleeaf:fix-draft06-inclusive-min-max

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 24, 2026

Copy link
Copy Markdown

In draft 06 and later, minimum and maximum become exclusive when the schema also sets exclusiveMinimum or exclusiveMaximum to a number other than zero:

import fastjsonschema

schema = {'$schema': 'http://json-schema.org/draft-07/schema', 'maximum': 10, 'exclusiveMaximum': 15}
fastjsonschema.validate(schema, 10)
# JsonSchemaValueException: data must be smaller than 10

schema = {'$schema': 'http://json-schema.org/draft-07/schema', 'minimum': 10, 'exclusiveMinimum': 5}
fastjsonschema.validate(schema, 10)
# JsonSchemaValueException: data must be bigger than 10

10 satisfies both keywords in each schema, and jsonschema.Draft7Validator(schema).is_valid(10) is True for both.

CodeGeneratorDraft06 inherits generate_minimum and generate_maximum from draft 04, where exclusiveMinimum/exclusiveMaximum are booleans that make the bound exclusive. Since draft 06 they are numbers and are already checked on their own by generate_exclusive_minimum/generate_exclusive_maximum, but the inherited code still reads them as a flag. Any number other than 0 is truthy, so the bound turned exclusive. Draft 06 now overrides both methods with the inclusive check only, so draft 04 behaves as before.

Added test_minimum_and_maximum_stay_inclusive_next_to_exclusive_keywords to tests/test_number.py for drafts 06 and 07. It fails before the change and passes after.

Checks run:

  • python -m pytest -m "not benchmark" tests: 4543 passed (4539 plus the 4 new cases), with the same xfailed and xpassed counts as before
  • python -m pylint fastjsonschema: same warnings as before, 9.90/10

Found by differential testing against jsonschema on generated draft 07 schemas.

Draft 06 and later reused the draft 04 minimum and maximum checks, which
make the bound exclusive when exclusiveMinimum or exclusiveMaximum is
truthy. Since draft 06 those keywords are numbers validated on their
own, so {"maximum": 10, "exclusiveMaximum": 15} rejected 10.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants