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 v0.2.0 #82

Merged
merged 8 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
steps:
- name: Get Code
uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/.gitignore
/test/
/scripts/
/npm/

### Borrowed from .gitignore
### ========================
Expand All @@ -20,6 +21,8 @@

## Directory-based project format:
.idea/
.vscode/

# if you remove the above rule, at least ignore the following:

# User-specific stuff:
Expand Down
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]

## [v0.2.0] - 2024-02-15

### Added

- Added support for reporting UserErrors when provided definition is invalid.

## [v0.1.8] - 2023-04-17

### Added
Expand Down Expand Up @@ -59,7 +65,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0

- Base release

[Unreleased]: https://github.com/postmanlabs/raml1-to-postman/compare/v0.1.8...HEAD
[Unreleased]: https://github.com/postmanlabs/raml1-to-postman/compare/v0.2.0...HEAD

[v0.2.0]: https://github.com/postmanlabs/raml1-to-postman/compare/v0.1.8...v0.2.0

[v0.1.8]: https://github.com/postmanlabs/raml1-to-postman/compare/0.1.7...v0.1.8

Expand Down
15 changes: 15 additions & 0 deletions lib/UserError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* constructor userError
* @constructor
* @param {*} message errorMessage
* @param {*} data additional data to be reported
*/
class UserError extends Error {
constructor(message, data) {
super(message);
this.name = 'UserError';
this.data = data || {};
}
}

module.exports = UserError;
8 changes: 4 additions & 4 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const raml = require('./../assets/raml-1-parser'),
helper = require('./helper.js'),
getOptions = require('./options').getOptions,
{ Node, Trie } = require('./trie.js'),
{ generateError } = require('./generateError.js'),

// This is the default collection name if one can't be inferred from the RAML 1.0 spec
COLLECTION_NAME = 'Converted from RAML 1.0';
Expand Down Expand Up @@ -250,10 +251,9 @@ var converter = {
}]
});
}
catch (e) {
return cb(null, {
result: false,
reason: e.toString()
catch (originalError) {
return generateError(ramlString, originalError, (constructedError) => {
return cb(constructedError);
});
}

Expand Down
46 changes: 46 additions & 0 deletions lib/generateError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const _ = require('lodash'),
wap = require('webapi-parser').WebApiParser,
UserError = require('./UserError');

/**
* Validates given RAML 1.0 definition using WebAPI Parser and
* generates UserError or Unhandled error depending upon type of error.
*
* @param {Object} definition - RAML definition
* @param {*} error - Original Error object
* @param {Function} cb - Callback function
* @returns {*} - Generated Error object
*/
function generateError (definition, error, cb) {
wap.raml10.parse(definition, '')
.then((model) => {
wap.raml10.validate(model)
.then((report) => {
if (report.conforms || report.results.length === 0) {
if (error instanceof Error) {
return cb(error);
}

const errorMessage = typeof error === 'string' ? error :
_.get(error, 'message', 'Failed to generate collection.');

return cb(new Error(errorMessage));
}

let lastReportRes = report.results.pop(),
message = lastReportRes.message;

return cb(new UserError(message, error));
})
.catch(() => {
return cb(new UserError('Provided RAML 1.0 definition is invalid.', error));
});
})
.catch(() => {
return cb(new UserError('Provided RAML 1.0 definition is invalid.', error));
});
}

module.exports = {
generateError
};
6 changes: 4 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
method.is.forEach(function(trait) {
for (property in traits[trait]) {
if (property !== 'name') {
if (modified_method[property]) {
if (modified_method[property] && typeof modified_method[property] === 'object') {
Object.assign(modified_method[property], traits[trait][property]);
}
else {
Expand Down Expand Up @@ -800,7 +800,7 @@
* @returns {*} Postman itemGroup or request
* @no-unit-test
*/
convertChildToItemGroup: function(baseUrl, child, globalParameters, options, pathVariables = []) {

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Expected to return a value at the end of method 'convertChildToItemGroup'

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Expected to return a value at the end of method 'convertChildToItemGroup'

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (20.x)

Expected to return a value at the end of method 'convertChildToItemGroup'

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Expected to return a value at the end of method 'convertChildToItemGroup'

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Expected to return a value at the end of method 'convertChildToItemGroup'

Check warning on line 803 in lib/helper.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (20.x)

Expected to return a value at the end of method 'convertChildToItemGroup'
var resource = child,
itemGroup,
subChild,
Expand Down Expand Up @@ -1058,7 +1058,9 @@

return resolvedResource;
});
}
},

addTraitsToMethod
};

module.exports = helper;
Loading
Loading