mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Throw errors instead of returning reason
Throw errors instead of returning reason and throw errors if the entry has no root files
This commit is contained in:
@@ -4921,26 +4921,23 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
|
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
|
||||||
inputRelatedFiles.origin, version, inputRelatedFiles.bundleFormat, toBundle);
|
inputRelatedFiles.origin, version, inputRelatedFiles.bundleFormat, toBundle);
|
||||||
|
if (res.output.data === undefined || res.output.data.result === false ||
|
||||||
|
res.output.data.length === 0) {
|
||||||
|
res.result = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (error instanceof ParseError) {
|
if (error instanceof ParseError) {
|
||||||
return {
|
|
||||||
result: false,
|
|
||||||
reason: error.message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw (error);
|
throw (error);
|
||||||
}
|
}
|
||||||
}
|
let newError = new Error('There was an error during the process');
|
||||||
if (res.output.data.result === false) {
|
newError.stack = error.stack;
|
||||||
res.result = res.output.data.result;
|
throw (newError);
|
||||||
res.error = res.output.data.error;
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return res;
|
throw new Error('Input should have at least one root file');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -401,12 +401,14 @@ describe('bundle files method - 3.0', function () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
const res = await Converter.bundle(input);
|
try {
|
||||||
expect(res).to.not.be.empty;
|
await Converter.bundle(input);
|
||||||
expect(res.result).to.be.false;
|
}
|
||||||
expect(res.reason).to.equal('Invalid format. Input must be in YAML or JSON ' +
|
catch (error) {
|
||||||
'format. Specification is not a valid YAML. YAMLException: duplicated mapping' +
|
expect(error.message).to.equal('Invalid format. Input must be in YAML or JSON ' +
|
||||||
' key at line 30, column -54:\n components:\n ^');
|
'format. Specification is not a valid YAML. YAMLException: duplicated mapping' +
|
||||||
|
' key at line 30, column -54:\n components:\n ^');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return bundled file from same_ref_different_source', async function () {
|
it('Should return bundled file from same_ref_different_source', async function () {
|
||||||
@@ -746,6 +748,76 @@ describe('bundle files method - 3.0', function () {
|
|||||||
expect(res.result).to.be.true;
|
expect(res.result).to.be.true;
|
||||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should take the root file from data array', async function () {
|
||||||
|
let contentRootFile = fs.readFileSync(sameRefDiffSource + '/root.yaml', 'utf8'),
|
||||||
|
user = fs.readFileSync(sameRefDiffSource + '/schemas/user/user.yaml', 'utf8'),
|
||||||
|
client = fs.readFileSync(sameRefDiffSource + '/schemas/client/client.yaml', 'utf8'),
|
||||||
|
specialUser = fs.readFileSync(sameRefDiffSource + '/schemas/user/special.yaml', 'utf8'),
|
||||||
|
specialClient = fs.readFileSync(sameRefDiffSource + '/schemas/client/special.yaml', 'utf8'),
|
||||||
|
magic = fs.readFileSync(sameRefDiffSource + '/schemas/client/magic.yaml', 'utf8'),
|
||||||
|
expected = fs.readFileSync(sameRefDiffSource + '/expected.json', 'utf8'),
|
||||||
|
input = {
|
||||||
|
type: 'folder',
|
||||||
|
specificationVersion: '3.0',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
path: '/root.yaml',
|
||||||
|
content: contentRootFile
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/schemas/user/user.yaml',
|
||||||
|
content: user
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/schemas/user/special.yaml',
|
||||||
|
content: specialUser
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/schemas/client/client.yaml',
|
||||||
|
content: client
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/schemas/client/special.yaml',
|
||||||
|
content: specialClient
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/schemas/client/magic.yaml',
|
||||||
|
content: magic
|
||||||
|
}
|
||||||
|
],
|
||||||
|
options: {},
|
||||||
|
bundleFormat: 'JSON'
|
||||||
|
};
|
||||||
|
const res = await Converter.bundle(input);
|
||||||
|
expect(res).to.not.be.empty;
|
||||||
|
expect(res.result).to.be.true;
|
||||||
|
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should throw error when input has not root files', async function () {
|
||||||
|
let user = fs.readFileSync(schemaFromResponse + '/schemas/user.yaml', 'utf8'),
|
||||||
|
input = {
|
||||||
|
type: 'folder',
|
||||||
|
specificationVersion: '3.0',
|
||||||
|
rootFiles: [],
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
path: '/schemas/user.yaml',
|
||||||
|
content: user
|
||||||
|
}
|
||||||
|
],
|
||||||
|
options: {},
|
||||||
|
bundleFormat: 'JSON'
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await Converter.bundle(input);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
expect(error.message).to.equal('Input should have at least one root file');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ let expect = require('chai').expect,
|
|||||||
|
|
||||||
describe('detectRelatedFiles method', function () {
|
describe('detectRelatedFiles method', function () {
|
||||||
|
|
||||||
it('should return empty data when there is no root in the entry', async function () {
|
it('should return error when there is no root in the entry', async function () {
|
||||||
let contentFile = fs.readFileSync(petstoreSeparatedPet, 'utf8'),
|
let contentFile = fs.readFileSync(petstoreSeparatedPet, 'utf8'),
|
||||||
input = {
|
input = {
|
||||||
type: 'folder',
|
type: 'folder',
|
||||||
@@ -44,10 +44,12 @@ describe('detectRelatedFiles method', function () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
const res = await Converter.detectRelatedFiles(input);
|
try {
|
||||||
expect(res).to.not.be.empty;
|
await Converter.detectRelatedFiles(input);
|
||||||
expect(res.result).to.be.true;
|
}
|
||||||
expect(res.output.data.length).to.equal(0);
|
catch (error) {
|
||||||
|
expect(error.message).to.equal('Input should have at least one root file');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should locate root and return empty data when there is no ref', async function () {
|
it('should locate root and return empty data when there is no ref', async function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user