Skip to content

Commit

Permalink
initial integration of sheldhur req validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Jul 17, 2019
1 parent 1af38e1 commit e69fd00
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"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",
Expand Down
22 changes: 16 additions & 6 deletions src/index.ts
Expand Up @@ -59,14 +59,24 @@ export class OpenApiValidator {
});
}

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

const validateMiddleware = (req, res, next) => 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,
// }),
// );
}
}
1 change: 1 addition & 0 deletions src/middlewares/index.ts
@@ -1,3 +1,4 @@
export { applyOpenApiMetadata } from './openapi.metadata';
export { validateRequest } from './openapi.request.validator';
export { RequestValidator } from './openapi.request.validator.2';
export { multipart } from './openapi.multipart';
2 changes: 1 addition & 1 deletion test/routes.spec.ts
Expand Up @@ -14,7 +14,7 @@ const basePath = (<any>app).basePath;
(<any>app).server.close();
});
describe(`GET ${basePath}/pets`, () => {
it('should throw 400 on missing required query parameter', async () =>
it.only('should throw 400 on missing required query parameter', async () =>
request(app)
.get(`${basePath}/pets`)
.set('Accept', 'application/json')
Expand Down

0 comments on commit e69fd00

Please sign in to comment.