Skip to content

Commit ced3fb8

Browse files
Remove deprecated jsPropertySyntax AJV option
Handle JSON pointers property syntax in instancePath error property.
1 parent 2cf6967 commit ced3fb8

File tree

10 files changed

+18
-20
lines changed

10 files changed

+18
-20
lines changed

packages/angular-material/test/autocomplete-control.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe('AutoComplete control Error Tests', () => {
293293
it('should display errors', () => {
294294
const errors: ErrorObject[] = [
295295
{
296-
instancePath: '.foo',
296+
instancePath: '/foo',
297297
message: 'Hi, this is me, test error!',
298298
params: {},
299299
keyword: '',

packages/angular-material/test/date-control.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe('Date control Error Tests', () => {
257257
const formsService = getJsonFormsService(component);
258258
formsService.updateCore(Actions.updateErrors([
259259
{
260-
instancePath: '.foo',
260+
instancePath: '/foo',
261261
message: 'Hi, this is me, test error!',
262262
params: {},
263263
keyword: '',

packages/angular-test/src/boolean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export const booleanErrorTest = <C extends JsonFormsControl, I>(
281281
});
282282
formsService.updateCore(Actions.updateErrors([
283283
{
284-
instancePath: '.foo',
284+
instancePath: '/foo',
285285
message: 'Hi, this is me, test error!',
286286
keyword: '',
287287
schemaPath: '',

packages/angular-test/src/number.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export const numberErrorTest = <C extends JsonFormsControl>(
346346
});
347347
formsService.updateCore(Actions.updateErrors([
348348
{
349-
instancePath: '.foo',
349+
instancePath: '/foo',
350350
message: 'Hi, this is me, test error!',
351351
keyword: '',
352352
schemaPath: '',

packages/angular-test/src/range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export const rangeErrorTest = <C extends JsonFormsControl, I>(
324324
});
325325
formsService.updateCore(Actions.updateErrors([
326326
{
327-
instancePath: '.foo',
327+
instancePath: '/foo',
328328
message: 'Hi, this is me, test error!',
329329
keyword: '',
330330
schemaPath: '',

packages/angular-test/src/text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export const textErrorTest = <C extends JsonFormsControl>(
293293
});
294294
formsService.updateCore(Actions.updateErrors([
295295
{
296-
instancePath: '.foo',
296+
instancePath: '/foo',
297297
message: 'Hi, this is me, test error!',
298298
keyword: '',
299299
schemaPath: '',

packages/core/src/reducers/core.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,16 @@ export const getControlPath = (error: ErrorObject) => {
318318
}
319319
// dataPath was renamed to instancePath in AJV v8
320320
var controlPath: string = error.instancePath;
321-
const invalidProperty = getInvalidProperty(error);
322-
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
323-
controlPath = `${controlPath}.${invalidProperty}`;
324-
}
325-
// remove '.' chars at the beginning of paths
326-
controlPath = controlPath.replace(/^./, '');
327-
// change array paths to dot notation (e.g. 'segment[0]' becomes 'segment.0')
328-
controlPath = controlPath.replace(
329-
/\[\d+\]/g,
330-
m => '.' + m.match(/\d+/g)[0]
331-
);
321+
322+
// change '/' chars to '.'
323+
controlPath = controlPath.replace(/\//g, '.');
324+
// remove '.' chars at the beginning of paths
325+
controlPath = controlPath.replace(/^./, '');
326+
327+
const invalidProperty = getInvalidProperty(error);
328+
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
329+
controlPath = `${controlPath}.${invalidProperty}`;
330+
}
332331
return controlPath;
333332
}
334333

packages/core/src/util/validator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { Options } from 'ajv';
2929
export const createAjv = (options?: Options) => {
3030
const ajv = new Ajv({
3131
allErrors: true,
32-
jsPropertySyntax: true,
3332
verbose: true,
3433
...options
3534
});

packages/core/test/reducers/core.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ test('core reducer - updateErrors - should update errors with error', t => {
502502
};
503503

504504
const error = {
505-
instancePath: 'color',
505+
instancePath: '/color',
506506
keyword: 'enum',
507507
message: 'should be equal to one of the allowed values',
508508
params: {

packages/core/test/util/renderer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ test('mapStateToControlProps - errors', t => {
384384
};
385385
const clonedState = _.cloneDeep(createState(coreUISchema));
386386
const error: ErrorObject = {
387-
instancePath: '.firstName',
387+
instancePath: '/firstName',
388388
message: 'Duff beer',
389389
keyword: 'whatever',
390390
schemaPath: '',

0 commit comments

Comments
 (0)