forked from MapComplete/MapComplete
Add JSON-schema files
This commit is contained in:
parent
1511b0a167
commit
8e8340c7fe
25 changed files with 5632 additions and 5067 deletions
|
@ -1,14 +1,28 @@
|
|||
import ScriptUtils from "./ScriptUtils";
|
||||
import {readFileSync, writeFileSync} from "fs";
|
||||
|
||||
const allSchemas = ScriptUtils.readDirRecSync("./Docs/Schemas").filter(pth => pth.endsWith("JSC.ts"))
|
||||
|
||||
for (const path of allSchemas) {
|
||||
const dir = path.substring(0, path.lastIndexOf("/"))
|
||||
const name = path.substring(path.lastIndexOf("/"), path.length - "JSC.ts".length)
|
||||
let content = readFileSync(path, "UTF-8")
|
||||
content = content.substring("export default ".length)
|
||||
let parsed = JSON.parse(content)
|
||||
parsed["additionalProperties"] = false
|
||||
writeFileSync(dir+"/"+name+".schema.json", JSON.stringify(parsed, null, " "), "UTF8")
|
||||
}
|
||||
function main() {
|
||||
|
||||
const allSchemas = ScriptUtils.readDirRecSync("./Docs/Schemas").filter(pth => pth.endsWith("JSC.ts"))
|
||||
for (const path of allSchemas) {
|
||||
const dir = path.substring(0, path.lastIndexOf("/"))
|
||||
const name = path.substring(path.lastIndexOf("/"), path.length - "JSC.ts".length)
|
||||
let content = readFileSync(path, "UTF-8")
|
||||
content = content.substring("export default ".length)
|
||||
let parsed = JSON.parse(content)
|
||||
parsed["additionalProperties"] = false
|
||||
|
||||
for (const key in parsed.definitions) {
|
||||
const def = parsed.definitions[key]
|
||||
console.log("Patching ", key)
|
||||
if (def.type === "object") {
|
||||
def["additionalProperties"] = false
|
||||
}
|
||||
}
|
||||
|
||||
writeFileSync(dir + "/" + name + ".schema.json", JSON.stringify(parsed, null, " "), "UTF8")
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue