Adding safe parsing to the node's content parsing

This commit is contained in:
Erik Mendoza
2022-06-02 14:29:03 -05:00
parent 462c4dfd14
commit c82d50ed8d
2 changed files with 19 additions and 14 deletions

View File

@@ -92,7 +92,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
{ getRelatedFiles } = require('./relatedFiles'),
{ compareVersion } = require('./common/versionUtils.js'),
parse = require('./parse'),
{ getBundleContentAndComponents } = require('./bundle.js');
{ getBundleContentAndComponents, parseFileOrThrow } = require('./bundle.js');
/* eslint-enable */
// See https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options
@@ -4867,7 +4867,7 @@ module.exports = {
mapProcessRelatedFiles(rootFiles, inputData, origin, version, format, toBundle = false) {
let bundleFormat = format,
parsedRootFiles = rootFiles.map((rootFile) => {
let parsedContent = this.parseFileOrThrow(rootFile.content);
let parsedContent = parseFileOrThrow(rootFile.content);
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
}).filter((rootWithParsedContent) => {
let fileVersion = version === SWAGGER_VERSION ?
@@ -4931,14 +4931,5 @@ module.exports = {
else {
return res;
}
},
parseFileOrThrow(fileContent) {
const result = parse.getOasObject(fileContent);
if (result.result === false) {
throw new ParseError(result.reason);
}
return result;
}
};