npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

swagger-validation-express

v1.1.0

Published

validator middleware for express application , validation is generated from swagger file

Downloads

13

Readme

swagger-validation-express

Build Status

use your swagger file as a validation for express application

Tech

swagger-validation-express uses the open source definition of swagger to work properly:

Coming soon

  • headers validation
  • formdata validation
  • logger
  • white listing of url
  • flexible swagger file path

Installation

swagger-validation-express:

-requires Node.js v12+ to run as expected. -support typeScript -body should be parsed (use express.json() or body-parser)

1- Installing the module

$ npm i swagger-validation-express

or

$ yarn add swagger-validation-express

2- Including the swagger file in this version the module is expecting the swagger file to be as json at root level

├── package.json
├── package-lock.json
├── README.md
├── server.js
├── settings.json
├── src
├── swagger.json   //the same level with server.js and with exact name swagger.json
└── tsconfig.json

3-Use the middleware basicly theres two ways to use the module, one is flexible and the other is outside the box

import * as express from 'express';
import * as swaggerValidation from 'swagger-validation-express';
const app = express();
const PORT = 2900;
app.use(express.json());
app.use(swaggerValidation.middleware); //using the module as the midlleware
app.post('/test', (req, res) => {
    res.json({ status: 'success' });
});
app.listen(PORT);

OR

import * as express from 'express';
import * as swaggerValidation from 'swagger-validation-express';
const app = express();
const PORT = 2900;
app.use(express.json());
app.use((req, res, next) => {
    // add your own logic...
    try {
        swaggerValidation.validate(req);
        next();
    } catch (error) {
        res.status(401).json({ status: 'Rejected', message: error.message });
    }
});
app.post('/test', (req, res) => {
    res.json({ status: 'success' });
});
app.listen(PORT);

Example

Lets use our swagger file : https://github.com/uranium93/swagger-validation-express/blob/development/swagger.json and now lets try to send this request to our server

curl --location --request POST 'http://localhost:2900/service1/hjs/hold?query2=test&query1=111-dd-XRPW' \
--header 'Content-Type: application/json' \
--data-raw '{
    "key2": "string DATA",
    "record": {
        "subKey1": 12345,
        "subKey2": {
            "final": true,
            "script":"<script>some important scripts that should be allowed and well formated /script>"
        }
    }
}'

the request will be refused because script value didn't match the swagger pattern validation

{
    "status": "Rejected",
    "message": "<script>some important scripts that should be allowed and well formated <script> is not valid : ^<script>.*</script>$"
}

Development

Want to contribute? Great!

swagger-valdiation-express uses typescript for secure developing. Make a change in your file and instantaneously see your updates!

Open your favorite Terminal and run these commands.

First Tab:

$ git clone [email protected]:uranium93/swagger-validation-express.git

Second Tab:

$ cd swagger-valdiation-express

Third:

$ npm install

Fourth:

$ npm run dev

to run the development server