Skip to content

Commit

Permalink
Merge pull request #21 from postmanlabs/feature/remove-multiple-rootf…
Browse files Browse the repository at this point in the history
…ile-support

Handle input type:folder with multiple root files.
  • Loading branch information
VShingala authored Dec 20, 2019
2 parents cf733ba + 21dcd18 commit 11aebc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
33 changes: 7 additions & 26 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ module.exports = {
reason: 'Imported folder does not contain Root of the RAML 1.0 Specs.'
});
}
else if (rootSpecs.length > 1) {
return cb(null, {
result: false,
reason: 'Imported folder contains multiple Root of the RAML 1.0 Specs.'
});
}

async.each(rootSpecs, (rootSpec, callback) => {
var content = fs.readFileSync(rootSpec, 'utf8'),
Expand All @@ -51,32 +57,7 @@ module.exports = {
});
}

var conversionResult = false,
convertedCollections = [],
reasonForFail;

_.forEach(convertedSpecs, (convertedSpec) => {
if (convertedSpec.result) {
conversionResult = conversionResult || convertedSpec.result;
convertedCollections.push(convertedSpec.output[0]);
}
else {
conversionResult = conversionResult || convertedSpec.result;
reasonForFail = convertedSpec.reason;
}
});

if (conversionResult) {
return cb(null, {
result: true,
output: convertedCollections
});
}

return cb(null, {
result: false,
reason: reasonForFail
});
return cb(null, convertedSpecs[0]);
});
}
else {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,25 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});

it('The converter should return valid result and reason for ' +
'input type:folder with multiple root files', function(done) {
var input = {
data: [
{ fileName: VALID_RAML_DIR_PATH + '/ramlSpecFolder/types/user.raml' },
{ fileName: VALID_RAML_DIR_PATH + '/ramlSpecFolder/api.raml' },
{ fileName: VALID_RAML_DIR_PATH + '/ramlSpecBasic.raml' }
],
type: 'folder'
};

Converter.convert(input, {}, function(err, conversionResult) {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason).to.equal('Imported folder contains multiple Root of the RAML 1.0 Specs.');
done();
});
});
});

/* Plugin Interface Tests */
Expand Down

0 comments on commit 11aebc7

Please sign in to comment.