Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate validation warnings within oneOf #2360

Open
chadmcivor opened this issue Jul 23, 2024 · 1 comment
Open

Duplicate validation warnings within oneOf #2360

chadmcivor opened this issue Jul 23, 2024 · 1 comment

Comments

@chadmcivor
Copy link

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
Copy link
Member

sdirix commented Aug 7, 2024

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.

@sdirix sdirix added this to the next milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants