Refactor, cleaning and adding new test scenarios

- adding support for not provided nodes in input.
- adding support to bringing local dependencies in references from external references content
- bundle getReferences method tests
- Adding a new type of error to catch parsing errors and handle
This commit is contained in:
Erik Mendoza
2022-05-29 00:03:36 -05:00
parent 9a453e72cd
commit 088edba128
18 changed files with 547 additions and 136 deletions

View File

@@ -3,6 +3,8 @@
* utils.js contains other util functions
*/
const { ParseError } = require('./common/ParseError.js');
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
async = require('async'),
@@ -90,7 +92,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
{ getRelatedFiles } = require('./relatedFiles'),
{ compareVersion } = require('./common/versionUtils.js'),
parse = require('./parse'),
{ getRelatedFilesAndBundleData } = require('./bundle.js');
{ getBundleContentAndComponents } = require('./bundle.js');
/* eslint-enable */
// See https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options
@@ -4828,7 +4830,7 @@ module.exports = {
getBundledFileData(parsedRootFiles, inputData, origin, format) {
const data = parsedRootFiles.map((root) => {
let bundleData = getRelatedFilesAndBundleData(root, inputData, origin);
let bundleData = getBundleContentAndComponents(root, inputData, origin);
return bundleData;
});
let bundledFile = data[0].fileContent;
@@ -4858,7 +4860,7 @@ module.exports = {
mapProcessRelatedFiles(rootFiles, inputData, origin, version, format, toBundle = false) {
let bundleFormat = format,
parsedRootFiles = rootFiles.map((rootFile) => {
let parsedContent = parse.getOasObject(rootFile.content);
let parsedContent = this.parseFileOrThrow(rootFile.content);
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
}).filter((rootWithParsedContent) => {
bundleFormat = bundleFormat ? bundleFormat : rootWithParsedContent.parsed.inputFormat;
@@ -4895,13 +4897,38 @@ module.exports = {
}
};
if (inputRelatedFiles.rootFiles && inputRelatedFiles.rootFiles.length > 0) {
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
inputRelatedFiles.origin, version, inputRelatedFiles.bundleFormat, toBundle);
try {
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
inputRelatedFiles.origin, version, inputRelatedFiles.bundleFormat, toBundle);
}
catch (error) {
if (error instanceof ParseError) {
return {
result: false,
reason: error.message
};
}
else {
throw (error);
}
}
if (res.output.data.result === false) {
res.result = res.output.data.result;
res.error = res.output.data.error;
}
return res;
}
else {
return res;
}
},
parseFileOrThrow(fileContent) {
const result = parse.getOasObject(fileContent);
if (result.result === false) {
throw new ParseError(result.reason);
}
return result;
}
};