Skip to content

Commit dd940e5

Browse files
committed
Bugfixes and additional config
* Fixes #2 * Adds new optional config, `hierarchicalTagSeparator` (defaults to `/[:|]`
1 parent 7388365 commit dd940e5

File tree

9 files changed

+11652
-2074
lines changed

9 files changed

+11652
-2074
lines changed

package-lock.json

Lines changed: 10727 additions & 2042 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hierarchical-tags/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,28 @@ SwaggerUI({
101101

102102
## Hierarchical Tags Plugin Options
103103

104-
There are no additional options for this plugin. If the plugin is included on initialization, then
105-
it is enabled and will split tags on any colon (`:`) or pipe (`|`) character.
104+
* `hierarchicalTagSeparator` - (Optional, defaults to `/[|:]/`) The separator character(s) on which to split
105+
hierarchical tags. Can be any string or regexp.
106106

107107

108108
## Development
109109

110+
111+
### Live-Testing Development
112+
113+
1. Clone this repo, cd into `packages/hierarchical-tags` and `npm install`
114+
2. Run `npm start` - this starts a simple development web server that serves the files under the `example` directory.
115+
116+
From here, you should be able to go to `http://localhost:8080` in your browser and see the sample Pet Store API with
117+
hierarchical tags active. You can mess around with the `example/pet-store.json` and `example/index.html` files to try
118+
different inputs.
119+
120+
When you change the source code, just run `npm run build` to rebuild the plugin file in the `example` folder and reload
121+
the page.
122+
123+
124+
### Publishing
125+
110126
(This is more of a note-to-self.)
111127

112128
To publish the github package, simply bump the version and run `npm publish`.

packages/hierarchical-tags/example/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
],
1818
plugins: [
1919
HierarchicalTagsPlugin
20-
]
20+
],
21+
22+
//
23+
// Hierarchical tags config
24+
//
25+
26+
// (Optional)
27+
hierarchicalTagSeparator: '|',
2128
});
2229
}
2330
</script>

packages/hierarchical-tags/example/plugin.js

Lines changed: 869 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hierarchical-tags/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hierarchical-tags/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-ui-plugin-hierarchical-tags",
3-
"version": "1.0.2",
3+
"version": "1.0.4",
44
"description": "Display endpoints grouped into a hierarchy based on delimited tag names",
55
"author": "Kael Shipman<kael.shipman@gmail.com>",
66
"homepage": "https://github.com/kael-shipman/swagger-ui-plugins/tree/hierarchical-tags",

packages/hierarchical-tags/src/HierarchicalOperationTag.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export class HierarchicalOperationTag extends React.Component {
5353
tagObj,
5454
tag,
5555
childTags,
56-
children,
5756
oas3Selectors,
5857
layoutSelectors,
5958
layoutActions,
@@ -86,8 +85,9 @@ export class HierarchicalOperationTag extends React.Component {
8685
? buildUrl(rawTagExternalDocsUrl, specUrl, { selectedServer: oas3Selectors.selectedServer() })
8786
: rawTagExternalDocsUrl;
8887
const operations = tagObj ? tagObj.get("operations") : Im.fromJS({});
88+
const canonicalTagName = tagObj && tagObj.get("canonicalTagName") || tag;
8989

90-
const isShownKey = ["operations-tag", tag]
90+
const isShownKey = ["operations-tag", canonicalTagName]
9191
const showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")
9292

9393
return (
@@ -96,7 +96,7 @@ export class HierarchicalOperationTag extends React.Component {
9696
onClick={() => layoutActions.show(isShownKey, !showTag)}
9797
className={!tagDescription ? "opblock-tag no-desc" : "opblock-tag" }
9898
id={isShownKey.map(v => escapeDeepLinkPath(v)).join("-")}
99-
data-tag={tag}
99+
data-tag={canonicalTagName}
100100
data-is-open={showTag}
101101
>
102102
<DeepLink
@@ -188,7 +188,15 @@ export class HierarchicalOperationTag extends React.Component {
188188
} = this.props;
189189

190190
return (
191-
<div className="hierarchical-operation-tags" style={isRoot ? null : {margin: "0 0 0 2rem"}}>
191+
<div className="hierarchical-operation-tags" style={
192+
isRoot
193+
? null
194+
: {
195+
margin: "0 0 0 1.2rem",
196+
paddingLeft: "0.8rem",
197+
borderLeft: "1px solid #ccc"
198+
}
199+
}>
192200
{
193201
Object.entries(childTags).map(([ tag, data ]) => {
194202
return <HierarchicalOperationTag

packages/hierarchical-tags/src/HierarchicalOperations.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ export class HierarchicalOperations extends React.Component {
3737
// Get a flat map of tags to their set of operations
3838
let taggedOps = specSelectors.taggedOperations()
3939

40-
// Get the necessary components
41-
const OperationContainer = getComponent("OperationContainer", true)
40+
// Get the component we need
4241
const HierarchicalOperationTag = getComponent("HierarchicalOperationTag")
4342

4443
let {
4544
maxDisplayedTags,
45+
hierarchicalTagSeparator,
4646
} = getConfigs()
4747

48+
if (!hierarchicalTagSeparator) {
49+
hierarchicalTagSeparator = /[:|]/
50+
}
51+
4852
let filter = layoutSelectors.currentFilter()
4953

5054
if (filter) {
@@ -61,16 +65,18 @@ export class HierarchicalOperations extends React.Component {
6165
* Each taggedOperation is a tag with information and then some operations. All we need
6266
* to do is restructure this so that it reflects a hierarchical list instead of a flat
6367
* one.
68+
*
69+
* Existing structure:
6470
*
65-
* typeof taggedOps = Map<TagName: string, TagObj>;
66-
* TagObj = ?
71+
* type TagObj = unknown;
72+
* type TaggedOps = Map<TagName: string, TagObj>;
6773
*
6874
* Need to transform into:
6975
*
7076
* type HierarchicalOperationTag = {
7177
* [TagName]: {
7278
* data: TagObj & { canonicalTagName: string };
73-
* childrTags: Array<HierarchicalOperationTag>;
79+
* childTags: Array<HierarchicalOperationTag>;
7480
* }
7581
* }
7682
*
@@ -80,10 +86,10 @@ export class HierarchicalOperations extends React.Component {
8086
taggedOps.map((data, tag) => {
8187
// Fill in canonicalTagName, if necessary
8288
if (!data.has("canonicalTagName")) {
83-
data.set("canonicalTagName", tag);
89+
data = data.set("canonicalTagName", tag.replace(hierarchicalTagSeparator, "_"));
8490
}
8591

86-
const parts = tag.split(/[:|]/);
92+
const parts = tag.split(hierarchicalTagSeparator);
8793
let current = tagHierarchy;
8894
for (let i = 0; i < parts.length; i++) {
8995
const part = parts[i];
@@ -95,7 +101,7 @@ export class HierarchicalOperations extends React.Component {
95101
}
96102
}
97103

98-
//if point of insert reached add operations and tag information to structure
104+
// if point of insert reached add operations and tag information to structure
99105
if (i === parts.length - 1) {
100106
current[part].data = data;
101107
}

packages/hierarchical-tags/src/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { HierarchicalOperationTag } from "./HierarchicalOperationTag";
4141
// Provide our classes raw for others
4242
HierarchicalOperations,
4343
HierarchicalOperationTag,
44+
// Override operations so it uses our component instead of the original
4445
operations: HierarchicalOperations,
4546
},
4647
}

0 commit comments

Comments
 (0)