Skip to content

Instantly share code, notes, and snippets.

@ekardon
Created October 3, 2023 23:32
Show Gist options
  • Save ekardon/406da7056a7e66b3f7a44e1b9f89125f to your computer and use it in GitHub Desktop.
Save ekardon/406da7056a7e66b3f7a44e1b9f89125f to your computer and use it in GitHub Desktop.
Json-schema array examples
{
"description": "First element of the array is integer type and the rest is string type. Array length is unknown",
"type": "array",
"items": [
{
"type": "integer"
}
],
"additionalItems": {
"type": "string"
}
}
{
"description": "Size 2 array. Second elements conditions are set based on first element of the array. {} means skip, and required",
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "integer",
"enum": [0, 1, 2, 3]
},
{}
],
"allOf": [
{
"description": "If array[0] = 0, then array[1] is only numbers string with min. length 1",
"if": {
"items": [
{"const": 0},
{}
]
},
"then": {
"items": [
{},
{
"pattern": "^[0-9]+$",
"type": "string"
}
]
}
},
{
"description": "If array[0] = 1, then array[1] is only uppercase letters with min. length 1",
"if": {
"items": [
{"const": 1},
{}
]
},
"then": {
"items": [
{},
{
"pattern": "^[A-Z]+$",
"type": "string"
}
]
}
},
{
"description": "If array[0] = 2, then array[1] is only lowercase letters with min. length 1",
"if": {
"items": [
{"const": 2},
{}
]
},
"then": {
"items": [
{},
{
"pattern": "^[a-z]+$",
"type": "string"
}
]
}
},
{
"description": "If array[0] = 3, then array[1] is boolean",
"if": {
"items": [
{"const": 3},
{}
]
},
"then": {
"items": [
{},
{
"type": "boolean"
}
]
}
}
],
"additionalProperties": false
}
{
"type": "integer",
"items": {
"oneOf": [
{"const": 0, "title": "ExpressionParameter"},
{"const": 1, "title": "StringExpressionParameter"},
{"const": 2, "title": "FileParameter"},
{"const": 3, "title": "ComboParameter"},
{"const": 4, "title": "ObjectParameter"},
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment