diff --git a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts index 7f33e71f1c..1b5b7fe79b 100644 --- a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts +++ b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts @@ -54,7 +54,7 @@ export class SchemaValidEntityPolicy implements EntityPolicy { } throw new Error( - `Malformed envelope, ${error.dataPath || ''} ${error.message}`, + `Malformed envelope, ${error.instancePath || ''} ${error.message}`, ); } } diff --git a/packages/catalog-model/src/validation/ajv.ts b/packages/catalog-model/src/validation/ajv.ts index c65c3df18a..15d0b674bf 100644 --- a/packages/catalog-model/src/validation/ajv.ts +++ b/packages/catalog-model/src/validation/ajv.ts @@ -41,7 +41,7 @@ export function throwAjvError( const error = errors[0]; throw new TypeError( - `${error.dataPath || ''} ${error.message}${ + `${error.instancePath || ''} ${error.message}${ error.params ? ` - ${Object.entries(error.params) .map(([key, val]) => `${key}: ${val}`) diff --git a/packages/catalog-model/src/validation/entityKindSchemaValidator.ts b/packages/catalog-model/src/validation/entityKindSchemaValidator.ts index 66259cc63d..dc5aa586aa 100644 --- a/packages/catalog-model/src/validation/entityKindSchemaValidator.ts +++ b/packages/catalog-model/src/validation/entityKindSchemaValidator.ts @@ -74,7 +74,7 @@ export function entityKindSchemaValidator( // Only in the case where kind and/or apiVersion have enum mismatches AND // have NO other errors, we call it a soft error. const softCandidates = validate.errors?.filter(e => - ['/kind', '/apiVersion'].includes(e.dataPath), + ['/kind', '/apiVersion'].includes(e.instancePath), ); if ( softCandidates?.length && diff --git a/packages/config-loader/src/lib/schema/compile.test.ts b/packages/config-loader/src/lib/schema/compile.test.ts index 7b7db87c8f..999dabd307 100644 --- a/packages/config-loader/src/lib/schema/compile.test.ts +++ b/packages/config-loader/src/lib/schema/compile.test.ts @@ -32,9 +32,9 @@ describe('compileConfigSchemas', () => { errors: [ { keyword: 'type', - dataPath: '/a', + instancePath: '/a', schemaPath: '#/properties/a/type', - message: 'should be string', + message: 'must be string', params: { type: 'string' }, }, ], @@ -46,9 +46,9 @@ describe('compileConfigSchemas', () => { errors: [ { keyword: 'type', - dataPath: '/b', + instancePath: '/b', schemaPath: '#/properties/b/type', - message: 'should be number', + message: 'must be number', params: { type: 'number' }, }, ], diff --git a/packages/config-loader/src/lib/schema/compile.ts b/packages/config-loader/src/lib/schema/compile.ts index b7f705751e..c1059a28ae 100644 --- a/packages/config-loader/src/lib/schema/compile.ts +++ b/packages/config-loader/src/lib/schema/compile.ts @@ -57,11 +57,11 @@ export function compileConfigSchemas( }, compile(visibility: ConfigVisibility) { return (_data, context) => { - if (context?.dataPath === undefined) { + if (context?.instancePath === undefined) { return false; } if (visibility && visibility !== 'backend') { - const normalizedPath = context.dataPath.replace( + const normalizedPath = context.instancePath.replace( /\['?(.*?)'?\]/g, (_, segment) => `/${segment}`, ); @@ -77,10 +77,10 @@ export function compileConfigSchemas( metaSchema: { type: 'string' }, compile(deprecationDescription: string) { return (_data, context) => { - if (context?.dataPath === undefined) { + if (context?.instancePath === undefined) { return false; } - const normalizedPath = context.dataPath.replace( + const normalizedPath = context.instancePath.replace( /\['?(.*?)'?\]/g, (_, segment) => `/${segment}`, ); diff --git a/packages/config-loader/src/lib/schema/filtering.test.ts b/packages/config-loader/src/lib/schema/filtering.test.ts index df06975c9f..3a5de7e2c0 100644 --- a/packages/config-loader/src/lib/schema/filtering.test.ts +++ b/packages/config-loader/src/lib/schema/filtering.test.ts @@ -244,21 +244,21 @@ describe('filterErrorsByVisibility', () => { const errors = [ { keyword: 'something', - dataPath: '/a', + instancePath: '/a', schemaPath: '#/properties/a/something', params: {}, message: 'a', }, { keyword: 'something', - dataPath: '/b', + instancePath: '/b', schemaPath: '#/properties/b/something', params: {}, message: 'b', }, { keyword: 'something', - dataPath: '/c', + instancePath: '/c', schemaPath: '#/properties/c/something', params: {}, message: 'c', @@ -314,35 +314,35 @@ describe('filterErrorsByVisibility', () => { const errors = [ { keyword: 'type', - dataPath: '/a', + instancePath: '/a', schemaPath: '#/properties/a/type', params: { type: 'number' }, message: 'a', }, { keyword: 'type', - dataPath: '/b', + instancePath: '/b', schemaPath: '#/properties/b/type', params: { type: 'string' }, message: 'b', }, { keyword: 'type', - dataPath: '/c', + instancePath: '/c', schemaPath: '#/properties/c/type', params: { type: 'array' }, message: 'c', }, { keyword: 'type', - dataPath: '/c', + instancePath: '/c', schemaPath: '#/properties/c/type', params: { type: 'object' }, message: 'd', }, { keyword: 'type', - dataPath: '/c', + instancePath: '/c', schemaPath: '#/properties/c/type', params: { type: 'null' }, message: 'e', @@ -373,21 +373,21 @@ describe('filterErrorsByVisibility', () => { const errors = [ { keyword: 'required', - dataPath: '/a', + instancePath: '/a', schemaPath: '#/properties/o/required', params: { missingProperty: 'a' }, message: 'a', }, { keyword: 'required', - dataPath: '/b', + instancePath: '/b', schemaPath: '#/properties/o/required', params: { missingProperty: 'b' }, message: 'b', }, { keyword: 'required', - dataPath: '/c', + instancePath: '/c', schemaPath: '#/properties/o/required', params: { missingProperty: 'c' }, message: 'c', diff --git a/packages/config-loader/src/lib/schema/filtering.ts b/packages/config-loader/src/lib/schema/filtering.ts index 2855979b1f..e9a0327e06 100644 --- a/packages/config-loader/src/lib/schema/filtering.ts +++ b/packages/config-loader/src/lib/schema/filtering.ts @@ -173,7 +173,7 @@ export function filterErrorsByVisibility( } const vis = - visibilityByDataPath.get(error.dataPath) ?? DEFAULT_CONFIG_VISIBILITY; + visibilityByDataPath.get(error.instancePath) ?? DEFAULT_CONFIG_VISIBILITY; return vis && includeVisibilities.includes(vis); }); } diff --git a/packages/config-loader/src/lib/schema/load.test.ts b/packages/config-loader/src/lib/schema/load.test.ts index 8510ccb1d8..41971f7d01 100644 --- a/packages/config-loader/src/lib/schema/load.test.ts +++ b/packages/config-loader/src/lib/schema/load.test.ts @@ -105,7 +105,7 @@ describe('loadConfigSchema', () => { expect(() => schema2.process([...configs, { data: { key1: 3 }, context: 'test2' }]), ).toThrow( - 'Config validation failed, Config should be string { type=string } at /key1', + 'Config validation failed, Config must be string { type=string } at /key1', ); await expect( @@ -142,7 +142,7 @@ describe('loadConfigSchema', () => { ]; expect(() => schema.process(configs)).toThrow( - 'Config validation failed, Config should be number { type=number } at /key2', + 'Config validation failed, Config must be number { type=number } at /key2', ); expect(schema.process(configs, { visibility: ['frontend'] })).toEqual([ { @@ -151,7 +151,7 @@ describe('loadConfigSchema', () => { }, ]); expect(() => schema.process(configs, { visibility: ['secret'] })).toThrow( - 'Config validation failed, Config should be number { type=number } at /key2', + 'Config validation failed, Config must be number { type=number } at /key2', ); }); @@ -203,12 +203,12 @@ describe('loadConfigSchema', () => { }, ]); expect(() => schema.process(mkConfig({ y: 1 }))).toThrow( - 'Config validation failed, Config should be string { type=string } at /nested/0/y', + 'Config validation failed, Config must be string { type=string } at /nested/0/y', ); expect(() => schema.process(mkConfig({ y: 1 }), { visibility: ['frontend'] }), ).toThrow( - 'Config validation failed, Config should be string { type=string } at /nested/0/y', + 'Config validation failed, Config must be string { type=string } at /nested/0/y', ); expect( schema.process(mkConfig({ x: 'a' }), { visibility: ['frontend'] }), @@ -229,7 +229,7 @@ describe('loadConfigSchema', () => { expect(() => schema.process(mkConfig({ y: 'aaaa' }), { visibility: ['frontend'] }), ).toThrow( - 'Config validation failed, Config should match pattern "^...$" { pattern=^...$ } at /nested/0/y', + 'Config validation failed, Config must match pattern "^...$" { pattern=^...$ } at /nested/0/y', ); // This is a bit of an edge case where we have a structural error, these should always be reported @@ -238,7 +238,7 @@ describe('loadConfigSchema', () => { visibility: ['frontend'], }), ).toThrow( - 'Config validation failed, Config should be array { type=array } at /nested', + 'Config validation failed, Config must be array { type=array } at /nested', ); }); }); @@ -273,7 +273,7 @@ describe('loadConfigSchema', () => { visibility: ['frontend'], }), ).toThrow( - "Config should have required property 'x a' { missingProperty=x a } at /other", + "Config must have required property 'x a' { missingProperty=x a } at /other", ); }); }); diff --git a/packages/config-loader/src/lib/schema/load.ts b/packages/config-loader/src/lib/schema/load.ts index aa7ed06305..959b438371 100644 --- a/packages/config-loader/src/lib/schema/load.ts +++ b/packages/config-loader/src/lib/schema/load.ts @@ -41,11 +41,11 @@ export type LoadConfigSchemaOptions = }; function errorsToError(errors: ValidationError[]): Error { - const messages = errors.map(({ dataPath, message, params }) => { + const messages = errors.map(({ instancePath, message, params }) => { const paramStr = Object.entries(params) .map(([name, value]) => `${name}=${value}`) .join(' '); - return `Config ${message || ''} { ${paramStr} } at ${dataPath}`; + return `Config ${message || ''} { ${paramStr} } at ${instancePath}`; }); const error = new Error(`Config validation failed, ${messages.join('; ')}`); (error as any).messages = messages; diff --git a/packages/config-loader/src/lib/schema/types.ts b/packages/config-loader/src/lib/schema/types.ts index 75993b3c78..cc62192e30 100644 --- a/packages/config-loader/src/lib/schema/types.ts +++ b/packages/config-loader/src/lib/schema/types.ts @@ -53,7 +53,7 @@ export const DEFAULT_CONFIG_VISIBILITY: ConfigVisibility = 'backend'; */ export type ValidationError = { keyword: string; - dataPath: string; + instancePath: string; schemaPath: string; params: Record; propertyName?: string;