From 726dfefd3bb5dd320bd0aacdc239e70179a89080 Mon Sep 17 00:00:00 2001 From: Ran Date: Mon, 8 Aug 2022 21:16:19 +0800 Subject: [PATCH 1/3] add a script to group tags Signed-off-by: Ran --- src/grouptag.js | 18 ++++++++++++++++++ src/main.js | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 src/grouptag.js diff --git a/src/grouptag.js b/src/grouptag.js new file mode 100644 index 0000000..d5777fc --- /dev/null +++ b/src/grouptag.js @@ -0,0 +1,18 @@ +const fs = require("fs"); + +function groupTag(json_file, tag_group) { + const schema = JSON.parse(fs.readFileSync(json_file, 'utf8')); + const tags = []; + + // iterate through schema["tags"] + for (let i = 0; i < schema["tags"].length; i++) { + tags.push(schema["tags"][i]["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(); From 822d1cafb6178fb3aedce448c235b45c8fbb94ce Mon Sep 17 00:00:00 2001 From: Ran Date: Mon, 8 Aug 2022 21:23:59 +0800 Subject: [PATCH 2/3] use map Signed-off-by: Ran --- src/grouptag.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/grouptag.js b/src/grouptag.js index d5777fc..4bc5ef8 100644 --- a/src/grouptag.js +++ b/src/grouptag.js @@ -2,12 +2,7 @@ const fs = require("fs"); function groupTag(json_file, tag_group) { const schema = JSON.parse(fs.readFileSync(json_file, 'utf8')); - const tags = []; - - // iterate through schema["tags"] - for (let i = 0; i < schema["tags"].length; i++) { - tags.push(schema["tags"][i]["name"]); - } + const tags = schema["tags"].map(tag => tag["name"]); schema["x-tagGroups"] = [ {"name":tag_group, "tags": tags} ] From e4d7b82c2dd56728828b243e4db4eefce69fa895 Mon Sep 17 00:00:00 2001 From: Ran Date: Mon, 8 Aug 2022 21:31:46 +0800 Subject: [PATCH 3/3] update readme Signed-off-by: Ran --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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.