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: 7 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const genSampleCode = require("./gencode.js");
const patch = require("./patch.js");
const replaceInteger = require("./replaceint.js");
const groupTag = require("./grouptag.js");
const replaceBool = require("./replacebool.js");

const program = new Command();
program
Expand All @@ -32,7 +33,7 @@ program.command("patch")
.argument("<patch-filename>", "Patch file")
.argument("<in-filename", "Target JSON file")
.argument("[out-filename]", "Output JSON file. If not specified, use in-filename.")
.action(patch)
.action(patch);
program.command("replaceint")
.description("Replace the example and default value of integer type to number type")
.argument("<in-filename>", "Input JSON file")
Expand All @@ -43,4 +44,9 @@ program.command("grouptag")
.argument("<in-filename>", "Input JSON file")
.argument("<tag-group>", "Tag group name")
.action(groupTag);
program.command("replacebool")
.description("Remove the quotation marks around bool value")
.argument("<in-filename>", "Input JSON file")
.argument("[out-filename]", "Output JSON file. If not specified, use in-filename.")
.action(replaceBool);
program.parse();
28 changes: 28 additions & 0 deletions src/replacebool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require("fs");

function removeQuotationInBool(obj) {
for (let item in obj) {
if (obj[item] instanceof Object) {
removeQuotationInBool(obj[item]);
}
else if (item == "type" && obj[item] === "boolean") {
if (obj["example"] != undefined && typeof obj["example"] != "boolean") {
obj["example"] = obj["example"] === "true" ? true : false;
}
if (obj["default"] != undefined && typeof obj["default"] != "boolean") {
obj["default"] = obj["default"] === "true" ? true : false;
}
}
}
return obj;
}

async function replaceBool(readf, writef) {
writef = writef || readf;
const data = JSON.parse(fs.readFileSync(readf, 'utf8'));
const schema = removeQuotationInBool(data);
fs.writeFileSync(writef, JSON.stringify(schema, null, 2));
console.log(`Remove quotation marks around boolean value in ${writef}`);
}

module.exports = replaceBool;