{"action":"created","issue":{"url":"https://api.github.com/repos/inveniosoftware/doschema/issues/2","repository_url":"https://api.github.com/repos/inveniosoftware/doschema","labels_url":"https://api.github.com/repos/inveniosoftware/doschema/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/inveniosoftware/doschema/issues/2/comments","events_url":"https://api.github.com/repos/inveniosoftware/doschema/issues/2/events","html_url":"https://github.com/inveniosoftware/doschema/issues/2","id":139237917,"number":2,"title":"global: Backward compatibility function","user":{"login":"nharraud","id":5708796,"avatar_url":"https://avatars.githubusercontent.com/u/5708796?v=3","gravatar_id":"","url":"https://api.github.com/users/nharraud","html_url":"https://github.com/nharraud","followers_url":"https://api.github.com/users/nharraud/followers","following_url":"https://api.github.com/users/nharraud/following{/other_user}","gists_url":"https://api.github.com/users/nharraud/gists{/gist_id}","starred_url":"https://api.github.com/users/nharraud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nharraud/subscriptions","organizations_url":"https://api.github.com/users/nharraud/orgs","repos_url":"https://api.github.com/users/nharraud/repos","events_url":"https://api.github.com/users/nharraud/events{/privacy}","received_events_url":"https://api.github.com/users/nharraud/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/inveniosoftware/doschema/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"Paulina1","id":1929323,"avatar_url":"https://avatars.githubusercontent.com/u/1929323?v=3","gravatar_id":"","url":"https://api.github.com/users/Paulina1","html_url":"https://github.com/Paulina1","followers_url":"https://api.github.com/users/Paulina1/followers","following_url":"https://api.github.com/users/Paulina1/following{/other_user}","gists_url":"https://api.github.com/users/Paulina1/gists{/gist_id}","starred_url":"https://api.github.com/users/Paulina1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paulina1/subscriptions","organizations_url":"https://api.github.com/users/Paulina1/orgs","repos_url":"https://api.github.com/users/Paulina1/repos","events_url":"https://api.github.com/users/Paulina1/events{/privacy}","received_events_url":"https://api.github.com/users/Paulina1/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/inveniosoftware/doschema/milestones/1","html_url":"https://github.com/inveniosoftware/doschema/milestones/v0.1.0","labels_url":"https://api.github.com/repos/inveniosoftware/doschema/milestones/1/labels","id":1628488,"number":1,"title":"v0.1.0","description":null,"creator":{"login":"jirikuncar","id":189798,"avatar_url":"https://avatars.githubusercontent.com/u/189798?v=3","gravatar_id":"","url":"https://api.github.com/users/jirikuncar","html_url":"https://github.com/jirikuncar","followers_url":"https://api.github.com/users/jirikuncar/followers","following_url":"https://api.github.com/users/jirikuncar/following{/other_user}","gists_url":"https://api.github.com/users/jirikuncar/gists{/gist_id}","starred_url":"https://api.github.com/users/jirikuncar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jirikuncar/subscriptions","organizations_url":"https://api.github.com/users/jirikuncar/orgs","repos_url":"https://api.github.com/users/jirikuncar/repos","events_url":"https://api.github.com/users/jirikuncar/events{/privacy}","received_events_url":"https://api.github.com/users/jirikuncar/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":1,"state":"open","created_at":"2016-03-08T10:12:59Z","updated_at":"2016-03-08T13:20:23Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-03-08T10:27:02Z","updated_at":"2016-03-08T15:21:29Z","closed_at":null,"body":"Problem Definition\r\n==============\r\n**Use case**: From B2Share. Communities can have record submitted to them. Records are validated with the Community's JSON Schema. This JSON Schema can change, every modification create a new version.\r\n\r\n**Problem**: We want to make sure that searching records by field names is consistent and that all blocks of metadata having the same schema can be analyzed the same way (fields type is the same).\r\n\r\n**Solution**: We can develop a function which makes sure that the new JSON schema version is **backward compatible** with the previous schemas.\r\n\r\n**Who needs it**: B2Share\r\n\r\nDesign notes:\r\n==========\r\n\r\n**For B2Share** a schema is **backward compatible** if:\r\n- The fields' type remain the same in all JSON schemas declaring it.\r\n- JSON Schemas are **type consistent** within themselves too, i.e. A JSON Schema cannot validate two fields with different types which would be referenced with the same JSON pointer.\r\n\r\n**The definition of \"backward compatible\" can vary for other users**. Thus we should have either different functions checking the possible constraints (ex: fields cannot be removed, fields have to be type consistent, etc...) or one function with parameters to enable specific checks.\r\n\r\nJSON Schema allows to specify a different type/structure for different indexes of an array. However **there should be an option to ignore array indices** as some tools like Elasticsearch can specify only one mapping for all array values (see Example 3).\r\n\r\n**Function Prototype:**\r\n- *Arguments*:\r\n - a list of JSON Schemas ordered from first version to last.\r\n - an optional argument to ignore array indexes (see Example 3).\r\n- *Exceptions*: The function raises an exception when a contraint is violated. It should always say which JSON Schemas in the list conflict and on which field(s).\r\n- *Returns*: (optional) an incremental state which can be used to validate faster the next JSON Schema versions. This state would be given as an optional argument.\r\n\r\nExamples:\r\n========\r\n\r\n**Example 1: Type consistency example:**\r\nThe following schema **is not type consistent** because it would accept \"field_A\" to be either a \"string\" or an \"integer\".\r\n\r\n```json\r\n{\r\n   \"type\": \"object\",\r\n   \"oneOf\": [{\r\n       \"type\": \"object\", \r\n       \"properties\": {\r\n           \"field_A\": { \"type\": \"string\" }\r\n       }\r\n   }, {\r\n       \"type\": \"object\", \r\n       \"properties\": {\r\n           \"field_A\": { \"type\": \"integer\" }\r\n       }\r\n   }]\r\n}\r\n```\r\n\r\n**Example 2: Backward type compatibility example:***\r\nIn the following example, `Version 3` is not backward type compatible because it redefines `field_A` which was defined in `Version 1` with a different type.\r\nHowever `Version 1` and `Version  2` are type compatible because it is allowed to add/remove fields and change the `required` fields.\r\n\r\n*Version 1*\r\n```json\r\n{\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"field_A\": { \"type\": \"string\" }\r\n    },\r\n    \"required\": [\"field_A\"]\r\n}\r\n```\r\n\r\n*Version 2*\r\n```json\r\n{\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"field_B\": { \"type\": \"string\" }\r\n    },\r\n    \"required\": [\"field_B\"]\r\n}\r\n```\r\n\r\n*Version 3*\r\n```json\r\n{\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"field_B\": { \"type\": \"string\" },\r\n        \"field_A\": { \"type\": \"number\" }\r\n    },\r\n    \"required\": [\"field_B\"]\r\n}\r\n```\r\n\r\n**Example 3: Ignore array index**:\r\nFields can conflict only if they can be referenced with the same **JSON pointer in the validated JSON**.\r\nJSON Schema allows to specify a different type/structure for different indexes of an array. However there should be an option to ignore array indexes because some tools like Elasticsearch can specify only one mapping for all array values.\r\n\r\nIn the following JSON Schema the two `field_A` should have different JSON pointers, respectively `experiment_info[\"0\"].field_A` and `experiment_info[\"1\"].field_A`. If we enable the ignoring of array indices however, they should both be considered as `experiment_info[*].field_A` and conflict.\r\n```json\r\n{\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"experiment_info\": {\r\n            \"type\": \"array\",\r\n            \"items\": [\r\n                {\r\n                    \"type\": \"object\",\r\n                    \"properties\": {\r\n                        \"field_A\": { \"type\": \"string\" }\r\n                    }\r\n                },\r\n                {\r\n                    \"type\": \"object\",\r\n                    \"properties\": {\r\n                        \"field_A\": { \"type\": \"number\" }\r\n                    }\r\n                }\r\n            ]\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nIn the following JSON Schema however, the two fields will always conflict as the JSON Schema does not specify the indices.\r\n```json\r\n{\r\n    \"anyOf\": [\r\n        {\r\n            \"type\": \"object\",\r\n            \"properties\": {\r\n                \"experiment_info\": {\r\n                    \"type\": \"array\",\r\n                    \"items\": {\r\n                        \"type\": \"object\",\r\n                        \"properties\": {\r\n                            \"field_A\": { \"type\": \"string\" }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        },\r\n        {\r\n            \"type\": \"object\",\r\n            \"properties\": {\r\n                \"experiment_info\": {\r\n                    \"type\": \"array\",\r\n                    \"items\": {\r\n                        \"type\": \"object\",\r\n                        \"properties\": {\r\n                            \"field_A\": { \"type\": \"integer\" }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    ]\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/inveniosoftware/doschema/issues/comments/193822026","html_url":"https://github.com/inveniosoftware/doschema/issues/2#issuecomment-193822026","issue_url":"https://api.github.com/repos/inveniosoftware/doschema/issues/2","id":193822026,"user":{"login":"nharraud","id":5708796,"avatar_url":"https://avatars.githubusercontent.com/u/5708796?v=3","gravatar_id":"","url":"https://api.github.com/users/nharraud","html_url":"https://github.com/nharraud","followers_url":"https://api.github.com/users/nharraud/followers","following_url":"https://api.github.com/users/nharraud/following{/other_user}","gists_url":"https://api.github.com/users/nharraud/gists{/gist_id}","starred_url":"https://api.github.com/users/nharraud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nharraud/subscriptions","organizations_url":"https://api.github.com/users/nharraud/orgs","repos_url":"https://api.github.com/users/nharraud/repos","events_url":"https://api.github.com/users/nharraud/events{/privacy}","received_events_url":"https://api.github.com/users/nharraud/received_events","type":"User","site_admin":false},"created_at":"2016-03-08T15:21:29Z","updated_at":"2016-03-08T15:21:29Z","body":"@JavierDelgadoFernandez This might interest you."}}