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
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ rules:
prefer-arrow-callback: 2
prefer-const: 2
prefer-spread: 2
prefer-template: 2
prefer-template: 2

overrides:
- files: "**/*.test.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope 😞 Still 36% of duplication...

rules:
sonarjs/no-duplicate-string: 0
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
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.exclusions=src/customFilters.test.js,src/lodashFilters.test.js
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