Skip to content

Commit 4f1c537

Browse files
authored
Merge pull request #783 from postmanlabs/release/v4.20.0
Release version v4.20.0
2 parents 59e0b70 + 5dc28b1 commit 4f1c537

File tree

7 files changed

+84
-71
lines changed

7 files changed

+84
-71
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [v4.20.0] - 2024-02-15
6+
7+
### Added
8+
9+
- Added support for reporting UserErrors in case when OpenAPI definition to converted is invalid.
10+
511
## [v4.19.0] - 2024-01-18
612

713
## [v4.18.0] - 2023-09-28
@@ -602,7 +608,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0
602608

603609
- Base release
604610

605-
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.19.0...HEAD
611+
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.0...HEAD
612+
613+
[v4.20.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.19.0...v4.20.0
606614

607615
[v4.19.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.18.0...v4.19.0
608616

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const { MODULE_VERSION } = require('./lib/schemapack.js');
44

55
const _ = require('lodash'),
6-
SchemaPack = require('./lib/schemapack.js').SchemaPack;
6+
SchemaPack = require('./lib/schemapack.js').SchemaPack,
7+
UserError = require('./lib/common/UserError'),
8+
DEFAULT_INVALID_ERROR = 'Provided definition is invalid';
79

810
module.exports = {
911
// Old API wrapping the new API
@@ -13,7 +15,7 @@ module.exports = {
1315
if (schema.validated) {
1416
return schema.convert(cb);
1517
}
16-
return cb(null, schema.validationResult);
18+
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
1719
},
1820

1921
convertV2: function(input, options, cb) {
@@ -23,7 +25,7 @@ module.exports = {
2325
return schema.convertV2(cb);
2426
}
2527

26-
return cb(null, schema.validationResult);
28+
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
2729
},
2830

2931
validate: function (input) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-to-postmanv2",
3-
"version": "4.19.0",
3+
"version": "4.20.0",
44
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",
55
"homepage": "https://github.com/postmanlabs/openapi-to-postman",
66
"bugs": "https://github.com/postmanlabs/openapi-to-postman/issues",

test/unit/base.test.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -993,30 +993,30 @@ describe('CONVERT FUNCTION TESTS ', function() {
993993
});
994994
});
995995

996-
it('should not return undefined in the error message if spec is not valid JSON/YAML', function(done) {
996+
it('should return correct error message if spec is not valid JSON/YAML', function(done) {
997997
// invalid JSON
998-
Converter.convert({ type: 'string', data: '{"key": { "value" : } ' }, {}, (err, conversionResult) => {
999-
expect(err).to.be.null;
1000-
expect(conversionResult.result).to.be.false;
1001-
expect(conversionResult.reason).to.not.include('undefined');
998+
Converter.convert({ type: 'string', data: '{"key": { "value" : } ' }, {}, (err) => {
999+
expect(err).to.not.be.null;
1000+
expect(err.name).to.eql('UserError');
1001+
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
10021002
});
10031003

10041004
// invalid YAML
1005-
Converter.convert({ type: 'string', data: ' :' }, {}, (err, conversionResult) => {
1006-
expect(err).to.be.null;
1007-
expect(conversionResult.result).to.be.false;
1008-
expect(conversionResult.reason).to.not.include('undefined');
1005+
Converter.convert({ type: 'string', data: ' :' }, {}, (err) => {
1006+
expect(err).to.not.be.null;
1007+
expect(err.name).to.eql('UserError');
1008+
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
10091009
done();
10101010
});
10111011
});
10121012

10131013
it('should throw an invalid format error and not semantic version missing error when yaml.safeLoad ' +
10141014
'does not throw an error while parsing yaml', function(done) {
10151015
// YAML for which yaml.safeLoad does not throw an error
1016-
Converter.convert({ type: 'string', data: 'no error yaml' }, {}, (err, conversionResult) => {
1017-
expect(err).to.be.null;
1018-
expect(conversionResult.result).to.be.false;
1019-
expect(conversionResult.reason).to.not.include('Specification must contain a semantic version number' +
1016+
Converter.convert({ type: 'string', data: 'no error yaml' }, {}, (err) => {
1017+
expect(err).to.not.be.null;
1018+
expect(err.name).to.eql('UserError');
1019+
expect(err.message).to.not.include('Specification must contain a semantic version number' +
10201020
' of the OAS specification');
10211021
done();
10221022
});
@@ -1349,10 +1349,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
13491349
it('The converter must throw an error for invalid null info', function (done) {
13501350
var openapi = fs.readFileSync(invalidNullInfo, 'utf8');
13511351
Converter.convert({ type: 'string', data: openapi },
1352-
{}, (err, conversionResult) => {
1353-
expect(err).to.be.null;
1354-
expect(conversionResult.result).to.equal(false);
1355-
expect(conversionResult.reason)
1352+
{}, (err) => {
1353+
expect(err).to.not.be.null;
1354+
expect(err.name).to.eql('UserError');
1355+
expect(err.message)
13561356
.to.equal('Specification must contain an Info Object for the meta-data of the API');
13571357
done();
13581358
});
@@ -1361,10 +1361,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
13611361
it('The converter must throw an error for invalid null info title', function (done) {
13621362
var openapi = fs.readFileSync(invalidNullInfoTitle, 'utf8');
13631363
Converter.convert({ type: 'string', data: openapi },
1364-
{}, (err, conversionResult) => {
1365-
expect(err).to.be.null;
1366-
expect(conversionResult.result).to.equal(false);
1367-
expect(conversionResult.reason)
1364+
{}, (err) => {
1365+
expect(err).to.not.be.null;
1366+
expect(err.name).to.eql('UserError');
1367+
expect(err.message)
13681368
.to.equal('Specification must contain a title in order to generate a collection');
13691369
done();
13701370
});
@@ -1373,10 +1373,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
13731373
it('The converter must throw an error for invalid null info version', function (done) {
13741374
var openapi = fs.readFileSync(invalidNullInfoVersion, 'utf8');
13751375
Converter.convert({ type: 'string', data: openapi },
1376-
{}, (err, conversionResult) => {
1377-
expect(err).to.be.null;
1378-
expect(conversionResult.result).to.equal(false);
1379-
expect(conversionResult.reason)
1376+
{}, (err) => {
1377+
expect(err).to.not.be.null;
1378+
expect(err.name).to.eql('UserError');
1379+
expect(err.message)
13801380
.to.equal('Specification must contain a semantic version number of the API in the Info Object');
13811381
done();
13821382
});
@@ -2408,9 +2408,9 @@ describe('INTERFACE FUNCTION TESTS ', function () {
24082408
validationResult = Converter.validate({ type: 'string', data: openapi });
24092409

24102410
expect(validationResult.result).to.equal(false);
2411-
Converter.convert({ type: 'string', data: openapi }, {}, function(err, conversionResult) {
2412-
expect(err).to.be.null;
2413-
expect(conversionResult.result).to.equal(false);
2411+
Converter.convert({ type: 'string', data: openapi }, {}, function(err) {
2412+
expect(err).to.not.be.null;
2413+
expect(err.name).to.eql('UserError');
24142414
done();
24152415
});
24162416
});
@@ -2422,9 +2422,10 @@ describe('INTERFACE FUNCTION TESTS ', function () {
24222422
var result = Converter.validate({ type: 'fil', data: 'invalid_path' });
24232423
expect(result.result).to.equal(false);
24242424
expect(result.reason).to.contain('input');
2425-
Converter.convert({ type: 'fil', data: 'invalid_path' }, {}, function(err, conversionResult) {
2426-
expect(conversionResult.result).to.equal(false);
2427-
expect(conversionResult.reason).to.equal('Invalid input type (fil). type must be one of file/json/string.');
2425+
Converter.convert({ type: 'fil', data: 'invalid_path' }, {}, function(err) {
2426+
expect(err).to.not.be.null;
2427+
expect(err.name).to.eql('UserError');
2428+
expect(err.message).to.equal('Invalid input type (fil). type must be one of file/json/string.');
24282429
done();
24292430
});
24302431
});
@@ -2434,9 +2435,10 @@ describe('INTERFACE FUNCTION TESTS ', function () {
24342435
it('(type: file)', function(done) {
24352436
var result = Converter.validate({ type: 'file', data: 'invalid_path' });
24362437
expect(result.result).to.equal(false);
2437-
Converter.convert({ type: 'file', data: 'invalid_path' }, {}, function(err, result) {
2438-
expect(result.result).to.equal(false);
2439-
expect(result.reason).to.equal('ENOENT: no such file or directory, open \'invalid_path\'');
2438+
Converter.convert({ type: 'file', data: 'invalid_path' }, {}, function(err) {
2439+
expect(err).to.not.be.null;
2440+
expect(err.name).to.eql('UserError');
2441+
expect(err.message).to.equal('ENOENT: no such file or directory, open \'invalid_path\'');
24402442
done();
24412443
});
24422444
});

test/unit/bin.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ describe('openapi2postmanv2 ', function() {
3333
});
3434

3535
it('should show appropriate messages for invalid input', function (done) {
36-
exec('./bin/openapi2postmanv2.js -s test/data/invalid_openapi/multiple-components.yaml', function(err, stdout) {
37-
expect(err).to.be.null;
38-
expect(stdout).to.include('duplicated mapping key');
39-
done();
40-
});
36+
exec('./bin/openapi2postmanv2.js -s test/data/invalid_openapi/multiple-components.yaml',
37+
function(err, stdout, stderr) {
38+
expect(err).to.be.null;
39+
expect(stderr).to.include('duplicated mapping key');
40+
done();
41+
});
4142
});
4243
});

test/unit/convertV2.test.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -947,30 +947,30 @@ describe('The convert v2 Function', function() {
947947
});
948948
});
949949

950-
it('should not return undefined in the error message if spec is not valid JSON/YAML', function(done) {
950+
it('should return correct error message if spec is not valid JSON/YAML', function(done) {
951951
// invalid JSON
952-
Converter.convertV2({ type: 'string', data: '{"key": { "value" : } ' }, {}, (err, conversionResult) => {
953-
expect(err).to.be.null;
954-
expect(conversionResult.result).to.be.false;
955-
expect(conversionResult.reason).to.not.include('undefined');
952+
Converter.convertV2({ type: 'string', data: '{"key": { "value" : } ' }, {}, (err) => {
953+
expect(err).to.not.be.null;
954+
expect(err.name).to.eql('UserError');
955+
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
956956
});
957957

958958
// invalid YAML
959-
Converter.convertV2({ type: 'string', data: ' :' }, {}, (err, conversionResult) => {
960-
expect(err).to.be.null;
961-
expect(conversionResult.result).to.be.false;
962-
expect(conversionResult.reason).to.not.include('undefined');
959+
Converter.convertV2({ type: 'string', data: ' :' }, {}, (err) => {
960+
expect(err).to.not.be.null;
961+
expect(err.name).to.eql('UserError');
962+
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
963963
done();
964964
});
965965
});
966966

967967
it('should throw an invalid format error and not semantic version missing error when yaml.safeLoad ' +
968968
'does not throw an error while parsing yaml', function(done) {
969969
// YAML for which yaml.safeLoad does not throw an error
970-
Converter.convertV2({ type: 'string', data: 'no error yaml' }, {}, (err, conversionResult) => {
971-
expect(err).to.be.null;
972-
expect(conversionResult.result).to.be.false;
973-
expect(conversionResult.reason).to.not.include('Specification must contain a semantic version number' +
970+
Converter.convertV2({ type: 'string', data: 'no error yaml' }, {}, (err) => {
971+
expect(err).to.not.be.null;
972+
expect(err.name).to.eql('UserError');
973+
expect(err.message).to.not.include('Specification must contain a semantic version number' +
974974
' of the OAS specification');
975975
done();
976976
});
@@ -1244,10 +1244,10 @@ describe('The convert v2 Function', function() {
12441244
it('The converter must throw an error for invalid null info', function (done) {
12451245
var openapi = fs.readFileSync(invalidNullInfo, 'utf8');
12461246
Converter.convertV2({ type: 'string', data: openapi },
1247-
{}, (err, conversionResult) => {
1248-
expect(err).to.be.null;
1249-
expect(conversionResult.result).to.equal(false);
1250-
expect(conversionResult.reason)
1247+
{}, (err) => {
1248+
expect(err).to.not.be.null;
1249+
expect(err.name).to.eql('UserError');
1250+
expect(err.message)
12511251
.to.equal('Specification must contain an Info Object for the meta-data of the API');
12521252
done();
12531253
});
@@ -1256,10 +1256,10 @@ describe('The convert v2 Function', function() {
12561256
it('The converter must throw an error for invalid null info title', function (done) {
12571257
var openapi = fs.readFileSync(invalidNullInfoTitle, 'utf8');
12581258
Converter.convertV2({ type: 'string', data: openapi },
1259-
{}, (err, conversionResult) => {
1260-
expect(err).to.be.null;
1261-
expect(conversionResult.result).to.equal(false);
1262-
expect(conversionResult.reason)
1259+
{}, (err) => {
1260+
expect(err).to.not.be.null;
1261+
expect(err.name).to.eql('UserError');
1262+
expect(err.message)
12631263
.to.equal('Specification must contain a title in order to generate a collection');
12641264
done();
12651265
});
@@ -1268,10 +1268,10 @@ describe('The convert v2 Function', function() {
12681268
it('The converter must throw an error for invalid null info version', function (done) {
12691269
var openapi = fs.readFileSync(invalidNullInfoVersion, 'utf8');
12701270
Converter.convertV2({ type: 'string', data: openapi },
1271-
{}, (err, conversionResult) => {
1272-
expect(err).to.be.null;
1273-
expect(conversionResult.result).to.equal(false);
1274-
expect(conversionResult.reason)
1271+
{}, (err) => {
1272+
expect(err).to.not.be.null;
1273+
expect(err.name).to.eql('UserError');
1274+
expect(err.message)
12751275
.to.equal('Specification must contain a semantic version number of the API in the Info Object');
12761276
done();
12771277
});

0 commit comments

Comments
 (0)