-
Notifications
You must be signed in to change notification settings - Fork 391
indexOfFittingSchema for oneOf doesn't work anymore if $ref is used #1991
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
Comments
I've bisected and stepped through the code a bit and found the culprit in #1829. Before the merge ...
const resolvedSchema = Resolve.schema(
ownProps.schema || rootSchema,
uischema.scope,
rootSchema
);
...
const schema = resolvedSchema || rootSchema;
const _schema = resolveSubSchemas(schema, rootSchema, keyword);
...
let indexOfFittingSchema: number;
// TODO instead of compiling the combinator subschemas we can compile the original schema
// without the combinator alternatives and then revalidate and check the errors for the
// element
for (let i = 0; i < _schema[keyword].length; i++) {
try {
const valFn = ajv.compile(_schema[keyword][i]);
valFn(data);
if (dataIsValid(valFn.errors)) {
indexOfFittingSchema = i;
break;
}
} catch (error) {
console.debug("Combinator subschema is not self contained, can't hand it over to AJV");
}
} which works, because {
"oneOf": [
{
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"mail": {
"type": "string"
}
},
"required": [
"name",
"mail"
],
"additionalProperties": false
}
]
} After #1829 was merged, the logic was changed to const resolvedSchema = Resolve.schema(
ownProps.schema || rootSchema,
uischema.scope,
rootSchema
);
...
let indexOfFittingSchema: number;
// TODO instead of compiling the combinator subschemas we can compile the original schema
// without the combinator alternatives and then revalidate and check the errors for the
// element
for (let i = 0; i < resolvedSchema[keyword]?.length; i++) {
try {
const valFn = ajv.compile(resolvedSchema[keyword][i]);
valFn(data);
if (dataIsValid(valFn.errors)) {
indexOfFittingSchema = i;
break;
}
} catch (error) {
console.debug("Combinator subschema is not self contained, can't hand it over to AJV");
}
} This fails with the given debug message as {
"oneOf": [
{
"$ref": "#/definitions/address"
},
{
"$ref": "#/definitions/user"
}
]
} |
Thanks for the analysis! We'll take a look. In case you need a workaround until the fix is done you can use |
closes eclipsesource#1991 Signed-off-by: Lukas Boll [email protected]
Within the combinator mappings we try to determine the best fitting schema so that the The situation is now improved by resolving references on the combinator level. This Fixed in #2001 |
Describe the bug
Since Version 3.0.0-beta.2, the indexOfFittingSchema returns undefined instead, for example 0 or 1.
The Previous Versions worked fine.
If I use the same schema without any refs, it works fine.
oneOf with $ref (official oneOf Example)
oneOf without $ref
Expected behavior
If the bound data matches a oneOf Schema, then it should have an indexOfFittingSchema.
Steps to reproduce the issue
Screenshots
No response
In which browser are you experiencing the issue?
Browser independent
Framework
Core
RendererSet
Material
Additional context
No response
The text was updated successfully, but these errors were encountered: