Skip to content

Commit 6601a3b

Browse files
authored
Merge pull request #18 from ran-huang/tag-group
add a script to group tags
2 parents 3f0ba0b + e4d7b82 commit 6601a3b

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ Embed external Markdown file contents to the `info.description` auto-generated J
5151
### Add `x-logo`
5252

5353
[`x-logo`](https://github.com/Redocly/redoc/blob/master/docs/redoc-vendor-extensions.md#x-logo) is a [vendor extension](https://swagger.io/specification/#specificationExtensions) from Redoc. It allows you to show a custom logo on the left upper corner of your redoc output.
54+
55+
### Add tag group
56+
57+
Add an `x-tagGroups` field to the auto-generated JSON file and group all tags under that a specified tag. This field is a Redoc vendor extension. See [Redoc documentation](https://redocly.com/docs/redoc/redoc-vendor-extensions/#x-taggroups) for more information.

src/grouptag.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fs = require("fs");
2+
3+
function groupTag(json_file, tag_group) {
4+
const schema = JSON.parse(fs.readFileSync(json_file, 'utf8'));
5+
const tags = schema["tags"].map(tag => tag["name"]);
6+
7+
schema["x-tagGroups"] = [ {"name":tag_group, "tags": tags} ]
8+
9+
fs.writeFileSync(json_file, JSON.stringify(schema, null, 2));
10+
console.log(`Group all tags in the ${tag_group} tag group.`);
11+
}
12+
13+
module.exports = groupTag;

src/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const addLogo = require("./addlogo.js");
66
const genSampleCode = require("./gencode.js");
77
const devTier = require("./devTier.js");
88
const replaceInteger = require("./replaceint.js");
9+
const groupTag = require("./grouptag.js");
910

1011
const program = new Command();
1112
program
@@ -43,4 +44,9 @@ program.command("replaceint")
4344
.argument("<in-filename>", "Input JSON file")
4445
.argument("[out-filename]", "Output JSON file. If not specified, use in-filename.")
4546
.action(replaceInteger);
47+
program.command("grouptag")
48+
.description("Group all tags in a tag group")
49+
.argument("<in-filename>", "Input JSON file")
50+
.argument("<tag-group>", "Tag group name")
51+
.action(groupTag);
4652
program.parse();

0 commit comments

Comments
 (0)