Commit bcab9e41 authored by David Sveningsson's avatar David Sveningsson

feat(elements): make schema publicly accessible

parent 448c52d0
......@@ -7,6 +7,7 @@ module.exports = new Package("html-validate-docs", [
require("dgeni-packages/nunjucks"),
require("./highlight"),
require("./inline-validate"),
require("./schema"),
])
.processor(require("./processors/rules"))
......@@ -44,7 +45,8 @@ module.exports = new Package("html-validate-docs", [
log,
readFilesProcessor,
templateFinder,
writeFilesProcessor
writeFilesProcessor,
copySchema
) {
log.level = "info";
......@@ -62,6 +64,9 @@ module.exports = new Package("html-validate-docs", [
},
];
copySchema.outputFolder = "public/schemas";
copySchema.files = ["elements/elements.json"];
writeFilesProcessor.outputFolder = "public";
})
......
const Package = require("dgeni").Package;
module.exports = new Package("schema", [])
.processor(require("./processors/copy-schema-processor"))
.factory(require("./services/copy-schema"));
const path = require("path");
const fs = require("fs");
const mkdirp = require("mkdirp");
module.exports = function copySchemaProcessor(copySchema, readFilesProcessor) {
return {
$runBefore: ["extra-docs-added"],
$process,
};
function $process() {
const root = readFilesProcessor.basePath;
const outputFolder = path.join(root, copySchema.outputFolder, "schemas");
mkdirp.sync(outputFolder);
for (const src of copySchema.files) {
const name = path.basename(src);
fs.copyFileSync(path.join(root, src), path.join(outputFolder, name));
}
}
};
module.exports = function copySchema() {
return {
outputFolder: "",
files: [],
};
};
{
"$id": "https://html-validate.org/schemas/metadata.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://html-validate.org/schemas/elements.json",
"version": "1.0",
"type": "object",
"patternProperties": {
"^.*$": {
......
......@@ -41,7 +41,7 @@ export class MetaTable {
public constructor() {
this.elements = {};
this.schema = clone(require("../../elements/schema.json"));
this.schema = clone(require("../../elements/elements.json"));
}
public init(): void {
......@@ -76,6 +76,7 @@ export class MetaTable {
filename: string | null = null
): void {
const ajv = new Ajv({ jsonPointers: true });
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"));
const validator = ajv.compile(this.schema);
const valid = validator(obj);
if (!valid) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment