{"action":"created","issue":{"url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/52","labels_url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/52/comments","events_url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/52/events","html_url":"https://github.com/atlantishealthcare/swagger-model-validator/issues/52","id":125726314,"number":52,"title":"custom validators and swagger 2.0","user":{"login":"mattoshry","id":1676525,"avatar_url":"https://avatars.githubusercontent.com/u/1676525?v=3","gravatar_id":"","url":"https://api.github.com/users/mattoshry","html_url":"https://github.com/mattoshry","followers_url":"https://api.github.com/users/mattoshry/followers","following_url":"https://api.github.com/users/mattoshry/following{/other_user}","gists_url":"https://api.github.com/users/mattoshry/gists{/gist_id}","starred_url":"https://api.github.com/users/mattoshry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattoshry/subscriptions","organizations_url":"https://api.github.com/users/mattoshry/orgs","repos_url":"https://api.github.com/users/mattoshry/repos","events_url":"https://api.github.com/users/mattoshry/events{/privacy}","received_events_url":"https://api.github.com/users/mattoshry/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-09T01:02:28Z","updated_at":"2016-01-10T22:09:02Z","closed_at":null,"body":"The fix [1] for issue 50 [2] to use the model name in place of model.id isn't working for me unless I hack my call to validator.addFieldValidator to use the magic name `rootModel` as dictated by [3]:\r\n\r\n```\r\nreturn validate('rootModel', target, swaggerModel, swaggerModels,...\r\n```\r\n\r\nMy code:\r\n```\r\n    var validator = new Validator();\r\n    validator.addFieldValidator('order', 'orderId', someCustomValidator);\r\n    validator.validate(orderPayload, swagger.definitions.order, null, false, true);\r\n```\r\n\r\nIt seems a little odd that the addFieldValidator method requires a model name supplied by the caller, but the validate method uses an internal magic token (rootModel) as the model name which is then used to find the custom validator.\r\n\r\nThis issue can be reproduced by removing the `id` from the sample model in testCustomValidationRun at [4]. The test will pass if `testModel` is replaced with `rootModel`, but no one would/should know to do that without digging into the implementation of this module.\r\n\r\n[1] https://github.com/atlantishealthcare/swagger-model-validator/commit/1b9d94d6a3db80639e30a38fea4df07c64dd1829\r\n[2] https://github.com/atlantishealthcare/swagger-model-validator/issues/50\r\n[3] https://github.com/atlantishealthcare/swagger-model-validator/blob/3d403f5bca4015e87f8a815f1037efa57588135f/lib/modelValidator.js#L44\r\n[4] https://github.com/atlantishealthcare/swagger-model-validator/blob/3d403f5bca4015e87f8a815f1037efa57588135f/tests/testAddingCustomValidators.js#L70\r\n[5] https://github.com/atlantishealthcare/swagger-model-validator/blob/3d403f5bca4015e87f8a815f1037efa57588135f/tests/testAddingCustomValidators.js#L83"},"comment":{"url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/comments/170398575","html_url":"https://github.com/atlantishealthcare/swagger-model-validator/issues/52#issuecomment-170398575","issue_url":"https://api.github.com/repos/atlantishealthcare/swagger-model-validator/issues/52","id":170398575,"user":{"login":"brodyd","id":2774160,"avatar_url":"https://avatars.githubusercontent.com/u/2774160?v=3","gravatar_id":"","url":"https://api.github.com/users/brodyd","html_url":"https://github.com/brodyd","followers_url":"https://api.github.com/users/brodyd/followers","following_url":"https://api.github.com/users/brodyd/following{/other_user}","gists_url":"https://api.github.com/users/brodyd/gists{/gist_id}","starred_url":"https://api.github.com/users/brodyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brodyd/subscriptions","organizations_url":"https://api.github.com/users/brodyd/orgs","repos_url":"https://api.github.com/users/brodyd/repos","events_url":"https://api.github.com/users/brodyd/events{/privacy}","received_events_url":"https://api.github.com/users/brodyd/received_events","type":"User","site_admin":false},"created_at":"2016-01-10T22:09:02Z","updated_at":"2016-01-10T22:09:02Z","body":"Thanks for your investigation.  "}}