PayU / openapi-validator-middleware

Input validation using Swagger (Open API) and ajv
Apache License 2.0
144 stars 50 forks source link

Use express-ajv-swagger-validation in middleware #81

Open ghost opened 5 years ago

ghost commented 5 years ago

I am using nestjs and I use the express-ajv-swagger-validation in the middleware (couldn't figure out how to do it otherwise in nestjs and I don't need routes).

I got a crash when calling swaggerValidator.validate(req, res, next) which I fixed by manually adding the route object to the request object:

req.route = {
   path: req.path
};

Do you think its possible to check for the route property and if it does not exist use req.path? This would make express-ajv-swagger-validation a bit more flexible to use.

idanto commented 5 years ago

I think this is a very simple API use case that we probably missed, you are welcome to create a PR with this fix :)