Skip to content

Commit

Permalink
Remove deprecated jsPropertySyntax AJV option
Browse files Browse the repository at this point in the history
Handle JSON pointers property syntax in instancePath error property.
  • Loading branch information
AlexandraBuzila committed Oct 5, 2021
1 parent 2cf6967 commit 0c515e7
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('AutoComplete control Error Tests', () => {
it('should display errors', () => {
const errors: ErrorObject[] = [
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
params: {},
keyword: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-material/test/date-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('Date control Error Tests', () => {
const formsService = getJsonFormsService(component);
formsService.updateCore(Actions.updateErrors([
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
params: {},
keyword: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-test/src/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const booleanErrorTest = <C extends JsonFormsControl, I>(
});
formsService.updateCore(Actions.updateErrors([
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
keyword: '',
schemaPath: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-test/src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const numberErrorTest = <C extends JsonFormsControl>(
});
formsService.updateCore(Actions.updateErrors([
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
keyword: '',
schemaPath: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-test/src/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export const rangeErrorTest = <C extends JsonFormsControl, I>(
});
formsService.updateCore(Actions.updateErrors([
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
keyword: '',
schemaPath: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-test/src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const textErrorTest = <C extends JsonFormsControl>(
});
formsService.updateCore(Actions.updateErrors([
{
instancePath: '.foo',
instancePath: '/foo',
message: 'Hi, this is me, test error!',
keyword: '',
schemaPath: '',
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,17 @@ export const getControlPath = (error: ErrorObject) => {
}
// dataPath was renamed to instancePath in AJV v8
var controlPath: string = error.instancePath;
const invalidProperty = getInvalidProperty(error);
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
controlPath = `${controlPath}.${invalidProperty}`;
}
// remove '.' chars at the beginning of paths
controlPath = controlPath.replace(/^./, '');
// change array paths to dot notation (e.g. 'segment[0]' becomes 'segment.0')
controlPath = controlPath.replace(
/\[\d+\]/g,
m => '.' + m.match(/\d+/g)[0]
);

// change '/' chars to '.'
controlPath = controlPath.replace(/\//g, '.');

const invalidProperty = getInvalidProperty(error);
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
controlPath = `${controlPath}.${invalidProperty}`;
}

// remove '.' chars at the beginning of paths
controlPath = controlPath.replace(/^./, '');
return controlPath;
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { Options } from 'ajv';
export const createAjv = (options?: Options) => {
const ajv = new Ajv({
allErrors: true,
jsPropertySyntax: true,
verbose: true,
...options
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/reducers/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ test('core reducer - updateErrors - should update errors with error', t => {
};

const error = {
instancePath: 'color',
instancePath: '/color',
keyword: 'enum',
message: 'should be equal to one of the allowed values',
params: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/util/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ test('mapStateToControlProps - errors', t => {
};
const clonedState = _.cloneDeep(createState(coreUISchema));
const error: ErrorObject = {
instancePath: '.firstName',
instancePath: '/firstName',
message: 'Duff beer',
keyword: 'whatever',
schemaPath: '',
Expand Down

0 comments on commit 0c515e7

Please sign in to comment.