Adding new tests for 2.0 version

This commit is contained in:
Erik Mendoza
2022-06-01 12:17:53 -05:00
parent 243c9a1dba
commit caf725e997
36 changed files with 1033 additions and 127 deletions

View File

@@ -4828,13 +4828,20 @@ module.exports = {
return data;
},
getBundledFileData(parsedRootFiles, inputData, origin, format) {
getBundledFileData(parsedRootFiles, inputData, origin, format, version) {
const data = parsedRootFiles.map((root) => {
let bundleData = getBundleContentAndComponents(root, inputData, origin);
let bundleData = getBundleContentAndComponents(root, inputData, origin, version);
return bundleData;
});
let bundledFile = data[0].fileContent;
bundledFile.components = data[0].components;
if (version === '2.0') {
Object.entries(data[0].components).forEach(([key, value]) => {
bundledFile[key] = value;
});
}
else {
bundledFile.components = data[0].components;
}
if (format === parse.YAML_FORMAT) {
bundledFile = parse.toYAML(bundledFile);
}
@@ -4863,11 +4870,14 @@ module.exports = {
let parsedContent = this.parseFileOrThrow(rootFile.content);
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
}).filter((rootWithParsedContent) => {
let fileVersion = version === '2.0' ?
rootWithParsedContent.parsed.oasObject.swagger :
rootWithParsedContent.parsed.oasObject.openapi;
bundleFormat = bundleFormat ? bundleFormat : rootWithParsedContent.parsed.inputFormat;
return compareVersion(version, rootWithParsedContent.parsed.oasObject.openapi);
return compareVersion(version, fileVersion);
}),
data = toBundle ?
this.getBundledFileData(parsedRootFiles, inputData, origin, bundleFormat.toLowerCase()) :
this.getBundledFileData(parsedRootFiles, inputData, origin, bundleFormat.toLowerCase(), version) :
this.getRelatedFilesData(parsedRootFiles, inputData, origin);
return data;