From 81b40a5b2a01330e92d23783e6ea87685ba5b728 Mon Sep 17 00:00:00 2001 From: Animesh Kumar Date: Sat, 6 Jul 2024 00:02:50 +0530 Subject: [PATCH] fix: apply suggestions and fixes Changes: - https://github.com/asyncapi/spec/pull/1059#discussion_r1666910252 - https://github.com/asyncapi/spec/pull/1059#discussion_r1667007928 - https://github.com/asyncapi/spec/pull/1059#discussion_r1667009673 --- .../validation/embedded-examples-validation.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/scripts/validation/embedded-examples-validation.js b/scripts/validation/embedded-examples-validation.js index 4599c5a7..c9dc5964 100644 --- a/scripts/validation/embedded-examples-validation.js +++ b/scripts/validation/embedded-examples-validation.js @@ -47,17 +47,11 @@ function extractCommentsAndExamples(content) { // Extract comments and examples from the markdown file const combinedData = extractCommentsAndExamples(markdownContent); -// Function to convert URI Fragment to JSON Pointer -function uriFragmentToJsonPointer(uriFragment) { - if (uriFragment === '#') return ''; - return uriFragment.slice(1).split('/').map(decodeURIComponent).join('/'); -} - // Function to apply JSON Merge Patch updates to the document function applyUpdates(updates, baseDoc) { updates.forEach(update => { try { - const jsonPointerPath = uriFragmentToJsonPointer(update.json_pointer); + const jsonPointerPath = update.json_pointer; // Handle root document case if (jsonPointerPath === '') { @@ -91,7 +85,6 @@ async function validateParser(document, name) { process.exit(1); } else { console.log(errorMessage); - process.exit(1); } }); } else { @@ -109,19 +102,16 @@ const baseDocPath = './base-doc-combined.json'; const baseDoc = JSON.parse(fs.readFileSync(baseDocPath, 'utf8')); const validationPromises = combinedData.map(async (item) => { - const baseDocument = JSON.parse(JSON.stringify(baseDoc)); - - const updatedDocument = applyUpdates([item], baseDocument); + const updatedDocument = applyUpdates([item], baseDoc); - const documentString = updatedDocument; - await validateParser(documentString, `${item.name}-${item.format}-format`); + await validateParser(updatedDocument, `${item.name}-${item.format}-format`); }); console.log(`\nNumber of examples extracted: ${combinedData.length}\n`); Promise.all(validationPromises) .then(() => { - console.log('\n\nAll files are valid!'); + console.log('\n\nValidation process complete!\nCheck logs for any errors.'); }) .catch((error) => { console.error('Error during validations:', error);