
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
mongoose-payload-validator
Advanced tools
A lightweight middleware for schema validation in Mongoose and Express.
A middleware for validating request payloads against a Mongoose schema in Express.js applications using JavaScript. This package ensures the incoming request body adheres to the Mongoose schema structure, type definitions, and required constraints.
Install via npm:
npm install mongoose-payload-validator
validatePayload
middleware.const express = require("express");
const mongoose = require("mongoose");
const validatePayload = require("mongoose-payload-validator");
const app = express();
app.use(express.json());
// Define a Mongoose schema
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true },
age: { type: Number },
role: { type: String, enum: ["admin", "user", "guest"] },
});
// Middleware to validate request body
app.post("/user", validatePayload(userSchema), (req, res) => {
res.json({ message: "User data is valid!" });
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
const postSchema = new mongoose.Schema({
title: { type: String, required: true },
author: {
name: { type: String, required: true },
email: { type: String, required: true },
},
tags: [{ type: String }],
});
// Apply middleware
app.post("/post", validatePayload(postSchema), (req, res) => {
res.json({ message: "Post data is valid!" });
});
When validation fails, the middleware responds with a detailed error message:
Example error response:
{
"error": {
"statusCode": 422,
"name": "UnprocessableEntityError",
"message": "The request body is invalid. See error object `details` property for more info.",
"details": [
{
"path": "email",
"message": "must have required property 'email'"
},
{
"path": "age",
"message": "must be of type 'number', received 'string'"
}
]
}
}
This project is licensed under the MIT License. See the LICENSE file for details.
This version clearly states that the middleware is specifically for use in Express.js with JavaScript
FAQs
A lightweight middleware for schema validation in Mongoose and Express.
The npm package mongoose-payload-validator receives a total of 2 weekly downloads. As such, mongoose-payload-validator popularity was classified as not popular.
We found that mongoose-payload-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.