python-jsonschema / python-jsonschema/jsonschema

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

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

Nobody has claimed this yet.

Dialects v2 Enhancement
Dominant language
Python
Stars
5k
Forks
671
Avg merge
1d 1h
Merged PRs (30d)
10

Description

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.

Contributor guide

Open the contributing guide

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.