From 94e5239ee2fd6bf53f31457b9f8b997d87f4c94a Mon Sep 17 00:00:00 2001 From: Artem Berdyshev Date: Thu, 5 Jul 2018 23:39:27 +0300 Subject: [PATCH] define a json-schema for the layout structure proposed in the ticket --- src/schema.json | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/schema.json diff --git a/src/schema.json b/src/schema.json new file mode 100644 index 00000000..c2a6efff --- /dev/null +++ b/src/schema.json @@ -0,0 +1,133 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Dynamic form configuration for DeskPRO", + "description": "JSON Schema of the dynamic form definition with visibility rules, validation criteria, etc", + "type": "array", + "items": { + "type": "object", + "properties": { + "rules": { + "type": "array", + "items": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "op": { + "type": "string", + "enum": [ + "eq", "gt", "gte", "lt", "lte", "in", "contains" + ] + }, + "value": { + "type": ["string", "number", "boolean"] + } + }, + "required": ["field", "op", "value"] + } + }, + "fields": { + "type": "array", + "items": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "label": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "choice", "text", "password", "numeric", "date", "datetime", "checkbox", "radio", "file", "textarea", "multichoice" + ] + }, + "default_value": { + "type": ["string", "number", "object", "boolean"] + }, + "validation": { + "type": "array", + "items": { + "anyOf": [{ + "type": "string", + "enum": ["required", "nullable", "max", "min", "length"] + }, + { + "type": "object", + "properties": { + "name": { + "type": "string", + "const": "regex" + }, + "regex": { + "type": "string" + } + }, + "required": ["name", "regex"] + }, + { + "type": "object", + "properties": { + "name": { + "type": "string", + "const": "date_range" + }, + "from": { + "type": ["string", "number"] + }, + "to": { + "type": ["string", "number"] + } + }, + "required": [ + "name", "from", "to" + ] + } + ] + }, + "uniqueItems": true + } + }, + "required": [ + "field", "label", "type" + ], + "anyOf": [{ + "properties": { + "type": { + "enum": [ + "choice", "checkbox", "radio", "multichoice" + ] + }, + "choices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": ["string", "number"] + }, + "title": { + "type": "string" + } + }, + "required": ["id", "title"] + }, + "minItems": 1 + } + }, + "required": ["choices"] + }] + }, + "minItems": 1 + } + }, + "required": [ + "fields" + ] + } +} \ No newline at end of file