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

feat!: support 2.1.0 version of spec #41

Merged
Merged
113 changes: 113 additions & 0 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
},
"homepage": "https://github.com/asyncapi/generator-filters#readme",
"devDependencies": {
"ava": "^3.7.0",
"eslint": "^6.8.0",
"eslint-plugin-sonarjs": "^0.5.0",
"jsdoc-to-markdown": "^5.0.3",
"@asyncapi/parser": "^1.6.0",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/github": "^7.0.4",
"@semantic-release/npm": "^7.0.3",
"@semantic-release/release-notes-generator": "^9.0.1",
"ava": "^3.7.0",
"conventional-changelog-conventionalcommits": "^4.2.3",
"eslint": "^6.8.0",
"eslint-plugin-sonarjs": "^0.5.0",
"jsdoc-to-markdown": "^5.0.3",
"semantic-release": "^17.0.4"
},
"dependencies": {
Expand Down
50 changes: 40 additions & 10 deletions src/customFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,28 @@ filter.logError = logError;
* @returns {object}
*/
function getPayloadExamples(msg) {
if (Array.isArray(msg.examples()) && msg.examples().find(e => e.payload)) {
const examples = msg.examples();
if (Array.isArray(examples) && examples.some(e => e.payload)) {
// Instead of flat or flatmap use this.
return _.flatMap(msg.examples().map(e => e.payload).filter(Boolean));
const messageExamples = _.flatMap(examples)
.map(e => {
if (!e.payload) return;
return {
name: e.name,
summary: e.summary,
example: e.payload,
};
})
.filter(Boolean);

if (messageExamples.length > 0) {
return messageExamples;
}
}

if (msg.payload() && msg.payload().examples()) {
return msg.payload().examples();

const payload = msg.payload();
if (payload && payload.examples()) {
return payload.examples().map(example => ({ example }));
}
}
filter.getPayloadExamples = getPayloadExamples;
Expand All @@ -55,13 +70,28 @@ filter.getPayloadExamples = getPayloadExamples;
* @returns {object}
*/
function getHeadersExamples(msg) {
if (Array.isArray(msg.examples()) && msg.examples().find(e => e.headers)) {
const examples = msg.examples();
if (Array.isArray(examples) && examples.some(e => e.headers)) {
// Instead of flat or flatmap use this.
return _.flatMap(msg.examples().map(e => e.headers).filter(Boolean));
const messageExamples = _.flatMap(examples)
.map(e => {
if (!e.headers) return;
return {
name: e.name,
summary: e.summary,
example: e.headers,
};
})
.filter(Boolean);

if (messageExamples.length > 0) {
return messageExamples;
}
}

if (msg.headers() && msg.headers().examples()) {
return msg.headers().examples();

const headers = msg.headers();
if (headers && headers.examples()) {
return headers.examples().map(example => ({ example }));
}
}
filter.getHeadersExamples = getHeadersExamples;
Expand Down
Loading