UNPKG

@microsoft.azure/autorest.testserver

Version:
45 lines 1.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPathsFromSpecs = void 0; const fs_1 = __importDefault(require("fs")); const logger_1 = require("../logger"); const getPathsFromSpecs = async (specPaths) => { let paths = []; for (const specPath of specPaths) { paths = paths.concat(await getPathsFromSpec(specPath)); } return paths; }; exports.getPathsFromSpecs = getPathsFromSpecs; const getPathsFromSpec = async (specPath) => { logger_1.logger.debug(`Parsing spec ${specPath}`); const json = await parseSpec(specPath); return json.paths && typeof json.paths === "object" ? parseOpenAPIPath(json.paths) : []; }; const parseOpenAPIPath = (paths) => { return Object.entries(paths) .map(([path, content]) => { return { path, methods: content && typeof content === "object" ? Object.keys(content) : [], }; }) .filter((x) => x.methods.length > 0); }; const parseSpec = async (specPath) => { const content = await fs_1.default.promises.readFile(specPath); try { const json = JSON.parse(content.toString().replace(/^\uFEFF/, "")); if (typeof json !== "object") { throw new Error(`Spec ${specPath} is not valid, should be an json object.`); } return json; } catch (e) { throw new Error(`Spec ${specPath} is not valid json, ${e}`); } }; //# sourceMappingURL=spec-coverage-service.js.map