UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

41 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeSchema = exports.getSchema = exports.getSchemaPath = void 0; const flagpole_execution_1 = require("../flagpole-execution"); const fs_extra_1 = require("fs-extra"); const path_1 = require("path"); const json_to_jtd_1 = require("@flagpolejs/json-to-jtd"); const json_to_jsonschema_1 = require("@flagpolejs/json-to-jsonschema"); function getSchemaPath(schemaName) { let path; if (schemaName.startsWith("@") && schemaName.length > 1) { const schemasFolder = flagpole_execution_1.FlagpoleExecution.global.config.getSchemasFolder(); if (!schemasFolder) { throw "Flagpole schema folder path not found."; } fs_extra_1.ensureDirSync(schemasFolder); path = path_1.resolve(schemasFolder, `${schemaName.substr(1)}.json`); } else { path = path_1.resolve(schemaName); } fs_extra_1.ensureFileSync(path); return path; } exports.getSchemaPath = getSchemaPath; function getSchema(schemaName) { const schemaPath = getSchemaPath(schemaName); if (fs_extra_1.existsSync(schemaPath)) { const content = fs_extra_1.readFileSync(schemaPath, "utf8"); return JSON.parse(content); } throw `Schema file ${schemaPath} does not exist`; } exports.getSchema = getSchema; function writeSchema(json, schemaName, schemaType) { const schema = schemaType == "JsonSchema" ? json_to_jsonschema_1.default(json) : json_to_jtd_1.default(json); fs_extra_1.writeFileSync(getSchemaPath(schemaName), JSON.stringify(schema, null, 2)); return schema; } exports.writeSchema = writeSchema; //# sourceMappingURL=assertion-schema.js.map