categories validation

This commit is contained in:
tree🌴 2023-10-08 01:16:03 +02:00
parent dba9a7f514
commit 219c103fb8
3 changed files with 23 additions and 17 deletions

View File

@ -12,7 +12,7 @@
name: Layer 2
- id: hardware
name: Hardware
- id: vpm
- id: vpn
name: VPN
- id: did
name: DID
@ -38,8 +38,8 @@
name: NFT
- id: other
name: Other
- id: alliance
name: Alliance
- id: alliances
name: Alliances
- id: mixing-management
name: Mixing management
- id: data-management
@ -48,5 +48,7 @@
name: Donate
- id: rd
name: R&D
- id: mixing-services
- id: mixing-service
name: Mixing services
- id: node
name: Node

View File

@ -27,19 +27,28 @@ const matrix = {
const schemaDir = "./schema";
const schemas = await loadSchemas();
schemas.project.properties.categories.items.enum = w3pd.data.categories.map(c => c.id)
for (const col of Object.keys(w3pd.data)) {
const validator = ajv.compile(schemas[matrix[col]]);
const ids = []
for (const item of w3pd.data[col]) {
const testName = `${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : '')
if(Object.keys(item).length === 1) {
continue
if (ids.includes(item.id)) {
Deno.test(testName + ' (id-duplicates)', () => {
throw { message: `Duplicate project id="${item.id}"` }
});
}
Deno.test(`${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : ''), () => {
if (!validator(item)) {
throw validator.errors;
}
});
if(Object.keys(item).length > 1) {
Deno.test(testName + ' (schema)', () => {
if (!validator(item)) {
throw validator.errors;
}
});
}
ids.push(item.id)
}
}

View File

@ -27,12 +27,7 @@ export class W3PData {
}
const pDir = `${catDir}/${pd.name}`;
const indexFn = `${pDir}/index.yaml`;
try {
await Deno.stat(indexFn);
} catch(e) {
continue
}
const index = yaml.load(
await Deno.readTextFile(indexFn),
);