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

flair-doc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flair-doc - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

test/validate-test.js

50

index.js

@@ -211,7 +211,12 @@ var express = require('express')

function makeValidator(schema) {
function makeValidator(originalSchema) {
var schema = convertHeadersToLowerCase(originalSchema);
return function paramValidator(req, res, next) {
var errors = joi.validate(req.params, schema);
var errors = joi.validate(
onlySchemaFields(merge(req.params, req.query, req.headers), schema),
schema
);
if (errors) {
res.send(400, { error: errors.message });
res.send(400, { error: errors.message, details: "http://www.youtube.com/watch?v=WOdjCb4LwQY" });
} else {

@@ -223,2 +228,37 @@ next();

function convertHeadersToLowerCase(schema) {
var converted = copyProperties({}, schema);
Object.keys(converted).forEach(function(key) {
var joiType = schema[key];
if (joiType.notes === 'header') {
if (key !== key.toLowerCase()) {
converted[key.toLowerCase()] = joiType;
delete converted[key];
}
}
});
return converted;
}
function onlySchemaFields(obj, schema) {
Object.keys(obj).forEach(function(key) {
if (!schema.hasOwnProperty(key)) {
delete obj[key];
}
});
return obj;
}
function copyProperties(dest, source) {
Object.keys(source).forEach(function(property) {
dest[property] = source[property];
});
return dest;
}
function merge() {
var toMerge = Array.prototype.slice.call(arguments);
return toMerge.reduce(copyProperties, {});
}
function minOrMax(swagger, joiType, index, minOrMax) {

@@ -248,3 +288,2 @@ swagger.allowableValues = swagger.allowableValues || {};

if (joiType.type === "String") {

@@ -290,5 +329,4 @@ swaggerParam.dataType = "string";

function validate(schema) {
var middleware = makeValidator(schema);
var middleware = makeValidator(convertHeadersToLowerCase(schema));
middleware.params = convertJoiTypesToSwagger(schema);

@@ -295,0 +333,0 @@ middleware.errorResponses = [

2

package.json
{
"name": "flair-doc",
"version": "0.0.7",
"version": "0.0.8",
"description": "Swagger-compliant REST API documentation generator",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -239,3 +239,6 @@ var should = require('should')

.get('/pants/cheese')
.expect(400, { error: "not valid" }, done);
.expect(400, {
error: "not valid",
details: "http://www.youtube.com/watch?v=WOdjCb4LwQY"
}, done);
});

@@ -242,0 +245,0 @@

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