Skip to content

Commit 72ac58d

Browse files
authored
Merge pull request #7 from Oreoxmt/importmd-support-megefiles
import md from folder
2 parents 551eda4 + 2ea52e7 commit 72ac58d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/importmd.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const fs = require("fs");
22

3-
function importMd(file, path) {
4-
const schema = JSON.parse(fs.readFileSync(file, 'utf8'));
5-
schema["info"]["description"] = { $ref: path };
6-
fs.writeFileSync(file, JSON.stringify(schema, null, 2));
7-
console.log(`Add \$Ref of ${path} to ${file}`);
3+
function importMd(json_file, md_folder, des_file) {
4+
const schema = JSON.parse(fs.readFileSync(json_file, 'utf8'));
5+
const description = fs.readdirSync(md_folder).sort().map(
6+
(filename) => fs.readFileSync(`${md_folder}/${filename}`)
7+
).join("\n");
8+
fs.writeFileSync(des_file, description, "utf8");
9+
schema["info"]["description"] = { $ref: des_file };
10+
fs.writeFileSync(json_file, JSON.stringify(schema, null, 2));
11+
console.log(`Add \$Ref of ${md_folder} to ${json_file}`);
812
}
913

1014
module.exports = importMd;

src/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ const program = new Command();
88
program
99
.name("postprocess")
1010
.description("Postprocess an OpenAPI document for ReDoc")
11-
.version("0.1.0");
11+
.version("0.3.0");
1212
program.command("deref")
1313
.description("Use $RefParser to dereference a JSON schema")
1414
.argument("<in-filename>", "Input JSON file")
1515
.argument("[out-filename]", "Output JSON file. If not specified, use in-filename.")
1616
.action(deref);
1717
program.command("importmd")
18-
.description("Add a markdown $Ref to JSON info.description")
18+
.description("Merge markdown files in <md-folder> to a markdown <gen-file>, and import it as $ref to JSON info.description.")
1919
.argument("<in-filename>", "Target JSON file")
20-
.argument("<path>", "markdown path to ref")
20+
.argument("<md-folder>", "Folder of markdown files to import")
21+
.argument("<gen-md>", "Merged markdown files")
2122
.action(importMd);
2223
program.command("addlogo")
2324
.description("Add a logo to JSON info.x-logo")

0 commit comments

Comments
 (0)