Skip to content

Better error message for additionalProperties: false when there are patternProperties#317

Merged
Julian merged 2 commits intopython-jsonschema:masterfrom
datawire:better-patternProperties-errors-316
Jan 26, 2017
Merged

Better error message for additionalProperties: false when there are patternProperties#317
Julian merged 2 commits intopython-jsonschema:masterfrom
datawire:better-patternProperties-errors-316

Conversation

@itamarst
Copy link

Fixes #316

Copy link
Member

@Julian Julian left a comment

Choose a reason for hiding this comment

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

Thanks, really appreciated!

Some nitpickin' because I can never resist, but overall looks good!

error = "Additional properties are not allowed (%s %s unexpected)"
yield ValidationError(error % _utils.extras_msg(extras))
if "patternProperties" in schema:
patterns = sorted(schema["patternProperties"].keys())
Copy link
Member

Choose a reason for hiding this comment

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

Can leave off the .keys()

verb = "does"
else:
verb = "do"
error = "%s %s not match any of the regexs: %s" % (
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be regexes :/?

schema = {u"type": u"object",
u"additionalProperties": False,
u"patternProperties": {
u"$abc^": {u"type": u"string"},
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: can you change these to slightly more realistic regexes, e.g. ^abc$ :)?

self.assertEqual(
message,
"{} does not match any of the regexs: $abc^, $def^".format(
repr(u"zebra")))
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: can you change the formatting here to not combine parens, e.g.

self.assertEqual(
    message,
    "whawefiuhweifuhiweuhfiwuehfiuwheftever".format(
        repr(stuff),
    ),
)

so that each one gets a trailing comma?

else:
verb = "do"
error = "%s %s not match any of the regexs: %s" % (
", ".join(map(repr, sorted(extras))), verb, ", ".join(patterns))
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to map repr for the first argument but not for the patterns?

Still would be a bit confusing I think if patterns ended up having the empty string in it.

@itamarst
Copy link
Author

OK, updated.

@itamarst
Copy link
Author

Travis CI issue appears to be unrelated at this point.

@Julian
Copy link
Member

Julian commented Jan 26, 2017

Bleh, yeah, OK, should have Travis CI fixed now, PyPy3 fun.

Thanks though! Looks good, merging, appreciated.

Now for a release...

@Julian Julian merged commit 124b81a into python-jsonschema:master Jan 26, 2017
Julian added a commit that referenced this pull request Jun 30, 2022
39d1d24d Merge pull request #317 from Relequestual/#291
b683de5a Forward-port and reword the new unevaluatedItems test.
816441f4 Add tests for Single-schema items and unevaluatedItems Resolves #291
1e0ebd20 Merge pull request #563 from json-schema-org/update-sanity-checker
e1dbaebb Merge pull request #562 from json-schema-org/remove-conditional-id-tests-from-draft6
53da77f3 Update the sanity checker to use a version which supports 2019+.
5aff83e5 reintroduce tests without using if/then/else
9495e3e4 remove conditional $id tests from draft 6

git-subtree-dir: json
git-subtree-split: 39d1d24dbc1920953dec90369edec5a2fa7158fa
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