Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version v4.20.0 #783

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v4.20.0] - 2024-02-15

### Added

- Added support for reporting UserErrors in case when OpenAPI definition to converted is invalid.

## [v4.19.0] - 2024-01-18

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

- Base release

[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.19.0...HEAD
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.0...HEAD

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

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

Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const { MODULE_VERSION } = require('./lib/schemapack.js');

const _ = require('lodash'),
SchemaPack = require('./lib/schemapack.js').SchemaPack;
SchemaPack = require('./lib/schemapack.js').SchemaPack,
UserError = require('./lib/common/UserError'),
DEFAULT_INVALID_ERROR = 'Provided definition is invalid';

module.exports = {
// Old API wrapping the new API
Expand All @@ -13,7 +15,7 @@ module.exports = {
if (schema.validated) {
return schema.convert(cb);
}
return cb(null, schema.validationResult);
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},

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

return cb(null, schema.validationResult);
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},

validate: function (input) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openapi-to-postmanv2",
"version": "4.19.0",
"version": "4.20.0",
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",
"homepage": "https://github.com/postmanlabs/openapi-to-postman",
"bugs": "https://github.com/postmanlabs/openapi-to-postman/issues",
Expand Down
70 changes: 36 additions & 34 deletions test/unit/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,30 +993,30 @@ describe('CONVERT FUNCTION TESTS ', function() {
});
});

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

// invalid YAML
Converter.convert({ type: 'string', data: ' :' }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.be.false;
expect(conversionResult.reason).to.not.include('undefined');
Converter.convert({ type: 'string', data: ' :' }, {}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
done();
});
});

