Comments (4)
Also, for anyone in the future: you can add middleware to your Express app that handles all errors, including those from validation. This it the key line from the express-openapi-validation README:
If validation errors occur,
next
is called with{status: 400, errors: [<validation errors>]}
.
You can add this code to the entry point of your node app:
app.use((err, req, res, next) => {
if (err.status) {
res.status(err.status);
}
if (err.errors) {
res.json(err.errors);
}
});
The above code will handle the error object that express-openapi-validation produces and respond with the list of validation errors as JSON.
from open-api.
@kevipapo1 this is very helpful! I agree with you 100%. Can you do some digging and possibly open a PR against express-openapi-validation
? If anything, perhaps a customer toString
method should be added to output stringified JSON.
from open-api.
Done! PR can be found here.
from open-api.
Awesome! Thanks @kevipapo1 !
from open-api.
Related Issues (20)
- [enhancement] openapi-response-validator: native ESM node modules default export not working as intended HOT 3
- [ft. request] openapi-response-validator - allow access to response param in errorTransformer HOT 1
- Using automatic paths with ESM HOT 2
- OpenAPI Types package, Path Item Object HOT 1
- Supertest integration tests fail after update to express-openapi 12.x.x
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi HOT 2
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi
- External refs not captured in parameters for request validation HOT 1
- Bug: OpenAPIResponseValidatorArgs responses object incorrectly defined
- Support for Asynchronous Custom Keywords in openapi-request-validator
- Support for validating OpenAPI 3.1
- Type narrowing
- [Bug] Custom formats not working for objects
- fs-routes is using a vulnerable version of glob HOT 1
- How to get the nice swagger page? HOT 1
- Path slash differences with Windows and Linux HOT 2
- Using `x-express-openapi-disable-validation-middleware` extension
- [openapi-types] V3.1 Schema Type Wrongly Referenced V3.0 Schema HOT 1
- Cannot disable defaults middleware HOT 1
- [openapi-request-validator] CLI & YAML support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-api.