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

View file

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

View file

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