eclipsesource / jsonforms

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
http://jsonforms.io
Other
2.18k stars 368 forks source link

Duplicate validation warnings within oneOf #2360

Open chadmcivor opened 3 months ago

chadmcivor commented 3 months ago

Describe the bug

A similar issue was previously reported by bug #1265 which has been closed. I have encountered this problem using jsonforms 3.3.0. Duplicate validation warnings when using oneOf block where items have required properties with the same name. Only one of the items can be selected at a time but warnings are displayed for all of the items available for selection.

Expected behavior

No duplication of validation errors.

Steps to reproduce the issue

Use the following schema, select an application type and add an application.

export const schema = { "definitions": {
"serviceType": { "type": "string", "description": "Type of service executed at runtime", "enum": ["Run Task", "Export Data", "Import Data"], "default": "Run Task"
}, "subjectIds": { "type": "string", "description": "Use , item delimitor for multiple subject ids" }, "taskId": { "type": "string", "description": "Id of the automated task" }, "aiaApplication": { "type": "object", "properties": {
"serviceType": { $ref: "#/definitions/serviceType" },
"subjectIds": { $ref: "#/definitions/subjectIds" }, "subjectType": { "type": "string", "enum": ["Contract Id", "Contract Id File"]
}, "taskId": { $ref: "#/definitions/taskId" } }, "required": ["serviceType", "subjectIds", "subjectType", "taskId"]
}, "webApplication": { "type": "object", "properties": {
"serviceType": { $ref: "#/definitions/serviceType" },
"subjectIds": { $ref: "#/definitions/serviceType" }, "subjectType": { "type": "string", "enum": ["CPR"]
}, "taskId": { $ref: "#/definitions/taskId" } }, "required": ["serviceType", "subjectIds", "subjectType", "taskId"]
} }, "type": "object", "properties": { "applicationType": { "type": "string",
"description": "Type of application run", "enum": ["AIA", "Web"]
}, "application": {
"oneOf": [
{ $ref: "#/definitions/aiaApplication" }, { $ref: "#/definitions/webApplication" } ] }
}, "required": ["applicationType", "application"]
};

export const uischema = { "type": "VerticalLayout", "elements": [
{ "type": "Control", "scope": "#/properties/applicationType" },
{ type: "VerticalLayout",
"rule": { "effect": "SHOW", "condition": {
"scope": "#/properties/applicationType", "schema": { "const": "AIA"
} } }, elements: [ { type: 'VerticalLayout',
"elements": [
{ "type": "Control", "scope": "#/properties/application/oneOf/0/properties/serviceType", "options": { "format": "string", "default": "Run Task"
} }, { "type": "Control", "scope": "#/properties/application/oneOf/0/properties/subjectIds", "options": { "multi": true } }, { "type": "Control", "label": "Subject type", "scope": "#/properties/application/oneOf/0/properties/subjectType"
},
{ "type": "Control", "scope": "#/properties/application/oneOf/0/properties/taskId", "options": { "format": "string", } } ] } ] }, { type: "VerticalLayout",
"rule": { "effect": "SHOW", "condition": {
"scope": "#/properties/applicationType", "schema": { "const": "Web"
} } }, elements: [ { type: 'VerticalLayout',
"elements": [
{ "type": "Control", "scope": "#/properties/application/oneOf/1/properties/serviceType", "options": { "format": "string", "default": "Run Task"
} }, { "type": "Control", "scope": "#/properties/application/oneOf/1/properties/subjectIds", "options": { "multi": true } }, { "type": "Control", "label": "Subject type", "scope": "#/properties/application/oneOf/1/properties/subjectType"
},
{ "type": "Control", "scope": "#/properties/application/oneOf/1/properties/taskId", "options": { "format": "string", } } ] } ] } ] }

Screenshots

Duplicate validation warnings

Which Version of JSON Forms are you using?

v3.3.0

Framework

React

RendererSet

Material

Additional context

No response

sdirix commented 2 months ago

Hi @chadmcivor, the issue stems from the fact on how JSON Schema errors are specified.

As long as no oneOf is matching, JSON Schema can't know which one is the "intended" one. Therefore it reports all errors of all oneOf, i.e. the errors reported look something like this:

Message: JSON is valid against no schemas from 'oneOf'.
Schema path: #/properties/application/oneOf
Message: Required properties are missing from object: subjectIds, subjectType, taskId.
Schema path: #/definitions/webApplication/required
Message: Required properties are missing from object: subjectIds, subjectType, taskId.
Schema path: #/definitions/aiaApplication/required

We don't have any special logic in JSON Forms to identify "different-but-same-looking" errors but simply concatenate them. As the same properties are required in both oneOf, this leads to the "duplicated" error messages.

We could do some analysis when converting actual errors to the eventual errors string to avoid adding the same message twice. Would you like to contribute such an improvement? The entry point is here.