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;
|
||||
|
||||
@@ -6569,15 +6569,6 @@ ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.1, ajv@^6.10.2, ajv@^6.12.4, ajv@^6.12.5, ajv
|
||||
json-schema-traverse "^0.4.1"
|
||||
uri-js "^4.2.2"
|
||||
|
||||
ajv@^7.0.0-beta.2:
|
||||
version "7.0.0-beta.3"
|
||||
resolved "https://registry.npmjs.org/ajv/-/ajv-7.0.0-beta.3.tgz#d34861ccfbdebb55bf9f49a08b29f76bf656fc5c"
|
||||
integrity sha512-gUGVvM4NmyqrFvCNAQnP4P7FC0RjxMQyRnrXpozNglBkDJnTysVbvycyOZUy5n6yLKSqVDUqWZBXj7dXINrSqw==
|
||||
dependencies:
|
||||
fast-deep-equal "^3.1.1"
|
||||
json-schema-traverse "^0.5.0"
|
||||
uri-js "^4.2.2"
|
||||
|
||||
alphanum-sort@^1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
|
||||
@@ -15052,11 +15043,6 @@ json-schema-traverse@^0.4.1:
|
||||
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
|
||||
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==
|
||||
|
||||
json-schema-traverse@^0.5.0:
|
||||
version "0.5.0"
|
||||
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.5.0.tgz#1069a6097f9e9a567bfc6cc215e85f606ebf6480"
|
||||
integrity sha512-x+TRJIQFskrNnFKE2Viz9FCSjK1vIh+H/uaBiOYszh/IcZmAFneQ35H4osWDJp1NPXccuV2I0RMXmi2ZS6Kqcg==
|
||||
|
||||
json-schema@0.2.3:
|
||||
version "0.2.3"
|
||||
resolved "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
|
||||
|
||||
Reference in New Issue
Block a user