Skip to content

Instantly share code, notes, and snippets.

@luan-cestari
Last active August 29, 2015 14:02
Show Gist options
  • Save luan-cestari/5a1d5a360b93cb4f38d2 to your computer and use it in GitHub Desktop.
Save luan-cestari/5a1d5a360b93cb4f38d2 to your computer and use it in GitHub Desktop.
JSon Schema for validation / proof of concept
{
"copyright": [
"Copyright 2013 Red Hat, Inc. and/or its affiliates.",
"This file is part of lightblue.",
"This program is free software: you can redistribute it and/or modify",
"it under the terms of the GNU General Public License as published by",
"the Free Software Foundation, either version 3 of the License, or",
"(at your option) any later version.",
"This program is distributed in the hope that it will be useful,",
"but WITHOUT ANY WARRANTY; without even the implied warranty of",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"GNU General Public License for more details.",
"You should have received a copy of the GNU General Public License",
"along with this program. If not, see <http://www.gnu.org/licenses/>."
],
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "dml",
"properties": {
"delete": {
"$ref": "#/properties/insert",
"id": "delete"
},
"fetch": {
"$ref": "#/properties/insert",
"id": "fetch"
},
"insert": {
"type": "object",
"id": "insert",
"properties": {
"bindings": {
"type": "object",
"properties": {
"in": {
"type": "array",
"items": {
"type": "object",
"properties": {
"column": {
"type": "string"
},
"path": {
"type": "string"
}
}
}
},
"out": {
"$ref": "#/properties/insert/bindings/in"
}
}
},
"expressions": {
"type": "array",
"minItems": 1,
"items": {
"oneOf": [{
"type": "object",
"id": "statement",
"properties": {
"datasource": {
"type": "string",
"id": "datasource"
},
"sql": {
"type": "string",
"id": "sql"
},
"type": {
"id": "type",
"enum": ["select", "insert", "update", "delete", "call"]
}
}
}, {
"type": "object",
"properties": {
"if": {
"type": "object",
"properties": {
"oneOf": [
"$or": {
"description": "This piece of schema will be in conditional.json to avoid duplication",
"type": "array",
"minItems": 2,
"items": {
"anyOf": [{
"$ref": "conditional.json#/properties/oneOf/$or"
}, {
"$ref": "conditional.json#/properties/oneOf/$any"
}, {
"$ref": "conditional.json#/properties/oneOf/$and"
}, {
"$ref": "conditional.json#/properties/oneOf/$all"
}, {
"$ref": "conditional.json#/properties/oneOf/$not"
}, {
"description": "This schema will be in path-empty.json",
"type": "object",
"properties": {
"conditional": {
"enum": ["$isempty"]
},
"path1": {
"type": "string"
}
}
}, {
"description": "This schema will be in path-check-path.json",
"type": "object",
"properties": {
"conditional": {
"enum": ["$greaterThan", "$lessThan", "$equalTo", "$notEqualTo", "$greaterThanOrEqualTo", "$lessThanOrEqualTo", "$in", "$notIn", "$contains"]
},
"path1": {
"type": "string"
},
"path2": {
"type": "string"
}
}
}, {
"description": "This schema will be in path-check-value.json",
"type": "object",
"properties": {
"conditional": {
"enum": ["$greaterThan", "$lessThan", "$equalTo", "$notEqualTo", "$greaterThanOrEqualTo", "$lessThanOrEqualTo", "$in", "$notIn", "$contains"]
},
"path1": {
"type": "string"
},
"value2": {
"type": "string"
}
}
}, {
"description": "This schema will be in path-check-values.json",
"type": "object",
"properties": {
"conditional": {
"enum": ["$greaterThan", "$lessThan", "$equalTo", "$notEqualTo", "$greaterThanOrEqualTo", "$lessThanOrEqualTo", "$in", "$notIn", "$contains"]
},
"path1": {
"type": "string"
},
"values2": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
},
"uniqueItems": true
}
}
}, {
"description": "This schema will be in path-regex.json",
"type": "object",
"properties": {
"path": {
"type": "string"
},
"regex": {
"type": "string",
"format": "regex"
},
"case_insensitive": {
"type": "boolean"
},
"multiline": {
"type": "boolean"
},
"extended": {
"type": "boolean"
},
"dotall": {
"type": "boolean"
}
}
}]
}
}, {
"$ref": "conditional.json#/properties/oneOf/$any"
}, {
"$ref": "conditional.json#/properties/oneOf/$and"
}, {
"$ref": "conditional.json#/properties/oneOf/$all"
}, {
"$ref": "conditional.json#/properties/oneOf/$not"
}, {
"$ref": "path-empty.json#/"
}, {
"$ref": "path-check-path.json#"
}, {
"$ref": "path-check-value.json#"
}, {
"$ref": "path-check-values.json#"
}, {
"$ref": "path-regex.json#"
}
]
}
},
"then": {
"oneOf": [{
"$ref": "construct.json#expressions"
}, {
"enum": ["$fail", "$continue", "$break"]
}]
},
"elseIf": {
"type": "array",
"items": {
"allOf": [{
"$ref": "#properties/if"
}, {
"$ref": "#properties/then"
}]
}
},
"else": {
"oneOf": [{
"$ref": "construct.json#expressions"
}, {
"enum": ["$fail", "$continue", "$break"]
}]
}
}
}, {
"type": "object",
"properties": {
"$foreach": {
"properties": {
"iterateOverPath": {
"type": "string"
},
"expressions": {
"$ref": "construct.json#expressions"
}
}
}
}
}, {
"type": "object",
"properties": {
"$foreach": {
"properties": {
"loopTimes": {
"type": "number"
},
"loopVariable": {
"type": "string"
},
"expressions": {
"$ref": "construct.json#expressions"
}
}
}
}
}]
}
}
}
},
"save": {
"$ref": "#/properties/insert"
},
"update": {
"$ref": "#/properties/insert"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment