openapi-graph-core
Version:
A TS library to manage large API projects defined by OpenAPIv3 specification.
24 lines (23 loc) • 811 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOpenApisContent = void 0;
const fs_1 = require("fs");
const js_yaml_1 = require("js-yaml");
const logger = require('pino')({
prettyPrint: {
ignore: 'time,pid,hostname',
singleLine: true
}
});
/**
* reads the contents of all given paths. The files will be validated.
*
* @param paths of the .yaml|.yml files. The paths should exists.
* @returns the contents of the files as JSON with their path
*/
async function getOpenApisContent(paths) {
return (paths
.map(p => ({ path: p, content: js_yaml_1.load(fs_1.readFileSync(p, 'utf8')) || logger.warn(`Couldn't load ${p}`) }))
.filter(p => p.content?.openapi?.includes("3.0")));
}
exports.getOpenApisContent = getOpenApisContent;