From 5117f387e9639db5bf4cfd409ad10c2a4fdb1f59 Mon Sep 17 00:00:00 2001 From: Ran Date: Thu, 14 Jul 2022 11:20:10 +0800 Subject: [PATCH 1/3] add a script to add logo to json Signed-off-by: Ran --- src/addlogo.js | 15 +++++++++++++++ src/main.js | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/addlogo.js diff --git a/src/addlogo.js b/src/addlogo.js new file mode 100644 index 0000000..1647d13 --- /dev/null +++ b/src/addlogo.js @@ -0,0 +1,15 @@ +const fs = require("fs"); + +function addLogo(file, url, alt, href) { + const schema = JSON.parse(fs.readFileSync(file, 'utf8')); + schema["info"]["x-logo"] = { + "url": url, + "backgroundColor": "#FFFFFF", + "altText": alt, + "href": href, + }; + fs.writeFileSync(file, JSON.stringify(schema, null, 2)); + console.log(`Add logo to ${file}`); +} + +module.exports = addLogo; diff --git a/src/main.js b/src/main.js index 03b9a69..10b299b 100644 --- a/src/main.js +++ b/src/main.js @@ -2,6 +2,7 @@ const { Command } = require("commander"); const deref = require("./deref.js"); const importMd = require("./importmd.js"); +const addLogo = require("./addlogo.js"); const program = new Command(); program @@ -18,5 +19,12 @@ program.command("importMd") .argument("", "Target JSON file") .argument("", "markdown path to ref") .action(importMd); +program.command("addLogo") + .description("Add a logo to JSON info.x-logo") + .argument("", "Target JSON file") + .argument("", "Logo absolute url") + .argument("", "Logo alt text") + .argument("", "Logo href") + .action(addLogo); program.parse(); From 948a9d583dfdbd439b929fc02ab69cb39f87d085 Mon Sep 17 00:00:00 2001 From: Ran Date: Thu, 14 Jul 2022 11:30:37 +0800 Subject: [PATCH 2/3] update readme Signed-off-by: Ran --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 18304ad..4ded7b7 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,7 @@ Use [@apidevtools/json-schema-ref-parser](https://github.com/APIDevTools/json-sc ToDo ### Convert string to int for int32 type in `.proto` ToDo + +### 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. \ No newline at end of file From 15a599a4ce55730991762454124d1d7de231a9f1 Mon Sep 17 00:00:00 2001 From: Ran Date: Thu, 14 Jul 2022 11:45:48 +0800 Subject: [PATCH 3/3] use lowercase for subcommands; update readme Signed-off-by: Ran --- README.md | 6 +++++- src/main.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4ded7b7..9991f96 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ ToDo ### Convert string to int for int32 type in `.proto` ToDo +### Import markown files + +Embed external Markdown file contents to the `info.description` auto-generated JSON file. See [Redoc documentation](https://redocly.com/docs/api-reference-docs/guides/embedded-markdown/) for more information. + ### 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. \ No newline at end of file +[`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. diff --git a/src/main.js b/src/main.js index 10b299b..b3ad8e9 100644 --- a/src/main.js +++ b/src/main.js @@ -14,12 +14,12 @@ program.command("deref") .argument("", "Input JSON file") .argument("[out-filename]", "Output JSON file. If not specified, use in-filename.") .action(deref); -program.command("importMd") +program.command("importmd") .description("Add a markdown $Ref to JSON info.description") .argument("", "Target JSON file") .argument("", "markdown path to ref") .action(importMd); -program.command("addLogo") +program.command("addlogo") .description("Add a logo to JSON info.x-logo") .argument("", "Target JSON file") .argument("", "Logo absolute url")