updated schema for contentbuilder and refactored code
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sebastian Frank 2022-11-18 18:59:36 +00:00
parent dcfde495c7
commit 14da32bac6
Signed by: apairon
GPG Key ID: 9A9F8F10A937E426
7 changed files with 521 additions and 235 deletions

View File

@ -3,3 +3,4 @@ type: string
meta:
label:
de: test
widget: "text"

View File

@ -23,3 +23,30 @@ hooks:
file: hooks/mycol/get_return.js
x-additional: test
fields:
- name: testfield
type: string
meta:
label:
de: test
en: test
widget: "text"
- name: testfield2
type: string
meta:
label:
de: test2
en: test2
widget: "contentbuilder"
baseHref: /mycol
- name: testfield3
type: string
meta:
label:
de: test3
en: test3
widget: "select"
choices: []

View File

@ -33,7 +33,7 @@
"properties": {
"rowIdentTpl": {
"description": "template which evaluates to short string to identify entry in pe. select boxes",
"$ref": "field.json#/definitions/evalExpressions"
"$ref": "definitions.json#/definitions/evalExpressions"
},
"subNavigation": {
"oneOf": [

View File

@ -9,14 +9,18 @@
"description": "template property"
}
},
"required": ["label"],
"required": [],
"properties": {
"name": {
"type": "string",
"description": "name of navigation"
},
"label": {
"$ref": "field.json#/definitions/i18nString"
"$ref": "definitions.json#/definitions/i18nString"
},
"defaultImageFilter": {
"type": "string",
"description": "image filter name used for image previews"
},
"muiIcon": {
"type": "string",
@ -28,7 +32,7 @@
"additionalProperties": false,
"properties": {
"field": {
"$ref": "field.json#/definitions/fieldSource"
"$ref": "definitions.json#/definitions/fieldSource"
},
"order": {
"description": "sort order",
@ -36,6 +40,25 @@
}
}
},
"defaultCallback": {
"description": "default action on entry, defaults to edit - can be one of: edit, view, Object with js eval",
"oneOf": [
{
"type": "string",
"enum": ["edit", "view"]
},
{
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "js eval string of (entry) => {}"
}
},
"additionalProperties": false
}
]
},
"filter": {
"type": "object",
"description": "filter for prefiltering collection view"
@ -60,30 +83,30 @@
"primaryText": {
"oneOf": [
{
"$ref": "field.json#/definitions/fieldSource"
"$ref": "definitions.json#/definitions/fieldSource"
},
{
"$ref": "field.json#/definitions/evalExpressions"
"$ref": "definitions.json#/definitions/evalExpressions"
}
]
},
"secondaryText": {
"oneOf": [
{
"$ref": "field.json#/definitions/fieldSource"
"$ref": "definitions.json#/definitions/fieldSource"
},
{
"$ref": "field.json#/definitions/evalExpressions"
"$ref": "definitions.json#/definitions/evalExpressions"
}
]
},
"tertiaryText": {
"oneOf": [
{
"$ref": "field.json#/definitions/fieldSource"
"$ref": "definitions.json#/definitions/fieldSource"
},
{
"$ref": "field.json#/definitions/evalExpressions"
"$ref": "definitions.json#/definitions/evalExpressions"
}
]
}
@ -102,13 +125,13 @@
{
"anyOf": [
{
"$ref": "field.json#/definitions/fieldSource"
"$ref": "definitions.json#/definitions/fieldSource"
},
{
"type": "object",
"properties": {
"label": {
"$ref": "field.json#/definitions/i18nString"
"$ref": "definitions.json#/definitions/i18nString"
}
}
}
@ -117,12 +140,12 @@
{
"allOf": [
{
"$ref": "field.json#/definitions/evalExpressions"
"$ref": "definitions.json#/definitions/evalExpressions"
},
{
"properties": {
"label": {
"$ref": "field.json#/definitions/i18nString"
"$ref": "definitions.json#/definitions/i18nString"
}
}
}

View File

@ -0,0 +1,84 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"evalObject": {
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "js code which must return same schema as value if directly defined"
}
}
},
"i18nString": {
"oneOf": [
{
"type": "object",
"patternProperties": {
"^[a-z]$": {
"type": "string"
}
}
},
{
"type": "string"
}
]
},
"evalExpressions": {
"oneOf": [
{
"type": "object",
"additionalProperties": true,
"properties": {
"twig": {
"type": "string",
"description": "twig template"
},
"projection": {
"type": "string",
"description": "query projection to use"
}
},
"required": ["twig"]
},
{
"type": "object",
"additionalProperties": true,
"properties": {
"eval": {
"type": "string",
"description": "javascript code"
},
"projection": {
"type": "string",
"description": "query projection to use"
}
},
"required": ["eval"]
}
]
},
"fieldSource": {
"oneOf": [
{
"$ref": "#/definitions/fieldPath"
},
{
"type": "object",
"properties": {
"source": {
"$ref": "#/definitions/fieldPath"
}
}
}
]
},
"fieldPath": {
"type": "string",
"description": "field, sub fields separated with dot (.)",
"pattern": "^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*$"
}
}
}

View File

@ -78,227 +78,8 @@
}
},
"meta": {
"type": "object",
"description": "meta object of field",
"properties": {
"label": {
"$ref": "#/definitions/i18nString"
},
"helperText": {
"$ref": "#/definitions/i18nString"
},
"widget": {
"description": "ui widget",
"enum": [
"text",
"richText",
"checkbox",
"checkboxArray",
"select",
"selectArray",
"date",
"datetime",
"file",
"image",
"json",
"tabs"
]
},
"choices": {
"oneOf": [
{
"type": "object",
"description": "endpoint configuration",
"additionalProperties": false,
"properties": {
"endpoint": {
"type": "string",
"description": "endpoint URL or path"
},
"params": {
"type": "object",
"description": "query parameters"
},
"mapping": {
"type": "object",
"description": "data mapping",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "name of id field"
},
"name": {
"type": "string",
"description": "name of name/description field"
}
}
}
}
},
{
"type": "array",
"description": "choices to select from",
"items": {
"type": "object",
"properties": {
"id": {
"oneOf": [
{
"type": "null"
},
{
"type": "string"
},
{
"type": "number"
}
]
},
"name": {
"description": "name is human readable value",
"$ref": "#/definitions/i18nString"
},
"chipStyle": {
"$ref": "https://raw.githubusercontent.com/rcorp/css-schema/master/schema.json"
}
},
"required": ["id", "name"]
}
}
]
},
"valueMap": {
"type": "object",
"description": "map values to icons",
"patternProperties": {
".*": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"properties": {
"muiIcon": {
"type": "string"
},
"style": {
"$ref": "https://raw.githubusercontent.com/rcorp/css-schema/master/schema.json"
}
}
}
]
}
}
},
"dependsOn": {
"description": "depends on rule",
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "javascript code which hides field widget if evaluates to false with $, $this, $parent and $stack variables"
}
}
}
]
},
"defaultValue": {
"description": "default value or code to get the value",
"oneOf": [
{ "type": "array" },
{ "type": "string" },
{ "type": "null" },
{ "type": "boolean" },
{ "type": "number" },
{
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "js code with $navigation variable"
}
}
}
]
}
}
"$ref": "fieldMeta.json"
}
},
"required": ["name", "type"],
"definitions": {
"i18nString": {
"oneOf": [
{
"type": "object",
"patternProperties": {
"^[a-z]$": {
"type": "string"
}
}
},
{
"type": "string"
}
]
},
"evalExpressions": {
"oneOf": [
{
"type": "object",
"additionalProperties": true,
"properties": {
"twig": {
"type": "string",
"description": "twig template"
},
"projection": {
"type": "string",
"description": "query projection to use"
}
},
"required": ["twig"]
},
{
"type": "object",
"additionalProperties": true,
"properties": {
"eval": {
"type": "string",
"description": "javascript code"
},
"projection": {
"type": "string",
"description": "query projection to use"
}
},
"required": ["eval"]
}
]
},
"fieldSource": {
"oneOf": [
{
"$ref": "#/definitions/fieldPath"
},
{
"type": "object",
"properties": {
"source": {
"$ref": "#/definitions/fieldPath"
}
}
}
]
},
"fieldPath": {
"type": "string",
"description": "field, sub fields separated with dot (.)",
"pattern": "^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*$"
}
}
"required": ["name", "type"]
}

