
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
koa-yup-validator
Advanced tools
Koa middleware for validating and coercing request data.
yarn add yup koa-yup-validator
import createValidator from "koa-yup-validator";
const validator = createValidator(validators, options); /* see below */
Arguments
validators
{
body: schema; // validates request body
headers: schema; // validates request headers
params: schema; // validates path params
query: schema; // validates query params
}
options:
Specify options for each validator ie.
{
body: options
}
partial | Allows data to satisfy schema partially at root level (if the data key exists it must satisfy schema). Useful for example patch operations. |
yup | Options to be passed to yup validate. |
There is an optional error middleware you may use for handling errors thrown by the validation middleware:
import { createErrorMiddleware } from "koa-yup-validator";
app.use(createErrorMiddleware());
//...your routes
Validate headers and body
import * as yup from "yup";
import validator from "koa-yup-validator";
const Pizza = yup.object().shape({
name: yup.string().required(),
toppings: yup.array().of(yup.string()),
});
const RequiredHeaders = yup.object().shape({
Authorization: yup.string().required(),
"x-pizza-maker": yup.string(),
});
router.post(
"/pizza",
validator({ body: Pizza, headers: RequiredHeaders }),
(ctx) => {
console.log(ctx.request.headers["x-pizza-maker"]);
ctx.response.status = 200;
ctx.response.body = "Valid pizza!";
}
);
// Pass yup options for body
router.post(
"/strict-pizza",
validator(
{ body: Pizza, headers: RequiredHeaders },
{ body: { yup: { strict: true } } }
),
(ctx) => {
console.log(ctx.request.headers["x-pizza-maker"]);
ctx.response.status = 200;
ctx.response.body = "Valid pizza!";
}
);
FAQs
Koa middleware for validating and coercing request data.
The npm package koa-yup-validator receives a total of 175 weekly downloads. As such, koa-yup-validator popularity was classified as not popular.
We found that koa-yup-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.