Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 15 additions & 0 deletions src/addlogo.js
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 9 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,10 +14,17 @@ program.command("deref")
.argument("<in-filename>", "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("<in-filename>", "Target JSON file")
.argument("<path>", "markdown path to ref")
.action(importMd);
program.command("addlogo")
.description("Add a logo to JSON info.x-logo")
.argument("<in-filename>", "Target JSON file")
.argument("<url>", "Logo absolute url")
.argument("<alt>", "Logo alt text")
.argument("<href>", "Logo href")
.action(addLogo);

program.parse();