Skip to content

Commit

Permalink
fix: apply suggestions and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimeshKumar923 committed Jul 5, 2024
1 parent 6faca8d commit 81b40a5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions scripts/validation/embedded-examples-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '') {
Expand Down Expand Up @@ -91,7 +85,6 @@ async function validateParser(document, name) {
process.exit(1);
} else {
console.log(errorMessage);
process.exit(1);
}
});
} else {
Expand All @@ -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);
Expand Down

0 comments on commit 81b40a5

Please sign in to comment.