{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/query.schema.json",
"title": "QueryParams",
"type": "object",
"required": ["page", "page_size"],
"properties": {
"filter": {
"$ref": "#/$defs/filterExpr"
},
"group_by": {
"type": "array",
"items": { "type": "string" }
},
"having": {
"$ref": "#/$defs/filterExpr"
},
"sort": {
"type": "array",
"items": { "$ref": "#/$defs/sortItem" }
},
"page": {
"type": "integer",
"minimum": 0
},
"page_size": {
"type": "integer",
"minimum": 1,
"maximum": 200
}
},
"$defs": {
"filterExpr": {
"oneOf": [
{
"type": "object",
"required": ["and"],
"properties": {
"and": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/filterExpr" }
}
},
"additionalProperties": false
},
{
"type": "object",
"required": ["or"],
"properties": {
"or": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/filterExpr" }
}
},
"additionalProperties": false
},
{
"$ref": "#/$defs/filterCond"
}
]
},
"filterCond": {
"type": "object",
"required": ["op"],
"properties": {
"field": {
"type": "string",
"description": "SQL column with alias, e.g. u.name"
},
"op": {
"type": "string",
"enum": [
"eq",
"ne",
"like",
"gt",
"lt",
"gte",
"lte",
"in",
"not_in",
"between",
"find_in_set",
"json_contains",
"is_null",
"is_not_null",
"exists",
"not_exists"
]
},
"value": {}
},
"allOf": [
{
"if": {
"properties": { "op": { "enum": ["is_null", "is_not_null"] } }
},
"then": {
"not": { "required": ["value"] }
}
},
{
"if": {
"properties": { "op": { "enum": ["in", "not_in", "between"] } }
},
"then": {
"required": ["value"],
"properties": {
"value": {
"type": "array",
"minItems": 1
}
}
}
},
{
"if": {
"properties": { "op": { "enum": ["exists", "not_exists"] } }
},
"then": {
"required": ["value"],
"properties": {
"value": {
"type": "object",
"required": ["sql"],
"properties": {
"sql": {
"type": "string",
"description": "EXISTS subquery SQL, controlled by backend"
},
"bind": {
"type": "array",
"items": {}
}
},
"additionalProperties": false
}
}
}
}
],
"additionalProperties": false
},
"sortItem": {
"type": "object",
"required": ["field"],
"properties": {
"field": {
"type": "string"
},
"desc": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}