config-loader: switch to ajv v6
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
"@backstage/config": "^0.1.1",
|
||||
"@types/json-schema": "^7.0.6",
|
||||
"@types/json-schema-merge-allof": "^0.6.0",
|
||||
"ajv": "^7.0.0-beta.2",
|
||||
"ajv": "^6.12.5",
|
||||
"fs-extra": "^9.0.0",
|
||||
"json-schema": "^0.2.5",
|
||||
"json-schema-merge-allof": "^0.7.0",
|
||||
|
||||
@@ -41,33 +41,27 @@ export function compileConfigSchemas(
|
||||
const visibilityByPath = new Map<string, ConfigVisibility>();
|
||||
|
||||
const ajv = new Ajv({
|
||||
strict: true,
|
||||
allErrors: true,
|
||||
defaultMeta: 'http://json-schema.org/draft-07/schema#',
|
||||
schemas: {
|
||||
'https://backstage.io/schema/config-v1': true,
|
||||
},
|
||||
keywords: [
|
||||
{
|
||||
keyword: 'visibility',
|
||||
schemaType: 'string',
|
||||
metaSchema: {
|
||||
type: 'string',
|
||||
enum: CONFIG_VISIBILITIES,
|
||||
},
|
||||
compile(visibility: ConfigVisibility) {
|
||||
return (_data, ctx) => {
|
||||
if (!ctx) {
|
||||
return false;
|
||||
}
|
||||
if (visibility) {
|
||||
visibilityByPath.set(ctx.dataPath, visibility);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
},
|
||||
},
|
||||
],
|
||||
}).addKeyword('visibility', {
|
||||
type: 'string',
|
||||
metaSchema: {
|
||||
type: 'string',
|
||||
enum: CONFIG_VISIBILITIES,
|
||||
},
|
||||
compile(visibility: ConfigVisibility) {
|
||||
return (_data, dataPath) => {
|
||||
if (!dataPath) {
|
||||
return false;
|
||||
}
|
||||
if (visibility) {
|
||||
visibilityByPath.set(dataPath, visibility);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const merged = mergeAllOf(
|
||||
|
||||
@@ -40,24 +40,24 @@ const data = {
|
||||
|
||||
const visibilities = 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',
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -39,7 +39,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);
|
||||
}
|
||||
@@ -58,7 +58,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;
|
||||
|
||||
Reference in New Issue
Block a user