Skip to content

Commit

Permalink
fix dublicate error message
Browse files Browse the repository at this point in the history
subErrorsAt now only returning errors form child elements

closes #1760
  • Loading branch information
LukasBoll committed Nov 14, 2022
1 parent f6a6e1b commit 11f64f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,4 @@ const getErrorsAt = (
export const errorAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, path => path === instancePath);
export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath + '.'));
36 changes: 36 additions & 0 deletions packages/core/test/reducers/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,42 @@ test('subErrorsAt filters array inner', t => {
t.deepEqual(filtered[0], state.errors[1]);
});

test('subErrorsAt only returning suberrors', t => {
const ajv = createAjv();
const schema: JsonSchema = {
type: 'object',
properties: {
numbers: {
title: 'Numbers',
type: 'array',
minItems: 1,
items: {
title: 'Type',
type: 'string',
enum: ['One', 'Two', 'Three']
},
}
}
};
const data: { numbers: string[] } = {
numbers: []
};
const v = ajv.compile(schema);
const errors = validate(v, data);

const state: JsonFormsCore = {
data,
schema,
uischema: undefined,
errors
};
const subErrors = subErrorsAt(
'numbers',
schema.properties.numbers.items as JsonSchema
)(state);
t.is(subErrors.length, 0);
});

test('subErrorsAt filters oneOf array inner', t => {
const ajv = createAjv();
const schema: JsonSchema = {
Expand Down

0 comments on commit 11f64f2

Please sign in to comment.