Skip to content

Commit

Permalink
Merge pull request #18 from ran-huang/tag-group
Browse files Browse the repository at this point in the history
add a script to group tags
  • Loading branch information
Oreoxmt authored Aug 9, 2022
2 parents 3f0ba0b + e4d7b82 commit 6601a3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ Embed external Markdown file contents to the `info.description` auto-generated J
### Add `x-logo`

[`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.

### Add tag group

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.
13 changes: 13 additions & 0 deletions src/grouptag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require("fs");

function groupTag(json_file, tag_group) {
const schema = JSON.parse(fs.readFileSync(json_file, 'utf8'));
const tags = schema["tags"].map(tag => tag["name"]);

schema["x-tagGroups"] = [ {"name":tag_group, "tags": tags} ]

fs.writeFileSync(json_file, JSON.stringify(schema, null, 2));
console.log(`Group all tags in the ${tag_group} tag group.`);
}

module.exports = groupTag;
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const addLogo = require("./addlogo.js");
const genSampleCode = require("./gencode.js");
const devTier = require("./devTier.js");
const replaceInteger = require("./replaceint.js");
const groupTag = require("./grouptag.js");

const program = new Command();
program
Expand Down Expand Up @@ -43,4 +44,9 @@ program.command("replaceint")
.argument("<in-filename>", "Input JSON file")
.argument("[out-filename]", "Output JSON file. If not specified, use in-filename.")
.action(replaceInteger);
program.command("grouptag")
.description("Group all tags in a tag group")
.argument("<in-filename>", "Input JSON file")
.argument("<tag-group>", "Tag group name")
.action(groupTag);
program.parse();

0 comments on commit 6601a3b

Please sign in to comment.