Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

fix: work correctly on pre-parsed AsyncAPI docs when given as Input #103

Merged
Merged
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const parser = require('@asyncapi/parser');
* @param {Array} asyncApiDocs unparsed AsyncAPI documents
* @returns {Promise<Array>} parsed AsyncAPI documents
*/

function validate(asyncApiDocs) {
return Promise.all(asyncApiDocs.map(async doc => {
if (doc && doc['x-parser-spec-parsed'] === true) {
if (typeof doc === 'object' && typeof doc.ext === 'function' && doc.ext('x-parser-spec-parsed')) {
return doc;
}
return parser.parse(doc);
Expand Down
36 changes: 29 additions & 7 deletions test/appRelationsDiscovery_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion test/testsUtil.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
const path = require('path');
const fs = require('fs');
const parser = require('@asyncapi/parser');

const examplesPath = './test/examples/flightService';

async function parseAsyncApiExamples(asyncApiDocs) {
const docs = [];
for (const doc of asyncApiDocs) {
const parsedDoc = await parser.parse(doc);
docs.push(parsedDoc);
}
return docs;
}

function getAsyncApiExamples() {
const docs = [];
const files = fs.readdirSync(examplesPath);
Expand All @@ -14,4 +24,4 @@ function getAsyncApiExamples() {
return docs;
}

module.exports = {getAsyncApiExamples};
module.exports = {getAsyncApiExamples,parseAsyncApiExamples};