config-loader: Bump to ajv 7, to enable v7 feature use elsewhere
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/config-loader': patch
|
||||
---
|
||||
|
||||
Bump config-loader to ajv 7, to enable v7 feature use elsewhere
|
||||
@@ -173,7 +173,9 @@
|
||||
"type": "string",
|
||||
"visibility": "frontend",
|
||||
"description": "Tracking ID for Google Analytics",
|
||||
"example": "UA-000000-0"
|
||||
"examples": [
|
||||
"UA-000000-0"
|
||||
]
|
||||
},
|
||||
"listen": {
|
||||
"type": "object",
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"dependencies": {
|
||||
"@backstage/cli-common": "^0.1.1",
|
||||
"@backstage/config": "^0.1.1",
|
||||
"ajv": "^6.12.5",
|
||||
"ajv": "^7.0.3",
|
||||
"fs-extra": "^9.0.0",
|
||||
"json-schema": "^0.2.5",
|
||||
"json-schema-merge-allof": "^0.7.0",
|
||||
|
||||
@@ -29,11 +29,11 @@ describe('compileConfigSchemas', () => {
|
||||
},
|
||||
]);
|
||||
expect(validate([{ data: { a: 1 }, context: 'test' }])).toEqual({
|
||||
errors: ['Config should be string { type=string } at .a'],
|
||||
errors: ['Config should be string { type=string } at /a'],
|
||||
visibilityByPath: new Map(),
|
||||
});
|
||||
expect(validate([{ data: { b: 'b' }, context: 'test' }])).toEqual({
|
||||
errors: ['Config should be number { type=number } at .b'],
|
||||
errors: ['Config should be number { type=number } at /b'],
|
||||
visibilityByPath: new Map(),
|
||||
});
|
||||
});
|
||||
@@ -80,10 +80,10 @@ describe('compileConfigSchemas', () => {
|
||||
).toEqual({
|
||||
visibilityByPath: new Map(
|
||||
Object.entries({
|
||||
'.a': 'frontend',
|
||||
'.b': 'secret',
|
||||
'.d': 'secret',
|
||||
'.d.0': 'frontend',
|
||||
'/a': 'frontend',
|
||||
'/b': 'secret',
|
||||
'/d': 'secret',
|
||||
'/d/0': 'frontend',
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -42,23 +42,25 @@ export function compileConfigSchemas(
|
||||
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
allowUnionTypes: true,
|
||||
schemas: {
|
||||
'https://backstage.io/schema/config-v1': true,
|
||||
},
|
||||
}).addKeyword('visibility', {
|
||||
}).addKeyword({
|
||||
keyword: 'visibility',
|
||||
metaSchema: {
|
||||
type: 'string',
|
||||
enum: CONFIG_VISIBILITIES,
|
||||
},
|
||||
compile(visibility: ConfigVisibility) {
|
||||
return (_data, dataPath) => {
|
||||
if (!dataPath) {
|
||||
return (_data, context) => {
|
||||
if (context?.dataPath === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (visibility && visibility !== 'backend') {
|
||||
const normalizedPath = dataPath.replace(
|
||||
const normalizedPath = context.dataPath.replace(
|
||||
/\['?(.*?)'?\]/g,
|
||||
(_, segment) => `.${segment}`,
|
||||
(_, segment) => `/${segment}`,
|
||||
);
|
||||
visibilityByPath.set(normalizedPath, visibility);
|
||||
}
|
||||
|
||||
@@ -40,24 +40,24 @@ const data = {
|
||||
|
||||
const visibility = new Map<string, ConfigVisibility>(
|
||||
Object.entries({
|
||||
'.arr.0': 'frontend',
|
||||
'.arr.1': 'backend',
|
||||
'.arr.2': 'secret',
|
||||
'.obj.f': 'frontend',
|
||||
'.obj.b': 'backend',
|
||||
'.obj.b.s': 'secret',
|
||||
'.objArr.0.f': 'frontend',
|
||||
'.objArr.0.b': 'backend',
|
||||
'.objArr.0.s': 'secret',
|
||||
'.objArr.1.f': 'frontend',
|
||||
'.objArr.1.b': 'backend',
|
||||
'.objArr.1.s': 'secret',
|
||||
'.arrF': 'frontend',
|
||||
'.arrB': 'backend',
|
||||
'.arrS': 'secret',
|
||||
'.objF': 'frontend',
|
||||
'.objB': 'backend',
|
||||
'.objS': 'secret',
|
||||
'/arr/0': 'frontend',
|
||||
'/arr/1': 'backend',
|
||||
'/arr/2': 'secret',
|
||||
'/obj/f': 'frontend',
|
||||
'/obj/b': 'backend',
|
||||
'/obj/b/s': 'secret',
|
||||
'/objArr/0/f': 'frontend',
|
||||
'/objArr/0/b': 'backend',
|
||||
'/objArr/0/s': 'secret',
|
||||
'/objArr/1/f': 'frontend',
|
||||
'/objArr/1/b': 'backend',
|
||||
'/objArr/1/s': 'secret',
|
||||
'/arrF': 'frontend',
|
||||
'/arrB': 'backend',
|
||||
'/arrS': 'secret',
|
||||
'/objF': 'frontend',
|
||||
'/objB': 'backend',
|
||||
'/objS': 'secret',
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export function filterByVisibility(
|
||||
const arr = new Array<JsonValue>();
|
||||
|
||||
for (const [index, value] of jsonVal.entries()) {
|
||||
const out = transform(value, `${path}.${index}`);
|
||||
const out = transform(value, `${path}/${index}`);
|
||||
if (out !== undefined) {
|
||||
arr.push(out);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ export function filterByVisibility(
|
||||
if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
const out = transform(value, `${path}.${key}`);
|
||||
const out = transform(value, `${path}/${key}`);
|
||||
if (out !== undefined) {
|
||||
outObj[key] = out;
|
||||
hasOutput = true;
|
||||
|
||||
@@ -85,7 +85,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 should be string { type=string } at /key1',
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
||||
Reference in New Issue
Block a user