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

Commit

Permalink
fix: work correctly on pre-parsed AsyncAPI docs when given as Input (#…
Browse files Browse the repository at this point in the history
…103)

* fix: work correctly on pre-parsed input

* add tests for parsed asyncapi docs

* Update test/testsUtil.js

Co-authored-by: Maciej Urbańczyk <[email protected]>

* Update lib/utils.js

Co-authored-by: Maciej Urbańczyk <[email protected]>

* chore: remove console

* chore: fix code smells

* fix: code smell

Co-authored-by: Maciej Urbańczyk <[email protected]>
Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
3 people authored May 12, 2022
1 parent f049d17 commit 133921a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
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};

0 comments on commit 133921a

Please sign in to comment.