openapi-parse
Advanced tools
+5
-0
@@ -5,2 +5,7 @@ # Change Log | ||
| <a name="0.1.4"></a> | ||
| ## [0.1.4](https://github.com/devdigital/openapi-parse/compare/v0.1.3...v0.1.4) (2018-04-25) | ||
| <a name="0.1.3"></a> | ||
@@ -7,0 +12,0 @@ ## [0.1.3](https://github.com/devdigital/openapi-parse/compare/v0.1.2...v0.1.3) (2018-04-24) |
+100
-194
@@ -5,12 +5,12 @@ 'use strict'; | ||
| 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'); | ||
| const $RefParser = require('json-schema-ref-parser'); | ||
| const isNil = require('inspected/schema/is-nil').default; | ||
| const isString = require('inspected/schema/is-string').default; | ||
| const isObject = require('inspected/schema/is-object').default; | ||
| const merge = require('deepmerge'); | ||
| const fs = require('fs'); | ||
| var fromFile = function fromFile(filePath) { | ||
| return new Promise(function (resolve, reject) { | ||
| fs.readFile(filePath, 'utf8', function (err, data) { | ||
| const fromFile = filePath => { | ||
| return new Promise((resolve, reject) => { | ||
| fs.readFile(filePath, 'utf8', (err, data) => { | ||
| if (err) { | ||
@@ -21,3 +21,3 @@ reject(err); | ||
| var spec = JSON.parse(data); | ||
| const spec = JSON.parse(data); | ||
| resolve(spec); | ||
@@ -28,211 +28,117 @@ }); | ||
| 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 } | ||
| }; | ||
| const dereference = (() => { | ||
| var _ref = _asyncToGenerator(function* (content, basePath, parser, resolver) { | ||
| const options = { | ||
| parse: { custom: parser }, | ||
| resolve: { custom: resolver } | ||
| }; | ||
| if (!basePath) { | ||
| _context.next = 5; | ||
| break; | ||
| } | ||
| if (basePath) { | ||
| return yield $RefParser.dereference(basePath, content, options); | ||
| } | ||
| _context.next = 4; | ||
| return $RefParser.dereference(basePath, content, options); | ||
| return yield $RefParser.dereference(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; | ||
| } | ||
| const parse = (() => { | ||
| var _ref2 = _asyncToGenerator(function* (content, options) { | ||
| if (isNil(content)) { | ||
| throw new Error('No content specified.'); | ||
| } | ||
| throw new Error('No content specified.'); | ||
| if (!isString(content) && !isObject(content)) { | ||
| throw new Error('Content must be a string or spec object.'); | ||
| } | ||
| case 2: | ||
| if (!(!isString(content) && !isObject(content))) { | ||
| _context6.next = 4; | ||
| break; | ||
| } | ||
| // TODO: validate options against schema | ||
| if (!isNil(options) && !isObject(options)) { | ||
| throw new Error('Options should be an object.'); | ||
| } | ||
| throw new Error('Content must be a string or spec object.'); | ||
| try { | ||
| const defaultOptions = { | ||
| parser: { | ||
| canParse: function (file) { | ||
| return false; | ||
| }, | ||
| parse: (() => { | ||
| var _ref3 = _asyncToGenerator(function* (file) {}); | ||
| case 4: | ||
| if (!(!isNil(options) && !isObject(options))) { | ||
| _context6.next = 6; | ||
| break; | ||
| } | ||
| return function parse(_x7) { | ||
| return _ref3.apply(this, arguments); | ||
| }; | ||
| })() | ||
| }, | ||
| resolver: { | ||
| canResolve: function (info) { | ||
| return false; | ||
| }, | ||
| resolve: (() => { | ||
| var _ref4 = _asyncToGenerator(function* (info) {}); | ||
| 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); | ||
| }; | ||
| }() | ||
| } | ||
| 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); | ||
| })); | ||
| const compiledOptions = options ? merge(defaultOptions, options) : defaultOptions; | ||
| 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 | ||
| }); | ||
| const parser = { | ||
| order: 1, | ||
| canParse: function (info) { | ||
| return compiledOptions.parser.canParse(info); | ||
| }, | ||
| parse: (() => { | ||
| var _ref5 = _asyncToGenerator(function* (info) { | ||
| return compiledOptions.parser.parse(info); | ||
| }); | ||
| case 2: | ||
| return _context5.abrupt('return', _context5.sent); | ||
| return function parse(_x9) { | ||
| return _ref5.apply(this, arguments); | ||
| }; | ||
| })() | ||
| }; | ||
| case 3: | ||
| case 'end': | ||
| return _context5.stop(); | ||
| } | ||
| } | ||
| }, _callee5, undefined); | ||
| })); | ||
| const resolver = { | ||
| order: 1, | ||
| canRead: function (info) { | ||
| return compiledOptions.resolver.canResolve({ | ||
| path: info.url, | ||
| extension: info.extension | ||
| }); | ||
| }, | ||
| read: (() => { | ||
| var _ref6 = _asyncToGenerator(function* (info) { | ||
| return yield compiledOptions.resolver.resolve({ | ||
| path: info.url, | ||
| extension: info.extension | ||
| }); | ||
| }); | ||
| return function read(_x10) { | ||
| return _ref6.apply(this, arguments); | ||
| }; | ||
| }() | ||
| }; | ||
| _context6.next = 13; | ||
| return dereference(content, compiledOptions.basePath, parser, resolver); | ||
| return function read(_x10) { | ||
| return _ref6.apply(this, arguments); | ||
| }; | ||
| })() | ||
| }; | ||
| case 13: | ||
| spec = _context6.sent; | ||
| return _context6.abrupt('return', spec); | ||
| const spec = yield dereference(content, compiledOptions.basePath, parser, resolver); | ||
| case 17: | ||
| _context6.prev = 17; | ||
| _context6.t0 = _context6['catch'](6); | ||
| throw new Error('There was an error parsing the specified spec:\n' + _context6.t0); | ||
| return spec; | ||
| } catch (error) { | ||
| throw new Error(`There was an error parsing the specified spec:\n${error}`); | ||
| } | ||
| }); | ||
| case 20: | ||
| case 'end': | ||
| return _context6.stop(); | ||
| } | ||
| } | ||
| }, _callee6, undefined, [[6, 17]]); | ||
| })); | ||
| return function parse(_x5, _x6) { | ||
| return _ref2.apply(this, arguments); | ||
| }; | ||
| }(); | ||
| })(); | ||
| module.exports = parse; |
+1
-1
| { | ||
| "name": "openapi-parse", | ||
| "version": "0.1.3", | ||
| "version": "0.1.4", | ||
| "description": "Basic parser for OpenAPI specs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
-100%6757
-36.67%118
-42.16%