Idea: warn on unsupported keywords (e.g. "const" in draft-04 schemas)

Open
#778 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start with the validate example and the DraftXValidator implementations. Review how each draft handles schema keywords, then define warning behavior for the listed newer or renamed keywords while preserving the existing treatment of unknown format values; verify the warnings across the affected draft validators.

Written by the indexing model from the issue text.

Description

Dialects v2 Enhancement

I just spent a few minutes digging into a test failure which boiled down to the following:

from jsonschema import validate

schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "const": None,
}
validate("literally anything validates", schema)

which is of course because the const keyword was added in draft-06! Since I've seen analogous problems several times now, I wonder if we should make the earlier DraftXValidators emit a warning when they see a keyword which was added in a later draft. That would be:

  • <= draft04, warn on propertyNames, contains, and const (added in draft06)
  • <= draft06, warn on if, then, and else (added in draft07)
  • In draft07, the media keyword was replaced with contentMediaType and contentEncoding, so warnings on both sides could help
  • <= draft07... there are lots

I've ignored the string format values, because they explictly permit ignoring unknown values and it's reasonable to think that users might have backported a check - whereas the too-new keywords are almost certainly a programmer error.

Dominant language
Python
Stars
5k
Forks
741
Avg merge
4d 17h
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-jsonschema/jsonschema

All issues in python-jsonschema/jsonschema

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.