Skip to content

Commit

Permalink
fix: modify script to support YAML versions
Browse files Browse the repository at this point in the history
Changes:
- modified script to parse and validate YAML versions of the examples
- update package.json and package-lock.json with new dependencies
  • Loading branch information
AnimeshKumar923 committed Jun 18, 2024
1 parent 53290ea commit cf62169
Show file tree
Hide file tree
Showing 3 changed files with 1,274 additions and 18,744 deletions.
8 changes: 4 additions & 4 deletions scripts/validation/embedded-examples-validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const { JSONPath } = require('jsonpath-plus');
const path = require('path');
const yaml = require('js-yaml');
const { Parser } = require('@asyncapi/parser');
const parser = new Parser();

Expand All @@ -25,8 +26,7 @@ function extractCommentsAndExamples(content) {
if (format === 'json') {
example = JSON.parse(exampleContent);
} else if (format === 'yaml') {
// Add YAML parsing if needed, using a library like js-yaml
// example = yaml.load(exampleContent);
example = yaml.load(exampleContent);
} else {
throw new Error(`Unsupported format: ${format}`);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ function applyUpdatesAndSave(updates, baseDocPath, outputPath) {
} else {
const results = JSONPath({ path: update.json_path, json: baseDoc, resultType: 'all' });

console.log(`\nProcessing update for '${update.name}' at path '${update.json_path}'`);
console.log(`\nProcessing update for '${update.name}-${update.format}-format' at path '${update.json_path}'`);

const pathParts = update.json_path.split('.');
const targetKey = pathParts[pathParts.length - 1];
Expand Down Expand Up @@ -222,7 +222,7 @@ console.log(`\nNumber of examples extracted: ${combinedData.length}`);
Promise.all(validationPromises)
.then(() => {
// All validations are complete, delete the folder
// deleteFolderRecursive(outputDir); // Commented out to keep the updated files for debugging
deleteFolderRecursive(outputDir); // Commented out to keep the updated files for debugging
})
.catch((error) => {
console.error('Error during validations:', error);
Expand Down
Loading

0 comments on commit cf62169

Please sign in to comment.