Take format from root

take the format of each root when the option for the process is not present
This commit is contained in:
Luis Tejeda
2022-06-09 11:46:23 -05:00
parent fcf43811d0
commit 775682b7c3
4 changed files with 110 additions and 71 deletions

View File

@@ -4839,8 +4839,32 @@ module.exports = {
return data;
},
/**
* Maps the output for each bundled root file
* @param {object} format - defined output format from options
* @param {string} parsedRootFiles - specified version of the process
* @returns {object} - { rootFile: { path }, bundledContent }
*/
mapBundleOutput(format, parsedRootFiles) {
return (contentAndComponents) => {
let bundledFile = contentAndComponents.fileContent;
bundledFile.components = contentAndComponents.components;
if (!format) {
let rootFormat = parsedRootFiles.find((inputRoot) => {
return inputRoot.fileName === contentAndComponents.fileName;
}).parsed.inputFormat;
if (rootFormat.toLowerCase() === parse.YAML_FORMAT) {
bundledFile = parse.toYAML(bundledFile);
}
}
else if (format.toLowerCase() === parse.YAML_FORMAT) {
bundledFile = parse.toYAML(bundledFile);
}
return { rootFile: { path: parsedRootFiles[0].fileName }, bundledContent: bundledFile };
};
},
/*
*
* @description Takes in parsed root files and bundle it
* @param {object} parsedRootFiles - found parsed root files
* @param {array} inputData - file data information [{path, content}]
@@ -4856,14 +4880,7 @@ module.exports = {
return bundleData;
});
let bundleData = data.map((contentAndComponents) => {
let bundledFile = contentAndComponents.fileContent;
bundledFile.components = contentAndComponents.components;
if (format === parse.YAML_FORMAT) {
bundledFile = parse.toYAML(bundledFile);
}
return { rootFile: { path: parsedRootFiles[0].fileName }, bundledContent: bundledFile };
});
let bundleData = data.map(this.mapBundleOutput(format, parsedRootFiles));
return bundleData;
},
@@ -4887,11 +4904,11 @@ module.exports = {
let parsedContent = this.parseFileOrThrow(rootFile.content);
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
}).filter((rootWithParsedContent) => {
bundleFormat = bundleFormat ? bundleFormat : rootWithParsedContent.parsed.inputFormat;
// bundleFormat = bundleFormat ? bundleFormat : rootWithParsedContent.parsed.inputFormat;
return compareVersion(version, rootWithParsedContent.parsed.oasObject.openapi);
}),
data = toBundle ?
this.getBundledFileData(parsedRootFiles, inputData, origin, bundleFormat.toLowerCase()) :
this.getBundledFileData(parsedRootFiles, inputData, origin, bundleFormat) :
this.getRelatedFilesData(parsedRootFiles, inputData, origin);
return data;