New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

openapi-parse

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-parse - npm Package Compare versions

Comparing version
0.1.1
to
0.1.3
+235
index.js
'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var $RefParser = require('json-schema-ref-parser');
var isNil = require('inspected/schema/is-nil').default;
var isString = require('inspected/schema/is-string').default;
var isObject = require('inspected/schema/is-object').default;
var merge = require('deepmerge');
var fs = require('fs');
var fromFile = function fromFile(filePath) {
return new Promise(function (resolve, reject) {
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
reject(err);
return;
}
var spec = JSON.parse(data);
resolve(spec);
});
});
};
var dereference = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(content, basePath, parser, resolver) {
var options;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = {
parse: { custom: parser },
resolve: { custom: resolver }
};
if (!basePath) {
_context.next = 5;
break;
}
_context.next = 4;
return $RefParser.dereference(basePath, content, options);
case 4:
return _context.abrupt('return', _context.sent);
case 5:
_context.next = 7;
return $RefParser.dereference(content, options);
case 7:
return _context.abrupt('return', _context.sent);
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function dereference(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
var parse = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(content, options) {
var defaultOptions, compiledOptions, parser, resolver, spec;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
if (!isNil(content)) {
_context6.next = 2;
break;
}
throw new Error('No content specified.');
case 2:
if (!(!isString(content) && !isObject(content))) {
_context6.next = 4;
break;
}
throw new Error('Content must be a string or spec object.');
case 4:
if (!(!isNil(options) && !isObject(options))) {
_context6.next = 6;
break;
}
throw new Error('Options should be an object.');
case 6:
_context6.prev = 6;
defaultOptions = {
parser: {
canParse: function canParse(file) {
return false;
},
parse: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(file) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function parse(_x7) {
return _ref3.apply(this, arguments);
};
}()
},
resolver: {
canResolve: function canResolve(info) {
return false;
},
resolve: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(info) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
case 'end':
return _context3.stop();
}
}
}, _callee3, undefined);
}));
return function resolve(_x8) {
return _ref4.apply(this, arguments);
};
}()
}
};
compiledOptions = options ? merge(defaultOptions, options) : defaultOptions;
parser = {
order: 1,
canParse: function canParse(info) {
return compiledOptions.parser.canParse(info);
},
parse: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(info) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt('return', compiledOptions.parser.parse(info));
case 1:
case 'end':
return _context4.stop();
}
}
}, _callee4, undefined);
}));
return function parse(_x9) {
return _ref5.apply(this, arguments);
};
}()
};
resolver = {
order: 1,
canRead: function canRead(info) {
return compiledOptions.resolver.canResolve({
path: info.url,
extension: info.extension
});
},
read: function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(info) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return compiledOptions.resolver.resolve({
path: info.url,
extension: info.extension
});
case 2:
return _context5.abrupt('return', _context5.sent);
case 3:
case 'end':
return _context5.stop();
}
}
}, _callee5, undefined);
}));
return function read(_x10) {
return _ref6.apply(this, arguments);
};
}()
};
_context6.next = 13;
return dereference(content, compiledOptions.basePath, parser, resolver);
case 13:
spec = _context6.sent;
return _context6.abrupt('return', spec);
case 17:
_context6.prev = 17;
_context6.t0 = _context6['catch'](6);
throw new Error('There was an error parsing the specified spec:\n' + _context6.t0);
case 20:
case 'end':
return _context6.stop();
}
}
}, _callee6, undefined, [[6, 17]]);
}));
return function parse(_x5, _x6) {
return _ref2.apply(this, arguments);
};
}();
module.exports = parse;
+10
-0

@@ -5,3 +5,13 @@ # Change Log