View File

@ -0,0 +1,370 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "JSON Schema tibi-server field meta configuration",
"description": "tibi-server field meta linter",
"type": "object",
"anyOf": [
{
"$ref": "#/definitions/minimum"
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": { "enum": ["text", "checkbox"] }
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": { "enum": ["richtext", "richText"] }
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget|choices$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"required": ["choices"],
"properties": {
"widget": {
"enum": [
"checkboxArray",
"select",
"selectArray",
"chipArray"
]
},
"choices": {
"oneOf": [
{
"type": "object",
"description": "endpoint configuration",
"additionalProperties": false,
"properties": {
"endpoint": {
"type": "string",
"description": "endpoint URL or path"
},
"params": {
"type": "object",
"description": "query parameters"
},
"mapping": {
"type": "object",
"description": "data mapping",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "name of id field"
},
"name": {
"type": "string",
"description": "name of name/description field"
}
}
}
}
},
{
"type": "array",
"description": "choices to select from",
"items": {
"type": "object",
"properties": {
"id": {
"oneOf": [
{
"type": "null"
},
{
"type": "string"
},
{
"type": "number"
}
]
},
"name": {
"description": "name is human readable value",
"$ref": "definitions.json#/definitions/i18nString"
},
"chipStyle": {
"$ref": "https://raw.githubusercontent.com/rcorp/css-schema/master/schema.json"
}
},
"required": ["id", "name"]
}
}
]
}
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": {
"enum": ["date", "datetime"]
}
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": {
"enum": ["file", "image"]
}
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": {
"enum": ["json"]
}
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget$": { "$comment": "stub for allOf" }
},
"allOf": [
{
"properties": {
"widget": {
"enum": ["tabs"]
}
}
}
]
},
{
"$ref": "#/definitions/minimum",
"patternProperties": {
"^x-.*|widget|baseHref|cssHref|imageSelect|fileSelect|videoSelect|customTags|style$": {
"$comment": "stub for allOf"
}
},
"allOf": [
{
"properties": {
"widget": {
"enum": ["contentbuilder"]
},
"baseHref": {
"description": "base href for relative links inside of ContentBuilder",
"oneOf": [
{ "type": "string" },
{
"$ref": "definitions.json#/definitions/evalObject"
}
]
},
"cssHref": {
"description": "href to css file for use with ContentBuilder",
"oneOf": [
{ "type": "string" },
{
"type": "array",
"items": { "type": "string" }
},
{
"$ref": "definitions.json#/definitions/evalObject"
}
]
},
"imageSelect": {
"description": "target for image selection",
"$ref": "#definitions/assetsTarget"
},
"fileSelect": {
"description": "target for file selection",
"$ref": "#definitions/assetsTarget"
},
"videoSelect": {
"description": "target for video selection",
"$ref": "#definitions/assetsTarget"
},
"customTags": {
"description": "custom tags to add to ContentBuilder",
"oneOf": [
{
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["placeholder", "label"],
"properties": {
"placeholder": {
"type": "string",
"description": "placeholder inside html code"
},
"label": {
"$ref": "definitions.json#/definitions/i18nString"
}
}
}
},
{
"$ref": "definitions.json#/definitions/evalObject"
}
]
},
"style": {
"description": "css style to inject into ContentBuilder",
"oneOf": [
{ "type": "string" },
{
"$ref": "definitions.json#/definitions/evalObject"
}
]
}
}
}
]
}
],
"definitions": {
"minimum": {
"additionalProperties": false,
"patternProperties": {
"^x\\-": {
"description": "template property"
}
},
"properties": {
"label": {
"$ref": "definitions.json#/definitions/i18nString",
"description": "label for field"
},
"helperText": {
"$ref": "definitions.json#/definitions/i18nString",
"description": "helper text for field"
},
"dependsOn": {
"description": "depends on rule",
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "javascript code which hides field widget if evaluates to false with $, $this, $parent and $stack variables"
}
}
}
]
},
"defaultValue": {
"description": "default value or code to get the value",
"oneOf": [
{ "type": "array" },
{ "type": "string" },
{ "type": "null" },
{ "type": "boolean" },
{ "type": "number" },
{
"type": "object",
"properties": {
"eval": {
"type": "string",
"description": "js code with $navigation variable"
}
}
}
]
},
"valueMap": {
"type": "object",
"description": "map values to icons",
"patternProperties": {
".*": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"properties": {
"muiIcon": {
"type": "string"
},
"style": {
"$ref": "https://raw.githubusercontent.com/rcorp/css-schema/master/schema.json"
}
}
}
]
}
}
}
}
},
"assetsTarget": {
"oneOf": [
{
"type": "string",
"description": "url for assets view"
},
{
"type": "object",
"properties": {
"collection": {
"type": "string",
"description": "collection name"
},
"subNavigation": {
"type": "number",
"description": "sub navigation index in collections meta.subNavigation"
}
}
},
{
"$ref": "definitions.json#/definitions/evalObject"
}
]
}
}
}