chore: making the breaking change for this - perhaps a better way to do the deprecation though.

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-03-21 10:25:50 +01:00
parent e0a51384ac
commit c0697dcf88
10 changed files with 34 additions and 34 deletions
@@ -54,7 +54,7 @@ export class SchemaValidEntityPolicy implements EntityPolicy {
}
throw new Error(
`Malformed envelope, ${error.dataPath || '<root>'} ${error.message}`,
`Malformed envelope, ${error.instancePath || '<root>'} ${error.message}`,
);
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ export function throwAjvError(
const error = errors[0];
throw new TypeError(
`${error.dataPath || '<root>'} ${error.message}${
`${error.instancePath || '<root>'} ${error.message}${
error.params
? ` - ${Object.entries(error.params)
.map(([key, val]) => `${key}: ${val}`)
@@ -74,7 +74,7 @@ export function entityKindSchemaValidator<T extends Entity>(
// 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 &&
@@ -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' },
},
],
@@ -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}`,
);
@@ -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',
@@ -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);
});
}
@@ -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",
);
});
});
@@ -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;
@@ -53,7 +53,7 @@ export const DEFAULT_CONFIG_VISIBILITY: ConfigVisibility = 'backend';
*/
export type ValidationError = {
keyword: string;
dataPath: string;
instancePath: string;
schemaPath: string;
params: Record<string, any>;
propertyName?: string;