{"action":"created","issue":{"url":"https://api.github.com/repos/Julian/jsonschema/issues/250","labels_url":"https://api.github.com/repos/Julian/jsonschema/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/Julian/jsonschema/issues/250/comments","events_url":"https://api.github.com/repos/Julian/jsonschema/issues/250/events","html_url":"https://github.com/Julian/jsonschema/issues/250","id":111805314,"number":250,"title":"Unable to validate a schema where a default value is a required value","user":{"login":"darrenkenny","id":209306,"avatar_url":"https://avatars.githubusercontent.com/u/209306?v=3","gravatar_id":"","url":"https://api.github.com/users/darrenkenny","html_url":"https://github.com/darrenkenny","followers_url":"https://api.github.com/users/darrenkenny/followers","following_url":"https://api.github.com/users/darrenkenny/following{/other_user}","gists_url":"https://api.github.com/users/darrenkenny/gists{/gist_id}","starred_url":"https://api.github.com/users/darrenkenny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darrenkenny/subscriptions","organizations_url":"https://api.github.com/users/darrenkenny/orgs","repos_url":"https://api.github.com/users/darrenkenny/repos","events_url":"https://api.github.com/users/darrenkenny/events{/privacy}","received_events_url":"https://api.github.com/users/darrenkenny/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-16T10:36:00Z","updated_at":"2015-10-16T15:35:46Z","closed_at":null,"body":"I have a schema where it has a required value, that also has a default value. \r\n\r\nI followed the example in the documentation for adding a default value mechanism, but\r\nthat is insufficient, in that the \"required\" validator always seems to end up being\r\ncalled prior to the \"properties\" validator - so the defaulted value still appears to\r\nbe missing.\r\n\r\nI know that this is unusual, but it's a valid use-case.\r\n\r\nI've been able to work around it by some manipulation of the validators, along the\r\nlines of the mechanism for setting the default, and ensuring the correct order\r\nwhen calling the validators.\r\n\r\nBut, I believe this could be simply solved by replacing the dictionary of validators\r\nby an ordered dictionary that allowed the processing of the properties prior\r\nto the validation of the required list.\r\n\r\nSimply logging the list of validators, by iterating over them in the same way\r\nas the validator.py code does, I get the following output for a V4 schema:\r\n\r\n```\r\nrequired\r\nminProperties\r\nformat\r\nminLength\r\nenum\r\nadditionalItems\r\nmaximum\r\nnot\r\nminimum\r\nmaxItems\r\nmaxLength\r\nuniqueItems\r\nanyOf\r\nproperties\r\n$ref\r\noneOf\r\nminItems\r\npattern\r\nallOf\r\npatternProperties\r\nmultipleOf\r\ndependencies\r\nmaxProperties\r\nitems\r\nadditionalProperties\r\ntype\r\n```\r\n\r\nI'm not sure how this order is arrived at (guessing based on the dictionary key hash values), but\r\nit doesn't work for this use-case."},"comment":{"url":"https://api.github.com/repos/Julian/jsonschema/issues/comments/148748686","html_url":"https://github.com/Julian/jsonschema/issues/250#issuecomment-148748686","issue_url":"https://api.github.com/repos/Julian/jsonschema/issues/250","id":148748686,"user":{"login":"darrenkenny","id":209306,"avatar_url":"https://avatars.githubusercontent.com/u/209306?v=3","gravatar_id":"","url":"https://api.github.com/users/darrenkenny","html_url":"https://github.com/darrenkenny","followers_url":"https://api.github.com/users/darrenkenny/followers","following_url":"https://api.github.com/users/darrenkenny/following{/other_user}","gists_url":"https://api.github.com/users/darrenkenny/gists{/gist_id}","starred_url":"https://api.github.com/users/darrenkenny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darrenkenny/subscriptions","organizations_url":"https://api.github.com/users/darrenkenny/orgs","repos_url":"https://api.github.com/users/darrenkenny/repos","events_url":"https://api.github.com/users/darrenkenny/events{/privacy}","received_events_url":"https://api.github.com/users/darrenkenny/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T15:35:46Z","updated_at":"2015-10-16T15:35:46Z","body":"That's very true - but, just like jsonschema, not all validators will fill in the defaults, so the required field is needed for these validators.\r\n\r\nBeing able to express that a value is required is useful then to enforce that something is specified in a system where that is the case - especially in mixed systems.\r\n\r\nOn the other hand, being able to default is also useful to consumers of implementations that do support defaulting.\r\n\r\nI believe this is a valid case - but maybe I'm being just pedantic about it.\r\n\r\nI've been digging further and it actually appears to be the lines:\r\n\r\n```python\r\n# From validators.py\r\nif ref is not None:\r\n    validators = [(\"$ref\", ref)]\r\nelse:\r\n    validators = iteritems(_schema)\r\n\r\nfor k, v in validators:\r\n    validator = self.VALIDATORS.get(k)\r\n```\r\n\r\nThat are the cause, not the order of the VALIDATORS dictionary.\r\n\r\nIt's this iteration that causes the required to be processed before properties for me.\r\n\r\n"}}