it('should throw an invalid format error and not semantic version missing error when yaml.safeLoad ' +
'does not throw an error while parsing yaml', function(done) {
// YAML for which yaml.safeLoad does not throw an error
Converter.convert({ type: 'string', data: 'no error yaml' }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.be.false;
expect(conversionResult.reason).to.not.include('Specification must contain a semantic version number' +
Converter.convert({ type: 'string', data: 'no error yaml' }, {}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.not.include('Specification must contain a semantic version number' +
' of the OAS specification');
done();
});
Expand Down Expand Up @@ -1349,10 +1349,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
it('The converter must throw an error for invalid null info', function (done) {
var openapi = fs.readFileSync(invalidNullInfo, 'utf8');
Converter.convert({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain an Info Object for the meta-data of the API');
done();
});
Expand All @@ -1361,10 +1361,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
it('The converter must throw an error for invalid null info title', function (done) {
var openapi = fs.readFileSync(invalidNullInfoTitle, 'utf8');
Converter.convert({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain a title in order to generate a collection');
done();
});
Expand All @@ -1373,10 +1373,10 @@ describe('CONVERT FUNCTION TESTS ', function() {
it('The converter must throw an error for invalid null info version', function (done) {
var openapi = fs.readFileSync(invalidNullInfoVersion, 'utf8');
Converter.convert({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain a semantic version number of the API in the Info Object');
done();
});
Expand Down Expand Up @@ -2408,9 +2408,9 @@ describe('INTERFACE FUNCTION TESTS ', function () {
validationResult = Converter.validate({ type: 'string', data: openapi });

expect(validationResult.result).to.equal(false);
Converter.convert({ type: 'string', data: openapi }, {}, function(err, conversionResult) {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
Converter.convert({ type: 'string', data: openapi }, {}, function(err) {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
done();
});
});
Expand All @@ -2422,9 +2422,10 @@ describe('INTERFACE FUNCTION TESTS ', function () {
var result = Converter.validate({ type: 'fil', data: 'invalid_path' });
expect(result.result).to.equal(false);
expect(result.reason).to.contain('input');
Converter.convert({ type: 'fil', data: 'invalid_path' }, {}, function(err, conversionResult) {
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason).to.equal('Invalid input type (fil). type must be one of file/json/string.');
Converter.convert({ type: 'fil', data: 'invalid_path' }, {}, function(err) {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.equal('Invalid input type (fil). type must be one of file/json/string.');
done();
});
});
Expand All @@ -2434,9 +2435,10 @@ describe('INTERFACE FUNCTION TESTS ', function () {
it('(type: file)', function(done) {
var result = Converter.validate({ type: 'file', data: 'invalid_path' });
expect(result.result).to.equal(false);
Converter.convert({ type: 'file', data: 'invalid_path' }, {}, function(err, result) {
expect(result.result).to.equal(false);
expect(result.reason).to.equal('ENOENT: no such file or directory, open \'invalid_path\'');
Converter.convert({ type: 'file', data: 'invalid_path' }, {}, function(err) {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.equal('ENOENT: no such file or directory, open \'invalid_path\'');
done();
});
});
Expand Down
11 changes: 6 additions & 5 deletions test/unit/bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ describe('openapi2postmanv2 ', function() {
});

it('should show appropriate messages for invalid input', function (done) {
exec('./bin/openapi2postmanv2.js -s test/data/invalid_openapi/multiple-components.yaml', function(err, stdout) {
expect(err).to.be.null;
expect(stdout).to.include('duplicated mapping key');
done();
});
exec('./bin/openapi2postmanv2.js -s test/data/invalid_openapi/multiple-components.yaml',
function(err, stdout, stderr) {
expect(err).to.be.null;
expect(stderr).to.include('duplicated mapping key');
done();
});
});
});
50 changes: 25 additions & 25 deletions test/unit/convertV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
});

// Need to handle collaping of folders
it.skip('Should generate collection with collapsing unnecessary folders ' +

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test

Check warning on line 305 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, {}, (err, conversionResult) => {
Expand All @@ -314,7 +314,7 @@
done();
});
});
it.skip('Should collapse child and parent folder when parent has only one child' +

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test

Check warning on line 317 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec1, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec1, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
Expand All @@ -328,7 +328,7 @@
done();
});
});
it.skip('Should generate collection without creating folders and having only one request' +

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test

Check warning on line 331 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec2, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec2, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
Expand Down Expand Up @@ -947,30 +947,30 @@
});
});

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

// invalid YAML
Converter.convertV2({ type: 'string', data: ' :' }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.be.false;
expect(conversionResult.reason).to.not.include('undefined');
Converter.convertV2({ type: 'string', data: ' :' }, {}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.include('Invalid format. Input must be in YAML or JSON format.');
done();
});
});

it('should throw an invalid format error and not semantic version missing error when yaml.safeLoad ' +
'does not throw an error while parsing yaml', function(done) {
// YAML for which yaml.safeLoad does not throw an error
Converter.convertV2({ type: 'string', data: 'no error yaml' }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.be.false;
expect(conversionResult.reason).to.not.include('Specification must contain a semantic version number' +
Converter.convertV2({ type: 'string', data: 'no error yaml' }, {}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message).to.not.include('Specification must contain a semantic version number' +
' of the OAS specification');
done();
});
Expand Down Expand Up @@ -1244,10 +1244,10 @@
it('The converter must throw an error for invalid null info', function (done) {
var openapi = fs.readFileSync(invalidNullInfo, 'utf8');
Converter.convertV2({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain an Info Object for the meta-data of the API');
done();
});
Expand All @@ -1256,10 +1256,10 @@
it('The converter must throw an error for invalid null info title', function (done) {
var openapi = fs.readFileSync(invalidNullInfoTitle, 'utf8');
Converter.convertV2({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain a title in order to generate a collection');
done();
});
Expand All @@ -1268,10 +1268,10 @@
it('The converter must throw an error for invalid null info version', function (done) {
var openapi = fs.readFileSync(invalidNullInfoVersion, 'utf8');
Converter.convertV2({ type: 'string', data: openapi },
{}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(false);
expect(conversionResult.reason)
{}, (err) => {
expect(err).to.not.be.null;
expect(err.name).to.eql('UserError');
expect(err.message)
.to.equal('Specification must contain a semantic version number of the API in the Info Object');
done();
});
Expand Down
Loading