objection-swagger
Version:
Originally designed as Swagger definition generator for Objection.js models. Since then scope was extended to also cover Swagger-compatible snippets generation from plain JSON Schema entries as well as set of conversions that are useful for model and sche
33 lines (29 loc) • 841 B
JavaScript
const fs = require('fs');
const { promisify } = require('es6-promisify');
const writeFileAsync = promisify(fs.writeFile);
/**
* @param {GeneratedSwaggerYaml[]} yamlSchemaContainers
* @param {string} targetDir
* @param {Options} [opts]
* @returns {Promise<void>}
*/
function writeYamlsToFs(yamlSchemaContainers, targetDir, opts = {}) {
const writeEntries = yamlSchemaContainers.map((yamlSchemaContainer) => {
const suffix = opts.useSuffix || '';
return {
targetFile: `${targetDir}/${yamlSchemaContainer.name}${suffix}.yaml`,
data: yamlSchemaContainer.schema,
};
});
return _writeAllAsync(writeEntries);
}
function _writeAllAsync(entries) {
return Promise.all(
entries.map((entry) => {
return writeFileAsync(entry.targetFile, entry.data);
})
);
}
module.exports = {
writeYamlsToFs,
};