Skip to content

Promisification of functions in schemaUtils.js (ES6 Async/Await) - Enables external references for schemas and examples. #355

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"node": true,
"es6": true
},
"parser": "babel-eslint",
"rules": {
// Possible Errors
"comma-dangle": ["error", "never"],
Expand Down Expand Up @@ -74,7 +75,7 @@
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-invalid-this": "off",
"no-iterator": "error",
"no-labels": "error",
"no-lone-blocks": "error",
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const SchemaPack = require('./lib/schemapack.js').SchemaPack;

module.exports = {
// Old API wrapping the new API
convert: function(input, options, cb) {
convert: async function(input, options, cb) {
var schema = new SchemaPack(input, options);

if (schema.validated) {
return schema.convert(cb);
return await schema.convert(cb);
}
return cb(null, schema.validationResult);
},
Expand Down
216 changes: 130 additions & 86 deletions lib/schemaUtils.js

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions lib/schemapack.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class SchemaPack {

// convert method, this is called when you want to convert a schema that you've already loaded
// in the constructor
convert (callback) {
async convert (callback) {
let openapi,
options = this.computedOptions,
analysis,
Expand Down Expand Up @@ -299,10 +299,14 @@ class SchemaPack {
// For paths, All operations are grouped based on corresponding paths
try {
if (options.folderStrategy === 'tags') {
schemaUtils.addCollectionItemsUsingTags(openapi, generatedStore, componentsAndPaths, options, schemaCache);
await schemaUtils.addCollectionItemsUsingTags(
openapi, generatedStore, componentsAndPaths, options, schemaCache
);
}
else {
schemaUtils.addCollectionItemsUsingPaths(openapi, generatedStore, componentsAndPaths, options, schemaCache);
await schemaUtils.addCollectionItemsUsingPaths(
openapi, generatedStore, componentsAndPaths, options, schemaCache
);
}
}
catch (e) {
Expand Down Expand Up @@ -333,7 +337,7 @@ class SchemaPack {
* @param {*} callback return
* @returns {boolean} validation
*/
validateTransaction(transactions, callback) {
async validateTransaction (transactions, callback) {
let schema = this.openapi,
componentsAndPaths,
analysis,
Expand Down Expand Up @@ -536,13 +540,16 @@ class SchemaPack {
}
});

retVal = {
requests: _.keyBy(result, 'requestId'),
missingEndpoints: schemaUtils.getMissingSchemaEndpoints(schema, matchedEndpoints,
componentsAndPaths, options, schemaCache)
};

callback(null, retVal);
schemaUtils.getMissingSchemaEndpoints(schema, matchedEndpoints,
componentsAndPaths, options, schemaCache).then((resp) => {
retVal = {
requests: _.keyBy(result, 'requestId'),
missingEndpoints: resp
};
callback(null, retVal);
}).catch((e) => {
callback(e);
});
});
}, 0);
}
Expand Down
67 changes: 67 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"ajv": "6.12.3",
"async": "3.2.0",
"commander": "2.20.3",
"isomorphic-fetch": "3.0.0",
"js-yaml": "3.13.1",
"json-schema-merge-allof": "0.7.0",
"lodash": "4.17.21",
Expand All @@ -130,15 +131,16 @@
"author": "Postman Labs <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
"babel-eslint": "10.1.0",
"chai": "4.2.0",
"editorconfig": "0.15.3",
"eslint": "5.16.0",
"eslint-plugin-jsdoc": "3.8.0",
"eslint-plugin-mocha": "5.3.0",
"eslint-plugin-security": "1.4.0",
"expect.js": "0.3.1",
"nyc": "14.1.1",
"mocha": "5.2.0",
"nyc": "14.1.1",
"parse-gitignore": "0.5.1"
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions test/unit/plugin.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = '../../',
expect = require('expect.js'),
package = require(path),
pkg = require(path),
packageJson = require(path + '/package.json');

/* global describe, it */
Expand All @@ -17,18 +17,18 @@ describe('Plugin ' + packageJson.name, function() {
});

it('should expose the required functions', function (done) {
expect(typeof package.validate).to.equal('function');
expect(typeof package.convert).to.equal('function');
expect(typeof pkg.validate).to.equal('function');
expect(typeof pkg.convert).to.equal('function');
done();
});

it('should validate the sample input correctly', function (done) {
expect(package.validate(sampleInput).result).to.equal(true);
expect(pkg.validate(sampleInput).result).to.equal(true);
done();
});

it('should convert the sample input correctly', function (done) {
package.convert(sampleInput, {}, function(err, result) {
pkg.convert(sampleInput, {}, function(err, result) {
expect(err).to.be(null);
expect(result.result).to.equal(true);
result.output.forEach(function (element) {
Expand Down
Loading