{"action":"created","issue":{"url":"https://api.github.com/repos/zaggino/z-schema/issues/114","labels_url":"https://api.github.com/repos/zaggino/z-schema/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/zaggino/z-schema/issues/114/comments","events_url":"https://api.github.com/repos/zaggino/z-schema/issues/114/events","html_url":"https://github.com/zaggino/z-schema/issues/114","id":86620182,"number":114,"title":"Support for custom validators.","user":{"login":"IvanGoncharov","id":8336157,"avatar_url":"https://avatars.githubusercontent.com/u/8336157?v=3","gravatar_id":"","url":"https://api.github.com/users/IvanGoncharov","html_url":"https://github.com/IvanGoncharov","followers_url":"https://api.github.com/users/IvanGoncharov/followers","following_url":"https://api.github.com/users/IvanGoncharov/following{/other_user}","gists_url":"https://api.github.com/users/IvanGoncharov/gists{/gist_id}","starred_url":"https://api.github.com/users/IvanGoncharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IvanGoncharov/subscriptions","organizations_url":"https://api.github.com/users/IvanGoncharov/orgs","repos_url":"https://api.github.com/users/IvanGoncharov/repos","events_url":"https://api.github.com/users/IvanGoncharov/events{/privacy}","received_events_url":"https://api.github.com/users/IvanGoncharov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zaggino/z-schema/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/zaggino/z-schema/labels/PR%20welcome","name":"PR welcome","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-06-09T14:34:15Z","updated_at":"2015-09-02T06:36:52Z","closed_at":null,"body":"For many use cases JSON Schema isn't enough to check all restrictions.\r\nSo right now, typical scenario is validate using JSON schema validator and them use hand-write recursive code.\r\n\r\n Consider following schema:\r\n```json\r\n{\r\n   \"definitions\": {\r\n       \"TestType\": {\r\n          \"type\": \"string\",\r\n          \"description\": \"Type that should be additionally validated\"\r\n       }\r\n   },\r\n   \"oneOf\" : [\r\n      { \"$ref\": \"#/definitions/TestType\" },\r\n      {\r\n        \"type\": \"array\",\r\n        \"items\": { \"$ref\": \"#/definitions/TestType\" }\r\n      }\r\n   ]\r\n}\r\n```\r\nSo JS validation code would be, like that:\r\n```javascript\r\nfunction validate(data) {\r\n  if (data.constructor === Array) {\r\n    for (var i = 0; i < data.lenght; i++)\r\n       validateTestType(data);\r\n    return;\r\n  }\r\n  validateTestType(data);\r\n}\r\n\r\nfunction validateTestType(data) {\r\n  //user specific validation\r\n}\r\n```\r\nIn real life hand-written validator quickly mirror most of JSON Schema.\r\nIt especially hard to work with 'oneOf', 'allOf', etc.\r\nMy idea is to allow user to specify additional validators for JSON Schema types.\r\nSyntax could be like following:\r\n```javascript\r\nvar valid = validator.validate(json, schema, {\r\n  \"#/definitions/TestType\": function (report, json) {\r\n     //user specific validation\r\n  }\r\n});\r\n```\r\nIt not only simplify code but also significantly improve speed of full validation.\r\nIn next couple of days I could prepare PR.\r\nWhat do you think about such functionality?"},"comment":{"url":"https://api.github.com/repos/zaggino/z-schema/issues/comments/136951494","html_url":"https://github.com/zaggino/z-schema/issues/114#issuecomment-136951494","issue_url":"https://api.github.com/repos/zaggino/z-schema/issues/114","id":136951494,"user":{"login":"IvanGoncharov","id":8336157,"avatar_url":"https://avatars.githubusercontent.com/u/8336157?v=3","gravatar_id":"","url":"https://api.github.com/users/IvanGoncharov","html_url":"https://github.com/IvanGoncharov","followers_url":"https://api.github.com/users/IvanGoncharov/followers","following_url":"https://api.github.com/users/IvanGoncharov/following{/other_user}","gists_url":"https://api.github.com/users/IvanGoncharov/gists{/gist_id}","starred_url":"https://api.github.com/users/IvanGoncharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IvanGoncharov/subscriptions","organizations_url":"https://api.github.com/users/IvanGoncharov/orgs","repos_url":"https://api.github.com/users/IvanGoncharov/repos","events_url":"https://api.github.com/users/IvanGoncharov/events{/privacy}","received_events_url":"https://api.github.com/users/IvanGoncharov/received_events","type":"User","site_admin":false},"created_at":"2015-09-02T06:36:52Z","updated_at":"2015-09-02T06:36:52Z","body":"I really want to implement this feature, but right now I stuck with my current work :disappointed: \r\nI would try to find some time in next couple of months, but it would great if someone create PR before that."}}