@apistudio/apim-cli
Version:
CLI for API Management Products
29 lines (28 loc) • 1.06 kB
JavaScript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import JSZip from 'jszip';
import yaml from 'js-yaml';
import { addErrorToResponse } from '../helpers/helper.js';
import { LogWrapper } from '../service/log-wrapper.js';
export class YamlValidator {
async validateYamlFiles(buffer) {
const zip = new JSZip();
let allValid = true;
const zipContent = await zip.loadAsync(buffer);
for (const [fileName, file] of Object.entries(zipContent.files)) {
if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
const content = await file.async('string');
try {
yaml.loadAll(content);
}
catch (err) {
addErrorToResponse('STU-VAL_ERR', 'YAML_FILE', `Invalid YAML in file ${fileName}:${err}`);
LogWrapper.logError('0003', `Invalid YAML in file ${fileName}:${err}`);
allValid = false;
}
}
}
return allValid;
}
}