diff --git a/README.md b/README.md index 18304ad..9991f96 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,11 @@ Use [@apidevtools/json-schema-ref-parser](https://github.com/APIDevTools/json-sc 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. 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..b3ad8e9 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 @@ -13,10 +14,17 @@ 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") + .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();