Skip to content

validate() doesn't handle required properly. #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sontek opened this issue Oct 17, 2013 · 1 comment
Closed

validate() doesn't handle required properly. #128

sontek opened this issue Oct 17, 2013 · 1 comment

Comments

@sontek
Copy link
Contributor

sontek commented Oct 17, 2013

(Pdb) p params
{u'bar': u'foo'}
(Pdb) p flat_schema
{'type': 'object', 'properties': {'foo': {'required': True, 'type': 'string', 'value': 'bar'}}}
(Pdb) validate(params, flat_schema)
*** SchemaError: True is not of type u'array'

Failed validating u'type' in schema[u'properties'][u'properties'][u'additionalProperties'][u'properties'][u'required']:
    {u'items': {u'type': u'string'},
     u'minItems': 1,
     u'type': u'array',
     u'uniqueItems': True}

On instance[u'properties']['foo'][u'required']:
    True
(Pdb) from jsonschema import Draft4Validator
(Pdb) Draft4Validator(flat_schema).validate(params)

You see, with validate it thinks it needs to validate required as an array. Then if I use Draft4Validator it doesn't check the required flag.

@Julian
Copy link
Member

Julian commented Oct 17, 2013

Hey.

In draft 4, required must be an array, and goes topside. You're probably looking at a draft 3 example (jsonschema supports draft 3 but draft 4 is the default when your schema doesn't specify a version).

So:

{
"type": "object",
"properties":{"foo":{"type":"string"}},
"required": ["foo"],
}

And the reason why making a validator does not complain is that validate checks if a schema is valid first while passing a schema to a validator does not.

@Julian Julian closed this as completed Oct 18, 2013
Julian added a commit that referenced this issue Apr 25, 2023
6afa9b38d Merge pull request #664 from santhosh-tekuri/empty-tokens
e4bceb1ad Bump the python-jsonschema version used for the sanity check.
8025fc0d5 Merge pull request #128 from iainbeeston/foundations-of-json-schema-paper
cf7677078 Make all root $ids absolute URIs
07fd389a3 Added test cases from Foundations of JSON Schema research paper
1008edcee ref: test empty tokens in json-pointer
9beb3cfba Merge pull request #627 from json-schema-org/ether/output-readme-fixes
f2b0490ba minor edit to trigger gh action
c305ce54f Merge pull request #669 from hauner/typo
5e2845c1e Merge pull request #668 from hauner/if-without-then-else-creates-annotations
2f1df2293 typo
c1fae0022 test unevaluated* can see annotations from if without then/else
987a4c8fc Merge pull request #666 from json-schema-org/gregsdennis/file-refs
90b2a58ce fix *nix uris
68d18c6ac rename tests to fix sanity check
e9166bcbe fix indentation
1d1ec749a add file-id ref tests
fb60ed17c Merge pull request #663 from json-schema-org/ether/restore-format-tests
f32cd8b80 Revert "Revert "by default, "format" only annotates, not validates""
47958f82d Merge pull request #654 from santhosh-tekuri/output-escape
5262997e1 Merge pull request #661 from santhosh-tekuri/2019-output
ce2c16573 output-tests: correct 2019 output-schema.json
c9d943856 output: ensure ~ and / are escaped in json-pointer
f6b2324bf minor spelling and markdown formatting fixes; `valid` has also been removed from the tests

git-subtree-dir: json
git-subtree-split: 6afa9b38d84d45550ec703123eb4e8ec67a8ae75
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

No branches or pull requests

2 participants