Skip to content

Commit e0bd3eb

Browse files
feat: Add flag to use operations tags instead of root tags for the sidebar (#44)
1 parent 088f5c1 commit e0bd3eb

File tree

11 files changed

+1195
-183
lines changed

11 files changed

+1195
-183
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ npm install -g @asyncapi/generator
1919

2020
|Name|Description|Required|Allowed values|Example|
2121
|---|---|---|---|---|
22-
|sidebarOrganization|Defines how the sidebar should be organized. Set its value to 'byTags' to categorize operations by tags.|No|`byTags`|`byTags`|
22+
|sidebarOrganization|Defines how the sidebar should be organized. Set its value to `byTagsNoRoot` to categorize operations by operations tags. Set its value to `byTags` when you have tags on a root level. These tags are used to model tags navigation and need to have the same tags in operations.|No|`byTags`, `byTagsNoRoot`|`byTagsNoRoot`|
2323
|baseHref|Sets the base URL for links and forms.|No|*Any*|`/docs`|
2424

2525
## Development
@@ -49,4 +49,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
4949
<!-- prettier-ignore-end -->
5050
<!-- ALL-CONTRIBUTORS-LIST:END -->
5151

52-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
52+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

filters/all.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
const filter = module.exports;
22

33
function isExpandable(obj) {
4+
const fun = (obj) => typeof obj === "function";
45
if (
5-
(typeof obj.type === "function" && obj.type() === "object") ||
6-
(typeof obj.type === "function" && obj.type() === "array") ||
7-
(typeof obj.oneOf === "function" && obj.oneOf() && obj.oneOf().length) ||
8-
(typeof obj.anyOf === "function" && obj.anyOf() && obj.anyOf().length) ||
9-
(typeof obj.allOf === "function" && obj.allOf() && obj.allOf().length) ||
10-
(typeof obj.items === "function" && obj.items()) ||
11-
(typeof obj.additionalItems === "function" && obj.additionalItems()) ||
12-
(typeof obj.properties === "function" && obj.properties() && Object.keys(obj.properties()).length) ||
13-
(typeof obj.additionalProperties === "function" && obj.additionalProperties()) ||
14-
(typeof obj.extensions === "function" && obj.extensions() &&
6+
(fun(obj.type) && obj.type() === "object") ||
7+
(fun(obj.type) && obj.type() === "array") ||
8+
(fun(obj.oneOf) && obj.oneOf() && obj.oneOf().length) ||
9+
(fun(obj.anyOf) && obj.anyOf() && obj.anyOf().length) ||
10+
(fun(obj.allOf) && obj.allOf() && obj.allOf().length) ||
11+
(fun(obj.items) && obj.items()) ||
12+
(fun(obj.additionalItems) && obj.additionalItems()) ||
13+
(fun(obj.properties) && obj.properties() && Object.keys(obj.properties()).length) ||
14+
(fun(obj.additionalProperties) && obj.additionalProperties()) ||
15+
(fun(obj.extensions) && obj.extensions() &&
1516
Object.keys(obj.extensions()).filter(e => !e.startsWith("x-parser-")).length) ||
16-
(typeof obj.patternProperties === "function" && obj.patternProperties())
17+
(fun(obj.patternProperties) && obj.patternProperties())
1718
) return true;
1819

1920
return false;
@@ -48,7 +49,9 @@ function containTags(object, tagsToCheck) {
4849
let found = false;
4950
for (let tagToCheckIndex in tagsToCheck) {
5051
let tagToCheck = tagsToCheck[tagToCheckIndex]._json;
51-
if (tagToCheck.name === tag.name) {
52+
let tagName = tag.name;
53+
if ((tagToCheck && tagToCheck.name === tagName) ||
54+
tagsToCheck[tagToCheckIndex] === tagName) {
5255
found = true;
5356
}
5457
}
@@ -83,7 +86,9 @@ function containNoTag(channels, tagsToCheck) {
8386
let found = false;
8487
for (let tagToCheckIndex in tagsToCheck) {
8588
let tagToCheck = tagsToCheck[tagToCheckIndex]._json;
86-
if (tagToCheck.name === tag.name) {
89+
let tagName = tag.name;
90+
if ((typeof tagToCheck !== 'undefined' && tagToCheck.name === tagName) ||
91+
tagsToCheck[tagToCheckIndex] === tagName) {
8792
found = true;
8893
}
8994
}
@@ -99,3 +104,15 @@ function containNoTag(channels, tagsToCheck) {
99104
return false;
100105
};
101106
filter.containNoTag = containNoTag;
107+
108+
function operationsTags(object) {
109+
let tags = new Set();
110+
const extractName = (tags, acc) => tags.forEach((tag) => acc.add(tag.name()));
111+
object.channelNames().forEach(channelName => {
112+
let channel = object.channel(channelName);
113+
if (channel.hasPublish() && channel.publish().hasTags()) extractName(channel.publish().tags(), tags);
114+
if (channel.hasSubscribe() && channel.subscribe().hasTags()) extractName(channel.subscribe().tags(), tags);
115+
});
116+
return Array.from(tags);
117+
}
118+
filter.operationsTags = operationsTags;

0 commit comments

Comments
 (0)