Skip to content

Commit

Permalink
Merge ecb1ffe into 1af38e1
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jul 19, 2019
2 parents 1af38e1 + ecb1ffe commit 269344b
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 137 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![](https://travis-ci.org/cdimascio/express-openapi-validator.svg?branch=master)](#) [![](https://img.shields.io/npm/v/express-openapi-validator.svg)](https://www.npmjs.com/package/express-openapi-validator) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/express-openapi-validator/badge.svg)](https://coveralls.io/github/cdimascio/express-openapi-validator) [![](https://img.shields.io/badge/license-MIT-blue.svg)](#license)

An OpenApi validator for ExpressJS that automatically validates API requests using an OpenAPI 3 specification.
An OpenApi validator for ExpressJS that automatically validates API requests using an OpenAPI 3 specification

<p align="center">
<img src="https://raw.githubusercontent.com/cdimascio/express-openapi-validator/master/assets/express-openapi-validator.png" width="500">
Expand Down
46 changes: 6 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-openapi-validator",
"version": "1.2.2",
"version": "1.3.0-rc.1",
"description": "Automatically validate API requests using an OpenAPI 3 and Express.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -24,12 +24,11 @@
"author": "Carmine DiMascio <cdimascio@gmail.com>",
"license": "MIT",
"dependencies": {
"ajv": "^6.10.2",
"js-yaml": "^3.13.1",
"lodash": "^4.17.11",
"multer": "^1.4.1",
"ono": "^5.0.1",
"openapi-request-coercer": "^2.3.0",
"openapi-request-validator": "^3.8.3",
"openapi-schema-validator": "^3.0.3",
"openapi-security-handler": "^2.0.4",
"openapi-types": "^1.3.5",
Expand Down
2 changes: 2 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ export const validationError = (
status: number,
path: string,
message: string,
errors?: any, // TODO rename - normalize...something else
) => ({
status,
errors: [
{
path,
message,
...({errors } || {})
},
],
});
23 changes: 17 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,25 @@ export class OpenApiValidator {
});
}

const aoav = new middlewares.RequestValidator(this.context.apiDoc, {
coerceTypes: true,
removeAdditional: true,
useDefaults: true,
});

const validateMiddleware = (req, res, next) => {
return aoav.validate(req, res, next);
}

app.use(
middlewares.applyOpenApiMetadata(this.context),
middlewares.multipart(this.context, this.multerOpts),
middlewares.validateRequest({
apiDoc: this.context.apiDoc,
loggingKey,
enableObjectCoercion: this.opts.enableObjectCoercion,
}),
);
validateMiddleware);
// middlewares.validateRequest({
// apiDoc: this.context.apiDoc,
// loggingKey,
// enableObjectCoercion: this.opts.enableObjectCoercion,
// }),
// );
}
}
2 changes: 1 addition & 1 deletion src/middlewares/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { applyOpenApiMetadata } from './openapi.metadata';
export { validateRequest } from './openapi.request.validator';
export { RequestValidator } from './openapi.request.validator';
export { multipart } from './openapi.multipart';

0 comments on commit 269344b

Please sign in to comment.