Comments (2)
I suspect I may have recently fixed the issue with incorrect dataPath reporting in version 0.4.9 (it was issue #9).
Please try using the latest version (0.4.10 - there is another important fix). If you are still seeing the issue please post your schema, data and results (errors) here.
Thanks for helping me making it better ;)
from ajv.
Ok, I've figured what it was about.
The choice I've made was to put the object path in dataPath rather than the property, because it is the object that is being validated rather than its property.
So if you had additionalProperty keyword in some sub-object, you would have it's path in dataPath.
Although this is more consistent with the rest of the validation keywords, I agree that it is useful to have the actual additional property in error.dataPath.
So I added it in 0.4.15.
var schema = {
properties: {
foo: {},
bar: {}
},
additionalProperties: false
};
var data = { foo: 1, bar: 2, baz: 3, quux: 4 };
var ajv = Ajv({allErrors: true});
var valid = ajv.validate(schema, data);
console.log(ajv.errors);
There will be two errors in the array, with dataPaths "['baz']"
and "['.quux']"
. (It would have been easy to replace them with ".baz"
and ".quux"
, but as it's not a compile time replacement, I decided to keep it faster - you can map/slice your properties out of these errors.
So if you want to remove additional properties you could do smth like this:
ajv.errors
.filter(function(err) { return err.keyword == 'additionalProperties'; })
.map(function(err) { return err.dataPath.slice(2,-2); })
.forEach(function(p) { delete data[p]; });
It'll be just a bit more complex for properties in sub-objects.
from ajv.
Related Issues (20)
- Ref within def does not act consistently
- JSONSchemaType $ref doesn't work in array type. HOT 5
- oneOf returns unwanted errors HOT 1
- Description key set as boolean returns error that it must be string HOT 2
- Validate and infer JSON Schema validated data type: introducing type providers HOT 3
- JTD schema parser errors on empty properties field HOT 1
- Implement x-inOrder subschema for in order or sequential processing HOT 3
- additionalProperties shouldn't affect TypeScript types from JTDDataType HOT 2
- option compile from addKeyword doesn't change on a remove and then add again
- OneOf validation issue HOT 1
- Cannot find module 'ajv/dist/compile/codegen' HOT 2
- How can I make a property value depend on the value of another property? HOT 1
- Error using multipleOf with decimals HOT 1
- Using if/then/else fails validation HOT 1
- compileParser does not appear to support properties with type `field?: Record<string, unknown>` via `JTDSchemaType`. HOT 2
- Integers as Discriminators HOT 7
- How can I access `definitions` in schema-store using `$ref`?
- DeprecationWarning: The punycode module is deprecated #96 HOT 2
- `maxLength` constraint checking seems to not code (Hindi) unicode characters properly HOT 7
- ajv 8.13.0 upgrade doesn't work with ajv-formats 3.0.1 with TypeScript HOT 4
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 ajv.