{"action":"created","issue":{"url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/96","labels_url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/96/comments","events_url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/96/events","html_url":"https://github.com/nicolaiarocci/cerberus/issues/96","id":79871493,"number":96,"title":"Proposal: allow explicit rules per type","user":{"login":"funkyfuture","id":2004405,"avatar_url":"https://avatars.githubusercontent.com/u/2004405?v=3","gravatar_id":"","url":"https://api.github.com/users/funkyfuture","html_url":"https://github.com/funkyfuture","followers_url":"https://api.github.com/users/funkyfuture/followers","following_url":"https://api.github.com/users/funkyfuture/following{/other_user}","gists_url":"https://api.github.com/users/funkyfuture/gists{/gist_id}","starred_url":"https://api.github.com/users/funkyfuture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/funkyfuture/subscriptions","organizations_url":"https://api.github.com/users/funkyfuture/orgs","repos_url":"https://api.github.com/users/funkyfuture/repos","events_url":"https://api.github.com/users/funkyfuture/events{/privacy}","received_events_url":"https://api.github.com/users/funkyfuture/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-23T15:11:25Z","updated_at":"2015-06-15T12:01:53Z","closed_at":null,"body":"atm it is possible to test a value to be one of multiple types, eg:\r\n\r\n    'some_field': {'type': ['a_type', 'b_type']}\r\n\r\nfor simple cases this is fine. however:\r\n\r\n- in case it's a `dict`, you can't test `schema` if `list` is also allowed\r\n- any other rule can only be same for each possible type\r\n- schema-definitions become more or less unclear:\r\n\r\n```\r\n{'a_field': {'type': ['dict', 'list', 'string'],\r\n             'schema': {'type': ['dict', 'string'],\r\n                        'regex': 'foo.*',\r\n                        'keyschema': {'type': 'string',\r\n                                      'regex': '.*'}},\r\n             'keyschema': {'type': 'string',\r\n                           'regex': '.*'},\r\n             'regex': 'foo.*'}}\r\n```\r\n\r\nso, i propose to extend and also allow this notation:\r\n```\r\n{'a_field': {'type': {'dict': {'keyschema': {'type': 'string', 'regex': '.*'}},\r\n                      'list': {'schema': {'type': {'dict': {'keyschema': {'type': 'string', 'regex': '.*'}},\r\n                                                   'string': {'regex': 'foo.*'}}}},\r\n                      'string': {'regex': 'foo.*'}}}}\r\n```\r\n\r\nso, allowed types can also be mappings whose value is a schema that will be validated against `value` if the key is recognized as valid type of `value`. thus (not in the example), rules could be very different depending on the actual type. it seems quiet easy to implement and shouldn't break anything.\r\n\r\nthough that idea came up while debugging as a more-or-less-workaround at first, i still find it's not a bad idea. imo, its sexyness is caused by its [explicit nature](https://www.python.org/dev/peps/pep-0020/). atm i don't need it, but that may change any moment."},"comment":{"url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/comments/112036845","html_url":"https://github.com/nicolaiarocci/cerberus/issues/96#issuecomment-112036845","issue_url":"https://api.github.com/repos/nicolaiarocci/cerberus/issues/96","id":112036845,"user":{"login":"CD3","id":693953,"avatar_url":"https://avatars.githubusercontent.com/u/693953?v=3","gravatar_id":"","url":"https://api.github.com/users/CD3","html_url":"https://github.com/CD3","followers_url":"https://api.github.com/users/CD3/followers","following_url":"https://api.github.com/users/CD3/following{/other_user}","gists_url":"https://api.github.com/users/CD3/gists{/gist_id}","starred_url":"https://api.github.com/users/CD3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CD3/subscriptions","organizations_url":"https://api.github.com/users/CD3/orgs","repos_url":"https://api.github.com/users/CD3/repos","events_url":"https://api.github.com/users/CD3/events{/privacy}","received_events_url":"https://api.github.com/users/CD3/received_events","type":"User","site_admin":false},"created_at":"2015-06-15T12:01:53Z","updated_at":"2015-06-15T12:01:53Z","body":"#112 comes close to this, you would just have to repeat the `type` keyword\r\n\r\n```\r\n{'a_field': {'anyof': {'type' : 'dict', 'keyschema': {'type': 'string', 'regex': '.*'}},\r\n                      {'type' : 'list', 'schema': {'type': {'dict': {'keyschema': {'type': 'string', 'regex': '.*'}},\r\n                                                   'string': {'regex': 'foo.*'}}}},\r\n                      {'type' : 'string', 'regex': 'foo.*'}}}}\r\n```"}}