Comments (3)
@paulmarshall
This message is provided by Ajv. We do minimal processing on that message.
We could attempt to process that message further or perhaps even add a hook to allow you to transform the value. However, this can already by achieved fairly easily without any new change.
For example
The following error handler will strip the first qualifier (if present), returning the message in your preferred format
e.g.
// Register error handler
app.use((err, req, res, next) => {
res.status(err.status || 500).json({
errors: errors.map(p => ({
...p,
path: p.path.match(/^\.?(query|headers|path)?\.?(.*)/)[2]})
});
});
(Note, I'm sure there is a better regex than what I came up with above)
This custom error handler will transform the error message from e.g.
[ { path: '.query.limit',
message: 'should have required property \'limit\'',
errorCode: 'required.openapi.validation' },
{ path: '.query.test',
message: 'should have required property \'test\'',
errorCode: 'required.openapi.validation' } ]
to (which i believe is your preference)
[ { path: 'limit',
message: 'should have required property \'limit\'',
errorCode: 'required.openapi.validation' },
{ path: 'test',
message: 'should have required property \'test\'',
errorCode: 'required.openapi.validation' } ]
Hope this helps
from express-openapi-validator.
@paulmarshall please reopen if the proposed solution is not satisfactory. thanks!
from express-openapi-validator.
Good workaround - works for me, but puzzling why "Ajv" would think the dot prefix was acceptable in the first instance. Oh well - thanks for looking into this.
from express-openapi-validator.
Related Issues (20)
- format: date accepts incorrect month range HOT 1
- Add support to multiple specs on the same routes
- Invalid example for NestJS. Looks like response validation is broken. HOT 2
- Type error when passing an object to apiSpec (TypeScript) HOT 1
- Request Body content-types don't consider custom parameters
- How to specify middleware handler for single endpoint HOT 1
- multipartMiddleware preceeds securityMiddleware so files begin uploading before security check HOT 3
- Security handlers cannot access request params
- The validation doesn't work at all HOT 2
- Question: should serdes.serialize be called when validateResponse=false
- Serdes Does Not Work for Items in Request Parameters in Array HOT 1
- HTTP HEAD not implemented for HTTP GET similar to ExpressJS v4.
- Multer worked on 5.0.1 throws internal server error in 5.1.0 HOT 5
- Introduction of multiple swagger docs with new endpoint now versioned returns 404 HOT 2
- the same oneOf schema can pass request validation. But cannot pass response validation
- version 5.1.1, apiKey cookie authentication results in error HOT 1
- Email format validation does not accept non-ascii characters
- Multiple spec support breaks if validateResponses: true HOT 2
- readonly is ignored when properties are inherited through allOf
- Type coercion stops working if request validation is turned off HOT 1
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 express-openapi-validator.