From b48fdbfcf92bebb4d5c7875df074438181110c25 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Thu, 18 May 2023 23:30:25 +0200 Subject: [PATCH 1/6] feat: added json-schema-form hyper schema --- json-schema-form.schema.json | 153 +++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 json-schema-form.schema.json diff --git a/json-schema-form.schema.json b/json-schema-form.schema.json new file mode 100644 index 000000000..40cca2abc --- /dev/null +++ b/json-schema-form.schema.json @@ -0,0 +1,153 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "JSON json-schema-form-Schema", + "definitions": { + "schemaArray": { + "allOf": [ + { + "$ref": "http://json-schema.org/draft-07/schema#/definitions/schemaArray" + }, + { + "items": { "$ref": "#" } + } + ] + } + }, + "allOf": [{ "$ref": "http://json-schema.org/draft-07/schema#" }], + "properties": { + "additionalItems": { "$ref": "#" }, + "additionalProperties": { "$ref": "#" }, + "dependencies": { + "additionalProperties": { + "anyOf": [{ "$ref": "#" }, { "type": "array" }] + } + }, + "items": { + "anyOf": [{ "$ref": "#" }, { "$ref": "#/definitions/schemaArray" }] + }, + "definitions": { + "additionalProperties": { "$ref": "#" } + }, + "patternProperties": { + "additionalProperties": { "$ref": "#" } + }, + "properties": { + "additionalProperties": { "$ref": "#" } + }, + "if": { "$ref": "#" }, + "then": { "$ref": "#" }, + "else": { "$ref": "#" }, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" }, + "contains": { "$ref": "#" }, + "propertyNames": { "$ref": "#" }, + "x-jsf-order": { + "description": "This keyword defines the order of fields for a given form or fieldset. It's placed at the schema root and inside of each fieldset.", + "$ref": "http://json-schema.org/draft-07/schema#/definitions/stringArray" + }, + "x-jsf-errorMessage": { + "type": "object", + "additionalProperties": false, + "properties": { + "required": { "type": "string" }, + "minimum": { "type": "string" }, + "minLength": { "type": "string" }, + "maximum": { "type": "string" }, + "maxLength": { "type": "string" }, + "pattern": { "type": "string" }, + "maxFileSize": { "type": "string" }, + "accept": { "type": "string" } + } + }, + "x-jsf-presentation": { + "type": "object", + "description": "Presentation overrides for the schema", + "additionalProperties": false, + "properties": { + "inputType": { + "description": "Input type for the schema", + "type": "string", + "oneOf": [ + { + "const": "text", + "description": "Similar to the native HTML input with text type." + }, + { + "const": "select", + "description": "Similar to the native HTML select element." + }, + { + "const": "radio", + "description": "Similar to a native HTML input with radio type." + }, + { + "const": "number", + "description": "Similar to the native HTML input with number type." + }, + { + "const": "date", + "description": "Expects a value with format YYY-MM-DD." + }, + { + "const": "checkbox", + "description": "Similar to the native HTML input with checkbox type." + }, + { + "const": "email", + "description": "Similar to the native HTML input with email type." + }, + { + "const": "file", + "description": "Similar to the native HTML input with file type." + }, + { + "const": "fieldset", + "description": "Groups multiple Fields inside. Its expected value is a nested object." + }, + { + "const": "group-array", + "description": "A list of inputs that can be repeated. Its expected value is an array." + } + ] + }, + "accept": { + "description": "For `inputType: \"file\"`. The accepted file types, as a comma separated string.", + "type": "string" + }, + "description": { + "description": "Field description with HTML. If you don't need HTML, please use the native description keyword.", + "type": "string" + }, + "statement": { + "description": "Special message about the field. Useful in cases where this message is based on the field value.", + "additionalProperties": false, + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "description": { + "description": "The sentence itself. Might include HTML.", + "type": "string" + }, + "severity": { + "type": "string", + "description": "Defines the type of message.", + "enum": ["info", "warning", "error", "success"] + } + } + }, + "maxFileSize": { + "description": "For `inputType: \"file\"`. The maximum file size in KB. It's used to enhanced Yup validation.", + "type": "number" + }, + "addFieldText": { + "description": "Used in `group-array` fields. The button text to add a new field.", + "type": "string" + } + } + } + } +} From 13a6222bdc11944f6b76f6598c5cfc945204cca1 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Fri, 19 May 2023 09:23:19 +0200 Subject: [PATCH 2/6] fix: added descriptions and type property to x-jsf-errorMessage --- json-schema-form.schema.json | 44 +++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/json-schema-form.schema.json b/json-schema-form.schema.json index 40cca2abc..4072043aa 100644 --- a/json-schema-form.schema.json +++ b/json-schema-form.schema.json @@ -51,14 +51,42 @@ "type": "object", "additionalProperties": false, "properties": { - "required": { "type": "string" }, - "minimum": { "type": "string" }, - "minLength": { "type": "string" }, - "maximum": { "type": "string" }, - "maxLength": { "type": "string" }, - "pattern": { "type": "string" }, - "maxFileSize": { "type": "string" }, - "accept": { "type": "string" } + "type": { + "type": "string", + "description": "Message shown when the value is not of the correct type." + }, + "required": { + "type": "string", + "description": "Message shown when the value is required and not provided." + }, + "minimum": { + "type": "string", + "description": "Message shown when the value is less than the minimum value." + }, + "minLength": { + "type": "string", + "description": "Message shown when the value is less than the minimum length." + }, + "maximum": { + "type": "string", + "description": "Message shown when the value is greater than the maximum value." + }, + "maxLength": { + "type": "string", + "description": "Message shown when the value is greater than the maximum length." + }, + "pattern": { + "type": "string", + "description": "Message shown when the value is not the correct format and does not match the pattern property." + }, + "maxFileSize": { + "type": "string", + "description": "Message shown when the file size is greater than the maximum file size." + }, + "accept": { + "type": "string", + "description": "Message shown when the file type is not accepted." + } } }, "x-jsf-presentation": { From 4d93ef14b77b14b1f772122dfb0129e2606546e5 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Fri, 19 May 2023 09:24:31 +0200 Subject: [PATCH 3/6] fix: loosened restriction for x-jsf-presentation and inputType --- json-schema-form.schema.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/json-schema-form.schema.json b/json-schema-form.schema.json index 4072043aa..4d1279443 100644 --- a/json-schema-form.schema.json +++ b/json-schema-form.schema.json @@ -92,10 +92,9 @@ "x-jsf-presentation": { "type": "object", "description": "Presentation overrides for the schema", - "additionalProperties": false, "properties": { "inputType": { - "description": "Input type for the schema", + "description": "Input type for the generated UI field", "type": "string", "oneOf": [ { @@ -137,6 +136,10 @@ { "const": "group-array", "description": "A list of inputs that can be repeated. Its expected value is an array." + }, + { + "type": "string", + "description": "Any arbitrary custom inputType you might want to represent your UI Field." } ] }, From 2ebb9d49c740c3a128bb80a3f1ebbd476425563a Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Fri, 19 May 2023 09:35:04 +0200 Subject: [PATCH 4/6] fix: fixed multiple match error for inputType --- json-schema-form.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json-schema-form.schema.json b/json-schema-form.schema.json index 4d1279443..f88354925 100644 --- a/json-schema-form.schema.json +++ b/json-schema-form.schema.json @@ -96,7 +96,7 @@ "inputType": { "description": "Input type for the generated UI field", "type": "string", - "oneOf": [ + "anyOf": [ { "const": "text", "description": "Similar to the native HTML input with text type." From 9e8f1e8b63c129f538f0cefb36855b25ea347fb6 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Fri, 19 May 2023 14:21:38 +0200 Subject: [PATCH 5/6] fix: reduced restrictiveness of statement field --- json-schema-form.schema.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/json-schema-form.schema.json b/json-schema-form.schema.json index f88354925..bd04c6ba8 100644 --- a/json-schema-form.schema.json +++ b/json-schema-form.schema.json @@ -153,7 +153,6 @@ }, "statement": { "description": "Special message about the field. Useful in cases where this message is based on the field value.", - "additionalProperties": false, "type": "object", "properties": { "title": { @@ -164,9 +163,14 @@ "type": "string" }, "severity": { - "type": "string", "description": "Defines the type of message.", - "enum": ["info", "warning", "error", "success"] + "anyOf": [ + { "type": "string", "const": "info" }, + { "type": "string", "const": "warning" }, + { "type": "string", "const": "error" }, + { "type": "string", "const": "success" }, + {} + ] } } }, From 7eda828a220ea5c3fc9987ae72d34c68437654d9 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Fri, 19 May 2023 16:30:46 +0200 Subject: [PATCH 6/6] chore: added json-schema-form.schema.json to package.json files --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a64daf5e5..65916f88c 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "files": [ "dist", "src/tests", + "json-schema-form.schema.json", "README.md", "CHANGELOG.md", "LICENSE.md"