<a name="0.1.3"></a>
## [0.1.3](https://github.com/devdigital/openapi-parse/compare/v0.1.2...v0.1.3) (2018-04-24)
<a name="0.1.2"></a>
## [0.1.2](https://github.com/devdigital/openapi-parse/compare/v0.1.1...v0.1.2) (2018-04-24)
<a name="0.1.1"></a>
## 0.1.1 (2018-04-24)
+2
-3
{
"name": "openapi-parse",
"version": "0.1.1",
"version": "0.1.3",
"description": "Basic parser for OpenAPI specs",

@@ -26,4 +26,3 @@ "main": "index.js",

"inspected": "^0.3.0",
"json-schema-ref-parser": "^5.0.3",
"swagger-parser": "^4.1.0"
"json-schema-ref-parser": "^5.0.3"
},

@@ -30,0 +29,0 @@ "devDependencies": {

'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var $RefParser = require('json-schema-ref-parser');
var isNil = require('inspected/schema/is-nil').default;
var isString = require('inspected/schema/is-string').default;
var isObject = require('inspected/schema/is-object').default;
var merge = require('deepmerge');
var fs = require('fs');
var fromFile = function fromFile(filePath) {
return new Promise(function (resolve, reject) {
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
reject(err);
return;
}
var spec = JSON.parse(data);
resolve(spec);
});
});
};
var dereference = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(content, basePath, parser, resolver) {
var options;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = {
parse: { custom: parser },
resolve: { custom: resolver }
};
if (!basePath) {
_context.next = 5;
break;
}
_context.next = 4;
return $RefParser.dereference(basePath, content, options);
case 4:
return _context.abrupt('return', _context.sent);
case 5:
_context.next = 7;
return $RefParser.dereference(content, options);
case 7:
return _context.abrupt('return', _context.sent);
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function dereference(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
var parse = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(content, options) {
var defaultOptions, compiledOptions, parser, resolver, spec;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
if (!isNil(content)) {
_context6.next = 2;
break;
}
throw new Error('No content specified.');
case 2:
if (!(!isString(content) && !isObject(content))) {
_context6.next = 4;
break;
}
throw new Error('Content must be a string or spec object.');
case 4:
if (!(!isNil(options) && !isObject(options))) {
_context6.next = 6;
break;
}
throw new Error('Options should be an object.');
case 6:
_context6.prev = 6;
defaultOptions = {
parser: {
canParse: function canParse(file) {
return false;
},
parse: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(file) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function parse(_x7) {
return _ref3.apply(this, arguments);
};
}()
},
resolver: {
canResolve: function canResolve(info) {
return false;
},
resolve: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(info) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
case 'end':
return _context3.stop();
}
}
}, _callee3, undefined);
}));
return function resolve(_x8) {
return _ref4.apply(this, arguments);
};
}()
}
};
compiledOptions = options ? merge(defaultOptions, options) : defaultOptions;
parser = {
order: 1,
canParse: function canParse(info) {
return compiledOptions.parser.canParse(info);
},
parse: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(info) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt('return', compiledOptions.parser.parse(info));
case 1:
case 'end':
return _context4.stop();
}
}
}, _callee4, undefined);
}));
return function parse(_x9) {
return _ref5.apply(this, arguments);
};
}()
};
resolver = {
order: 1,
canRead: function canRead(info) {
return compiledOptions.resolver.canResolve({
path: info.url,
extension: info.extension
});
},
read: function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(info) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return compiledOptions.resolver.resolve({
path: info.url,
extension: info.extension
});
case 2:
return _context5.abrupt('return', _context5.sent);
case 3:
case 'end':
return _context5.stop();
}
}
}, _callee5, undefined);
}));
return function read(_x10) {
return _ref6.apply(this, arguments);
};
}()
};
_context6.next = 13;
return dereference(content, compiledOptions.basePath, parser, resolver);
case 13:
spec = _context6.sent;
return _context6.abrupt('return', spec);
case 17:
_context6.prev = 17;
_context6.t0 = _context6['catch'](6);
throw new Error('There was an error parsing the specified spec:\n' + _context6.t0);
case 20:
case 'end':
return _context6.stop();
}
}
}, _callee6, undefined, [[6, 17]]);
}));
return function parse(_x5, _x6) {
return _ref2.apply(this, arguments);
};
}();
module.exports = parse;