oas-normalize
Advanced tools
Comparing version 0.0.3 to 0.0.5
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); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances 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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
140545
28
1
2
1
4
778
4