Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
fleek-validator
Advanced tools
Middleware and utilities for validating data against swagger schema's.
Requirements:
This package is to be used as middleware for Koa2 to validate swagger documentation using ctx.fleek.context
defined by fleek-context or an equivalent custom middleware. Results of the validation are mapped to ctx.fleek.validation
, including passed
, failed
, and errors
.
npm install --save fleek-validator
For a swagger example, refer to the test swagger json
const Koa = require('koa');
const fleekCtx = require('fleek-context');
const fleekValidator = require('fleek-validator');
const SWAGGER = require('./swagger.json');
let app = new Koa();
app.use(fleekCtx(SWAGGER));
app.use(fleekValidator()); // Reject promise for validation failure
// OR
app.use(fleekValidator().catch((ctx, next) => {
console.log(ctx.fleek.validation); // =>{
// passed: [Boolean],
// failed: [Boolean],
// errors: [Array({ - github.com/fleekjs/fleek-validator/blob/lib/error/index.js
// name: [String] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json
// code: [Integer] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json,
// message: [String] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json,
// parameter : { [rejected param definition from swagger doc] }
// })]
// }
return next();
}));
app.listen(3000);
throw
: Boolean - if false, do not reject the middleware promise on validation failurecatch
: Function - must act as Koa2 middleware. this will be call if validation fails, with next
referring to the next middleware in the chain. prioritized over throw
ctx.fleek.context
to perform validationctx.fleek.validation
{
passed: [Boolean],
failed: [Boolean],
errors: [Array({ - github.com/fleekjs/fleek-validator/blob/lib/error/index.js
name: [String] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json
code: [Integer] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json,
message: [String] - github.com/fleekjs/fleek-validator/blob/lib/error/codes.json,
parameter : { [rejected param definition from swagger doc] }
})]
}
app.use(validator()); // reject middleware promise on failure
app.use(validator({ throw: false })); // continue down middleware on failure
app.use(validator({ catch: (ctx, next) => { return next(); } })); // continue down middleware on failure
app.use(validator().catch((ctx, next) => { return next(); })); // continue down middleware on failure
ctx.fleek.context
to define the validationsctx.fleek.context
set by fleek-contextctx.request.body = { name: 'foo' };
validator.ctx(ctx);
validator.ctx(ctx, {
parameters: [{
name: "user",
in: "body",
schema: {
type: "object",
required: ["name"],
properties: {
name: { type: "string", uppercase: true }
}
}
}]
});
let newCtx = validator.ctx(ctx, null, true);
console.log(newCtx); // => {
// passed: false,
// failed: true,
// errors: [{
// name: 'VALUE.UPPERCASE'
// code: 207,
// message: 'Must be uppercase',
// parameter : { name: 'user.name' type: 'string', uppercase: true }
// }]
// }
// }
.errors
list of validation errorslet result = validator.object({ name: 'FOO' }, { name: { type: 'string', uppercase: true } });
console.log(result); // => { name: 'FOO' }
let result = validator.object({ name: 'foo' }, { name: { type: 'string', toUpperCase: true } });
console.log(result); // => { name: 'FOO' }
let result = validator.object({ name: 'foo' }, { name: { type: 'string', uppercase: true } });
console.log(result); // => {
// message 'Validation failed',
// errors: [{
// name: 'VALUE.UPPERCASE'
// code: 207,
// message: 'Must be uppercase',
// parameter : { type: 'string', uppercase: true }
// }]
// }
let result = validator.one('FOO', { type: 'string', uppercase: true });
console.log(result); // => 'FOO'
let result = validator.one('foo', { type: 'string', toUpperCase: true });
console.log(result); // => 'FOO'
let result = validator.one('foo', { type: 'string', uppercase: true });
console.log(result); // => {
// name: 'VALUE.UPPERCASE'
// code: 207,
// message: 'Must be uppercase',
// parameter : { type: 'string', uppercase: true }
// }
default
trim
toUpperCase
toLowerCase
required
type
maxItems
minItems
uniqueItems
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxProperties
minProperties
email
alphanumeric
lowercase
uppercase
minLength
maxLength
pattern
enum
Built and maintained with by the Hart team.
FAQs
A validator for the fleek framework
The npm package fleek-validator receives a total of 13 weekly downloads. As such, fleek-validator popularity was classified as not popular.
We found that fleek-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.