diff --git a/.github/workflows/validate-embedded-examples.yml b/.github/workflows/validate-embedded-examples.yml new file mode 100644 index 00000000..fdcbb71d --- /dev/null +++ b/.github/workflows/validate-embedded-examples.yml @@ -0,0 +1,25 @@ +name: Validate Embedded Examples in asyncapi.md + +on: + # temporarily added for testing purposes + push: + branches: + - embedded-examples-validation + # pull_request_target: + # types: [opened, reopened, synchronize, edited, ready_for_review] + +jobs: + validate-examples: + name: Validate Examples + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + - name: Install Dependencies + run: npm install + - name: Validate AsyncAPI documents + run: npm run validate:examples \ No newline at end of file diff --git a/scripts/validation/embedded-examples-validation.js b/scripts/validation/embedded-examples-validation.js index 7207ca45..bb70294a 100644 --- a/scripts/validation/embedded-examples-validation.js +++ b/scripts/validation/embedded-examples-validation.js @@ -158,8 +158,10 @@ combinedData.forEach((item, index) => { fs.mkdirSync(outputDir, { recursive: true }); } - const outputPath = path.join(outputDir, `updated-doc-${index + 1}.json`); + const processedExampleName = item.name.replace(/[^\w\s-]/g, '').replace(/\s+/g, '-'); + const outputPath = path.join(outputDir, `${processedExampleName}.json`); // const outputPath = `./updated-docs/updated-doc-${index + 1}.json`; + // console.log(`\n${combinedData[num-1].name} = ${currentExample}`); // Apply updates and save the document applyUpdatesAndSave([item], baseDocPath, outputPath); @@ -259,7 +261,7 @@ console.log(`\nNumber of examples extracted: ${combinedData.length}`); let num = 43; const currentExample = JSON.stringify(combinedData[num-1], null, 2); console.log(`\nexample ${num} = ${currentExample} `) -// console.log(`\n${combinedData[num-1].name} = ${currentExample} `) +// console.log(`\n${combinedData[num-1].name} = ${currentExample}`); // Wait for all validation promises to resolve Promise.all(validationPromises) diff --git a/scripts/validation/package.json b/scripts/validation/package.json index 39c5ef5f..4ce1b0e6 100644 --- a/scripts/validation/package.json +++ b/scripts/validation/package.json @@ -1,10 +1,10 @@ { "name": "validation", "version": "1.0.0", - "description": "for example validation files", - "main": "validate-embedded-examples.js", + "description": "for validation of embedded examples in asyncapi.md file", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "validate:examples": "node embedded-examples-validation.js" }, "author": "Animesh Kumar", "license": "ISC",