{"action":"created","issue":{"url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/180","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/180/labels{/name}","comments_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/180/comments","events_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/180/events","html_url":"https://github.com/json-schema-org/json-schema-spec/issues/180","id":193576853,"number":180,"title":"Validation: if/then/else","user":{"login":"epoberezkin","id":2769109,"avatar_url":"https://avatars.githubusercontent.com/u/2769109?v=3","gravatar_id":"","url":"https://api.github.com/users/epoberezkin","html_url":"https://github.com/epoberezkin","followers_url":"https://api.github.com/users/epoberezkin/followers","following_url":"https://api.github.com/users/epoberezkin/following{/other_user}","gists_url":"https://api.github.com/users/epoberezkin/gists{/gist_id}","starred_url":"https://api.github.com/users/epoberezkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epoberezkin/subscriptions","organizations_url":"https://api.github.com/users/epoberezkin/orgs","repos_url":"https://api.github.com/users/epoberezkin/repos","events_url":"https://api.github.com/users/epoberezkin/events{/privacy}","received_events_url":"https://api.github.com/users/epoberezkin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/json-schema-org/json-schema-spec/milestones/3","html_url":"https://github.com/json-schema-org/json-schema-spec/milestone/3","labels_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/milestones/3/labels","id":2166252,"number":3,"title":"draft-future","description":"","creator":{"login":"awwright","id":437517,"avatar_url":"https://avatars.githubusercontent.com/u/437517?v=3","gravatar_id":"","url":"https://api.github.com/users/awwright","html_url":"https://github.com/awwright","followers_url":"https://api.github.com/users/awwright/followers","following_url":"https://api.github.com/users/awwright/following{/other_user}","gists_url":"https://api.github.com/users/awwright/gists{/gist_id}","starred_url":"https://api.github.com/users/awwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awwright/subscriptions","organizations_url":"https://api.github.com/users/awwright/orgs","repos_url":"https://api.github.com/users/awwright/repos","events_url":"https://api.github.com/users/awwright/events{/privacy}","received_events_url":"https://api.github.com/users/awwright/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":0,"state":"open","created_at":"2016-11-30T13:10:18Z","updated_at":"2016-12-07T09:45:59Z","due_on":null,"closed_at":null},"comments":22,"created_at":"2016-12-05T18:39:39Z","updated_at":"2016-12-11T19:58:45Z","closed_at":null,"body":"This can be seen as the extension of #31 and #64. I see it as the syntax sugar for existing boolean/compound keywords.\r\n\r\nThe validation process is very simple:\r\n- if the schema in `if` is valid, than the schema in `then` should be validated and its outcome determines the instance validation.\r\n- if the schema in `if` is invalid then the schema in `else` should be validated and its outcome determines the instance validation.\r\n- if `if` is not present then the schema itself is invalid (metaschema validation will fail).\r\n- if neither `then` nor `else` is present - the same as above\r\n\r\nAs I've written in some issue the schema with if/then/else: \r\n\r\n```json\r\n{\r\n  \"if\": {\"$ref\": \"condition\" },\r\n  \"then\": {\"$ref\": \"schema1\"},\r\n  \"else\": {\"$ref\": \"schema2\"}\r\n}\r\n```\r\n\r\nis a boolean operation and it is equivalent to the schema below that is possible now:\r\n\r\n```json\r\n{\r\n  \"anyOf\": [\r\n    { \"allOf\": [ {\"$ref\": \"condition\" }, {\"$ref\": \"schema1\"} ] },\r\n    { \"allOf\": [ {\"not\": {\"$ref\": \"condition\" } }, {\"$ref\": \"schema2\"} ] }\r\n  ]\r\n}\r\n```\r\n\r\nso if/then/else is as declarative as existing keywords but it provides a more convenient, clear and performance efficient alternative (\"condition\" will never be validated twice) for a quite common validation scenario.\r\n\r\nUsing if/then/else the problem in #31/#64 is also solved."},"comment":{"url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/comments/266303539","html_url":"https://github.com/json-schema-org/json-schema-spec/issues/180#issuecomment-266303539","issue_url":"https://api.github.com/repos/json-schema-org/json-schema-spec/issues/180","id":266303539,"user":{"login":"awwright","id":437517,"avatar_url":"https://avatars.githubusercontent.com/u/437517?v=3","gravatar_id":"","url":"https://api.github.com/users/awwright","html_url":"https://github.com/awwright","followers_url":"https://api.github.com/users/awwright/followers","following_url":"https://api.github.com/users/awwright/following{/other_user}","gists_url":"https://api.github.com/users/awwright/gists{/gist_id}","starred_url":"https://api.github.com/users/awwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awwright/subscriptions","organizations_url":"https://api.github.com/users/awwright/orgs","repos_url":"https://api.github.com/users/awwright/repos","events_url":"https://api.github.com/users/awwright/events{/privacy}","received_events_url":"https://api.github.com/users/awwright/received_events","type":"User","site_admin":false},"created_at":"2016-12-11T19:58:45Z","updated_at":"2016-12-11T19:58:45Z","body":"If we want to fit with the current convention of keywords, a \"conditional\" keyword would probably be the best bet:\r\n\r\n```javascript\r\n{\r\n\"conditional\":  {\r\n         \"if\": {},\r\n        \"then\": {},\r\n        \"else\": {}\r\n    }\r\n}\r\n```\r\n\r\nMaybe an array could provide \"switch\" like functionality, where only the _first_ match is picked:\r\n\r\n```javascript\r\n{\r\n\"conditional\":  [\r\n   {\r\n         \"if\": {},\r\n        \"then\": {}\r\n    }.\r\n   {\r\n         \"if\": {},\r\n        \"then\": {}\r\n    }\r\n]\r\n}\r\n```\r\n\r\nI also want to get an idea of how frequently this is actually necessary... how often would this actually simplify schemas and their output? Are there any use cases anyone is aware of?"}}
{"actor":{"display_login":"awwright"}}