Json schema validation not behaving as expected
- Dominant language
- JavaScript
- Stars
- 30
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
I created a Memory store (model) based on a simple Json Schema like this and tried to put an an invalid value, however the object was still created inside the store.
```
require(
[
'dojo/_base/declare',
'dstore/Memory',
'dmodel/extensions/jsonSchema'
],
function (declare, Memory, jsonSchema) {
var myStore = new Memory({
model: jsonSchema({
properties: {
someProperty: {
type: "number",
minimum: 0,
maximum: 10
},
}
})
});
myStore.put({ id: 1, someProperty: -21 });
});
```
Next I tried to use the String Validator like this
```
require(
[
'dojo/_base/declare',
'dstore/Memory',
'dmodel/extensions/jsonSchema',
'dmodel/validators/StringValidator'
],
function (declare, Memory, jsonSchema, StringValidator) {
var myStore = new Memory({
model: jsonSchema({
properties: {
someProperty: new StringValidator({
// must be at least 4 characters
minimumLength: 4,
// and max of 20 characters
maximumLength: 20,
// and only letters or numbers
pattern: /^\w+$/
}),
}
})
});
myStore.put({ id: 1, someProperty: '#' });
});
```
Again the property was created in the store. There were no validation errors.
Am I doing something wrong?
My end goal is to build a model from json schema, then when data is entered into the model, to validate based on the constraints defined in the schema. Data that does not match the constraints should not be put into the store. Is this even possible?
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the examples using dstore/Memory with dmodel/extensions/jsonSchema and dmodel/validators/StringValidator, starting at myStore.put. Trace whether validation is invoked during insertion and determine the existing error behavior. Done means values violating the schema or StringValidator constraints are not added to the store, with validation errors exposed as appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100