{"action":"closed","issue":{"url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/34","repository_url":"https://api.github.com/repos/json-schema-org/json-schema-spec","labels_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/34/comments","events_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/34/events","html_url":"https://github.com/json-schema-org/json-schema-spec/issues/34","id":158364995,"number":34,"title":"allow more complex conditional branching for individual keys","user":{"login":"mbroadst","id":312966,"avatar_url":"https://avatars.githubusercontent.com/u/312966?v=3","gravatar_id":"","url":"https://api.github.com/users/mbroadst","html_url":"https://github.com/mbroadst","followers_url":"https://api.github.com/users/mbroadst/followers","following_url":"https://api.github.com/users/mbroadst/following{/other_user}","gists_url":"https://api.github.com/users/mbroadst/gists{/gist_id}","starred_url":"https://api.github.com/users/mbroadst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbroadst/subscriptions","organizations_url":"https://api.github.com/users/mbroadst/orgs","repos_url":"https://api.github.com/users/mbroadst/repos","events_url":"https://api.github.com/users/mbroadst/events{/privacy}","received_events_url":"https://api.github.com/users/mbroadst/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-06-03T13:16:57Z","updated_at":"2016-06-23T17:08:52Z","closed_at":"2016-06-23T17:08:51Z","body":"Sorry for the somewhat verbose title there, but this is a proposal to discuss addition of a feature similar to Joi's [when](https://github.com/hapijs/joi/blob/v9.0.0-2/API.md#anywhenref-options).\r\n\r\nJoi lets you do something like:\r\n\r\n```\r\n{\r\n  query: Joi.object({\r\n    type: Joi.string().required(),\r\n    value: Joi.string().max(255).when('type', {\r\n      is: 'optionalValue',\r\n      then: Joi.optional(),\r\n      otherwise: Joi.required()\r\n    })\r\n  });\r\n}\r\n```\r\n\r\nThis is a bit of a contrived (and simple) example, but I think it shows how easy the mental mapping is versus json-schema. json-schema supports the same functionality but very quickly becomes difficult to define, needing to mix and match `dependencies` and in the worst case having to specify duplicate schemas with a single key's definition changed and jamming them into an `anyOf` or `oneOf`. What's worse is that when you have to use the aforementioned `anyOf` approach you generally end up with resultant errors which are incredibly difficult to reason about, when all you really need is a single error that a given field doesn't match the criteria (not e.g. 3 errors: one indicating that the field was incorrect according to one schema, another indicating the error is incorrect in the other possible schema, and finally that neither of the schemas provided in `anyOf` were matched).\r\n\r\nIs there any room for discussion on adding these types of features to later versions of json-schema?\r\n\r\n"}}
{"actor":{"display_login":"mbroadst"}}