diff --git a/README.md b/README.md index c20d0bf..2df9135 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/grouptag.js b/src/grouptag.js new file mode 100644 index 0000000..4bc5ef8 --- /dev/null +++ b/src/grouptag.js @@ -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; diff --git a/src/main.js b/src/main.js index f392d43..2841760 100644 --- a/src/main.js +++ b/src/main.js @@ -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 @@ -43,4 +44,9 @@ program.command("replaceint") .argument("", "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("", "Input JSON file") + .argument("", "Tag group name") + .action(groupTag); program.parse();