From b8198933f94da21d32ec242e3e74acc582ad8f8b Mon Sep 17 00:00:00 2001 From: Animesh Kumar Date: Tue, 28 Nov 2023 22:41:14 +0530 Subject: [PATCH] Add `excludeFiles` to avoid failing script Changes: - added the function temporarily to avoid validation failure due to these two files - The schemas version are incorrect in these and needs to be fixed Issue concerning fixing of the described issue: 1. https://github.com/asyncapi/spec-json-schemas/issues/454 2. https://github.com/asyncapi/spec-json-schemas/issues/455 --- scripts/validate-schemas-final.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/validate-schemas-final.js b/scripts/validate-schemas-final.js index 1b03c2d3..8e89147f 100644 --- a/scripts/validate-schemas-final.js +++ b/scripts/validate-schemas-final.js @@ -7,7 +7,7 @@ const ajvDraft04 = new AjvDraft04(); const Ajv = require('ajv'); const ajv = new Ajv(); -function validation (){ +function validation (excludedFiles){ // Specify the path to the 'schemas' directory const directoryPath = './schemas'; @@ -17,7 +17,7 @@ function validation (){ const files = fs.readdirSync(directoryPath); // Filter files - const filteredFiles = files.filter(file => path.extname(file).toLowerCase() === '.json'); + const filteredFiles = files.filter(file => !excludedFiles.includes(file) && path.extname(file).toLowerCase() === '.json'); // Collect errors in an array @@ -39,13 +39,13 @@ function validation (){ // Validate the schema validate = ajvDraft04.validateSchema(obj); if(validate){ - console.log(`${file}: JSON Schema is valid!`); + console.log(`\n${file}: JSON Schema is valid!`); } } else { // Validate the schema validate = ajv.validateSchema(obj); if(validate){ - console.log(`${file}: JSON Schema is valid!`); + console.log(`\n${file}: JSON Schema is valid!`); } } @@ -62,14 +62,14 @@ function validation (){ } catch (error) { validationErrors.push({ file, - errors: [{ message: `Error reading or parsing JSON Schema: ${error.message}` }] + errors: [{ message: `\nError reading or parsing JSON Schema: ${error.message}` }] }); } }); // Print errors after processing all files validationErrors.forEach(({ file, errors }) => { - console.error(`${file}: JSON Schema is not valid:`, errors); + console.error(`\n${file}: JSON Schema is not valid:`, errors); }); // Exit with an error code if there are validation errors @@ -78,10 +78,13 @@ function validation (){ } } catch (error) { - console.error('Error during validation:', error.message); + console.error('\nError during validation:', error.message); } } -validation(); -console.log('Validation completed successfully.'); \ No newline at end of file +const excludedFiles=['2.0.0-rc1.json', '2.0.0-rc1-without-$id.json']; // added temporarily to avoid validation failure due to these two files. The schemas version are incorrect in these and needs to be fixed. + +validation(excludedFiles); + +console.log('\nValidation completed successfully.'); \ No newline at end of file