Better error message for additionalProperties: false when there are patternProperties#317
Conversation
…atternProperties.
Julian
left a comment
There was a problem hiding this comment.
Thanks, really appreciated!
Some nitpickin' because I can never resist, but overall looks good!
jsonschema/_validators.py
Outdated
| 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()) |
jsonschema/_validators.py
Outdated
| verb = "does" | ||
| else: | ||
| verb = "do" | ||
| error = "%s %s not match any of the regexs: %s" % ( |
jsonschema/tests/test_validators.py
Outdated
| schema = {u"type": u"object", | ||
| u"additionalProperties": False, | ||
| u"patternProperties": { | ||
| u"$abc^": {u"type": u"string"}, |
There was a problem hiding this comment.
Nitpick: can you change these to slightly more realistic regexes, e.g. ^abc$ :)?
jsonschema/tests/test_validators.py
Outdated
| self.assertEqual( | ||
| message, | ||
| "{} does not match any of the regexs: $abc^, $def^".format( | ||
| repr(u"zebra"))) |
There was a problem hiding this comment.
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?
jsonschema/_validators.py
Outdated
| else: | ||
| verb = "do" | ||
| error = "%s %s not match any of the regexs: %s" % ( | ||
| ", ".join(map(repr, sorted(extras))), verb, ", ".join(patterns)) |
There was a problem hiding this comment.
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.
|
OK, updated. |
|
Travis CI issue appears to be unrelated at this point. |
|
Bleh, yeah, OK, should have Travis CI fixed now, PyPy3 fun. Thanks though! Looks good, merging, appreciated. Now for a release... |
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
Fixes #316