Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oas-normalize

Package Overview
Dependencies
Maintainers
7
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oas-normalize - npm Package Compare versions

Comparing version 0.0.3 to 0.0.5

.DS_Store

85

oas.js

@@ -1,13 +0,3 @@

/* TODO:
* - documentation
* - errors
* - functions
* - credits
* - promise support
* - convert from v2 -> v3
*/
const r2 = require('r2')
const r2 = require('r2');
const fs = require('fs');
const YAML = require('yamljs');
const $RefParser = require('json-schema-ref-parser');

@@ -19,2 +9,3 @@ const deepClone = require('deep-extend');

const v3 = require('./validators/v3.js');
const utils = require('./lib/utils');

@@ -41,5 +32,5 @@ class OAS {

const success = (obj) => {
obj = utils.stringToJSON(obj);
this.f_load = obj;
cb(null, obj);
const ret = utils.stringToJSON(obj);
this.f_load = ret;
cb(null, ret);
};

@@ -49,6 +40,6 @@

return success(this.file);
} else if(this.type === 'buffer') {
} else if (this.type === 'buffer') {
return success(this.file.toString());
} else if (this.type === 'url') {
let resp = await r2.get(this.file).text;
const resp = await r2.get(this.file).text;
return success(resp);

@@ -58,3 +49,3 @@ } else if (this.type === 'path') {

if (!this.opts.enablePaths) {
return cb(new Error("Use opts.enablePaths to enable accessing local files"));
return cb(new Error('Use opts.enablePaths to enable accessing local files'));
}

@@ -65,3 +56,3 @@

} else {
cb(new Error("Could not load this file"));
cb(new Error('Could not load this file'));
}

@@ -75,4 +66,4 @@ }

if (err) return cb(err);
$RefParser.bundle(schema, (err, _schema) => {
if (err) return cb(err);
$RefParser.bundle(schema, (err2, _schema) => {
if (err2) return cb(err2);
this.out.bundle = _schema;

@@ -89,4 +80,4 @@ cb(null, _schema);

if (err) return cb(err);
$RefParser.dereference(schema, (err, _schema) => {
if (err) return cb(err);
$RefParser.dereference(schema, (err2, _schema) => {
if (err2) return cb(err2);
this.out.deref = _schema;

@@ -102,9 +93,9 @@ cb(null, _schema);

const baseVersion = parseInt(utils.version(schema));
const baseVersion = parseInt(utils.version(schema), 10);
const done = (err, out) => {
if (err) return cb(err);
const done = (err2, out) => {
if (err2) return cb(err2);
if (out && convertToLatest) {
return converter.convertObj(out, {}, (err, options) => {
return converter.convertObj(out, {}, (err3, options) => {
cb(null, options.openapi);

@@ -115,3 +106,3 @@ });

}
}
};

@@ -140,44 +131,4 @@ if (baseVersion === 1) {

}
}
const utils = {
// YAML or JSON string to JSON Object
stringToJSON : (string) => {
if (typeof string === 'object') {
return deepClone({}, string);
} else if (string.match(/^\s*{/)) {
return JSON.parse(string);
} else {
return YAML.parse(string);
}
},
type : (obj) => {
if (utils.isBuffer(obj)) {
return 'buffer';
} if (typeof obj === 'object') {
return 'json';
} else if (typeof obj === 'string') {
if (obj.match(/\s*{/)) {
return 'string-json';
}
if (obj.match(/\n/)) { // Not sure about this...
return 'string-yaml';
}
if (obj.substr(0, 4) === 'http') {
return 'url';
}
return 'path';
}
return false;
},
version: schema => schema.swagger || schema.openapi,
isBuffer: obj => obj != null && obj.constructor != null &&
typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj),
};
module.exports = OAS;
{
"name": "oas-normalize",
"version": "0.0.3",
"version": "0.0.5",
"description": "Swagger 2 or OAS 3? YAML or JSON? URL, path, string or object? Who cares! It just works.",
"main": "oas.js",
"repository": {
"type": "git",
"url": "git://github.com/readmeio/oas-normalize.git"
},
"bugs": {
"url": "https://github.com/readmeio/oas-normalize/issues"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"lint": "eslint -f unix .",
"test": "jest --coverage"
},
"author": "",
"license": "ISC",
"license": "MIT",
"dependencies": {

@@ -18,3 +25,9 @@ "deep-extend": "^0.6.0",

"yamljs": "^0.3.0"
},
"devDependencies": {
"eslint": "^6.4.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.2",
"jest": "^24.9.0"
}
}
const swagger = require('swagger-parser');
module.exports = (el, cb) => {
swagger.validate(el.out.deref, (err, out) => {
swagger.validate(el.out.deref, (err) => {
if (err) {

@@ -9,10 +9,14 @@ if (err.details && err.details.length) {

errors: [{
message: err.details[0].message,
path: err.details[0].path,
}], full: err});
message: err.details[0].message,
path: err.details[0].path,
}],
full: err,
});
} else {
return cb({
errors: [{
message: err.message.replace(/\[object Object\]/g, 'Schema')
}], full: err});
message: err.message.replace(/\[object Object\]/g, 'Schema'),
}],
full: err,
});
}

@@ -19,0 +23,0 @@ } else {

@@ -8,4 +8,6 @@ const validator = require('swagger2openapi/validate.js');

errors: [{
message: err.message,
}], full: err});
message: err.message,
}],
full: err,
});
} else {

@@ -12,0 +14,0 @@ cb(null, el.out.deref);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc