Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fed135/swagger-route-validator
The fastest route validation middleware
https://github.com/fed135/swagger-route-validator
hacktoberfest openapi swagger validation
Last synced: 5 days ago
JSON representation
The fastest route validation middleware
- Host: GitHub
- URL: https://github.com/fed135/swagger-route-validator
- Owner: fed135
- License: other
- Created: 2019-07-09T13:53:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-30T13:34:36.000Z (over 2 years ago)
- Last Synced: 2024-11-01T20:12:26.320Z (14 days ago)
- Topics: hacktoberfest, openapi, swagger, validation
- Language: JavaScript
- Homepage:
- Size: 71.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Swagger Route Validator
---
- Extremely fast and 50% more efficient than [AJV](https://www.npmjs.com/package/ajv), the next fastest alternative
- Zero dependencies :star:
- Battle-tested by Fortune 500 companies
- Supports most OpenAPI 3.0 features like $ref, $not, $anyOf, $allOf, $oneOf, etc.
- Supports most common data formats like emails, ips, uuids, dates, etc.---
## Usage
This is an example of an express middleware, which you could easily implement if you have your routes' swagger definitions.
```javascript
import validate from 'swagger-route-validator';// Pass in the swagger spec for that route and return an express middleware
export default (routeSpec) => function validateRequest(req, res, next) {
// Check validation errors
const errors = validate(routeSpec, req);
if (errors.length > 0) return res.status(400).json(errors);next();
};
```If you don't know in advance what route definition to use on an inbound request, you can follow [this example](https://gist.github.com/fed135/7a45eab6510a78a5d514fae9a5cb6734)
## Running tests
```
npm run test
```## License
[Apache 2.0](./LICENSE) - Frederic Charette