Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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