inveniosoftware / doschema Goto Github PK
View Code? Open in Web Editor NEWUtilities to work with JSON Schemas.
Home Page: https://doschema.readthedocs.io
License: GNU General Public License v2.0
Utilities to work with JSON Schemas.
Home Page: https://doschema.readthedocs.io
License: GNU General Public License v2.0
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.
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).
Solution: We can develop a function which makes sure that the new JSON schema version is backward compatible with the previous schemas.
Who needs it: B2Share
For B2Share a schema is backward compatible if:
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.
JSON 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).
Function Prototype:
Example 1: Type consistency example:
The following schema is not type consistent because it would accept "field_A" to be either a "string" or an "integer".
{
"type": "object",
"oneOf": [{
"type": "object",
"properties": {
"field_A": { "type": "string" }
}
}, {
"type": "object",
"properties": {
"field_A": { "type": "integer" }
}
}]
}
Example 2: Backward type compatibility example:*
In 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.
However Version 1
and Version 2
are type compatible because it is allowed to add/remove fields and change the required
fields.
Version 1
{
"type": "object",
"properties": {
"field_A": { "type": "string" }
},
"required": ["field_A"]
}
Version 2
{
"type": "object",
"properties": {
"field_B": { "type": "string" }
},
"required": ["field_B"]
}
Version 3
{
"type": "object",
"properties": {
"field_B": { "type": "string" },
"field_A": { "type": "number" }
},
"required": ["field_B"]
}
Example 3: Ignore array index:
Fields can conflict only if they can be referenced with the same JSON pointer in the validated JSON.
JSON 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.
In 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.
{
"type": "object",
"properties": {
"experiment_info": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"field_A": { "type": "string" }
}
},
{
"type": "object",
"properties": {
"field_A": { "type": "number" }
}
}
]
}
}
}
In the following JSON Schema however, the two fields will always conflict as the JSON Schema does not specify the indices.
{
"anyOf": [
{
"type": "object",
"properties": {
"experiment_info": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field_A": { "type": "string" }
}
}
}
}
},
{
"type": "object",
"properties": {
"experiment_info": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field_A": { "type": "integer" }
}
}
}
}
}
]
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.