New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bravado-core

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bravado-core - npm Package Compare versions

Comparing version 0.9.0 to 0.11.0

136

lib/api-definition.js

@@ -11,2 +11,4 @@ var jsonRefs = require('json-refs');

var traverse = require('traverse');
var camelCase = require('lodash.camelcase');
var dir = require('node-dir');
var errors = require('./errors');

@@ -39,2 +41,16 @@

Object.defineProperty(ApiDefinition.prototype, 'resolveRefs', {
enumerable: false,
value: function () {
var refsOptions = {
relativeBase: this['x-bravado-sourceFile'],
filter: [ 'local', 'relative', 'remote' ]
};
return jsonRefs.resolveRefs(this, refsOptions)
.then(function (results) {
return results.resolved;
});
}
});
Object.defineProperty(ApiDefinition.prototype, 'saveJson', {

@@ -94,18 +110,110 @@ enumerable: false,

var doc = yaml.safeLoad(data);
var refsOptions = {
relativeBase: path.dirname(source),
filter: [ 'relative', 'remote' ],
loaderOptions: {
processContent: function (res, cb) {
cb(null, yaml.safeLoad(res.text));
doc['x-bravado-sourceFile'] = source;
var api = new ApiDefinition(doc);
return api;
});
};
ApiDefinition.build = function (root, options) {
var sourceDir = path.resolve(root);
var index = path.resolve(root, 'api.yaml');
var resourceDir = path.resolve(root, 'resources');
var defDir = path.resolve(root, 'definitions');
var exampleDir = path.resolve(root, 'examples');
return q.nfcall(fs.readFile, index)
.then(function loadApi(data) {
var doc = yaml.safeLoad(data);
doc.resources = doc.resources || {};
doc.definitions = doc.definitions || {};
doc.examples = doc.examples || {};
return [doc, q.nfcall(dir.files, resourceDir)];
})
.spread(function readResources(doc, files) {
return q.all(files.map(function (file) {
var ext = path.extname(file);
if (ext === '.json' || ext === '.yaml' || ext === '.yml') {
var base = path.basename(file, ext);
return q.all([doc, camelCase(base), q.nfcall(fs.readFile, file)]);
} else { return null; }
}));
})
.then(function parseResources(resources) {
var doc;
resources.forEach(function (item) {
if (!item) { return; }
if (!doc) { doc = item[0]; }
doc.resources[item[1]] = yaml.safeLoad(item[2]);
});
return q.all([doc, q.nfcall(dir.files, defDir)]);
})
.spread(function readDefs(doc, files) {
return q.all(files.map(function (file) {
var ext = path.extname(file);
if (ext === '.json' || ext === '.yaml' || ext === '.yml') {
var base = path.basename(file, ext);
var rel = path.relative(defDir, file);
if (rel[0] === '_') { return null; }
var jpath = path.dirname(rel).split(path.sep);
jpath.push(camelCase(base));
return q.all([doc, jpath, q.nfcall(fs.readFile, file)]);
} else { return null; }
}));
})
.then(function parseDefs(defs) {
var doc;
defs.forEach(function (item) {
if (!item) { return; }
if (!doc) { doc = item[0]; }
var obj = doc.definitions;
item[1].forEach(function (part, i) {
if (part[0] === '_' || part[0] === '.') { return false; }
if (i < item[1].length - 1) {
if (!obj[part]) {
obj[part] = {};
}
obj = obj[part];
} else {
obj[part] = yaml.safeLoad(item[2]);
}
}
};
return jsonRefs.resolveRefs(doc, refsOptions);
});
});
return q.all([doc, q.nfcall(dir.files, exampleDir)]);
})
.then(function (results) {
var api = results.resolved;
api['x-bravado-sourceFile'] = source;
var def = new ApiDefinition(api);
return def;
.spread(function readExamples(doc, files) {
return q.all(files.map(function (file) {
var ext = path.extname(file);
if (ext === '.json' || ext === '.yaml' || ext === '.yml') {
var base = path.basename(file, ext);
var rel = path.relative(exampleDir, file);
if (rel[0] === '_') { return null; }
var jpath = path.dirname(rel).split(path.sep);
jpath.push(camelCase(base));
return q.all([doc, jpath, q.nfcall(fs.readFile, file)]);
} else { return null; }
}));
})
.then(function parseExamples(examples) {
var doc;
examples.forEach(function (item) {
if (!item) { return; }
if (!doc) { doc = item[0]; }
var obj = doc.examples;
item[1].forEach(function (part, i) {
if (part[0] === '_' || part[0] === '.') { return false; }
if (i < item[1].length - 1) {
if (!obj[part]) {
obj[part] = {};
}
obj = obj[part];
} else {
obj[part] = yaml.safeLoad(item[2]);
}
});
});
return doc;
})
.then(function (doc) {
doc['x-bravado-sourceFile'] = index;
var api = new ApiDefinition(doc);
return api;
});

@@ -112,0 +220,0 @@ };

4

package.json
{
"name": "bravado-core",
"version": "0.9.0",
"version": "0.11.0",
"description": "REST (Level 3/HATEOAS) API Framework",

@@ -35,2 +35,4 @@ "directories": {

"jsonwebtoken": "^5.5.4",
"lodash.camelcase": "^4.1.1",
"node-dir": "^0.1.12",
"object-assign": "^3.0.0",

@@ -37,0 +39,0 @@ "q": "^1.4.1",

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