Skip to content

Commit 14b4eb6

Browse files
committed
Validate schemas in strict mode
1 parent b39adb3 commit 14b4eb6

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

examples/Duration.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@
2727
{
2828
"expression": { "Duration": [2, "years"] },
2929
"result": { "enum": [63113904] }
30-
},
31-
{
32-
"expression": { "Duration": 2 },
33-
"result": { "enum": [2] }
34-
},
35-
{
36-
"expression": { "Duration": [2] },
37-
"result": { "enum": [2] }
3830
}
3931
],
4032
"invalid": [
41-
{ "Duration": [4, "score"] }
33+
{ "Duration": [4, "score"] },
34+
{ "Duration": 2 },
35+
{ "Duration": [2] }
4236
]
4337
}

lib/validate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import schemas from '../schemas'
55
const ajv = new Ajv({
66
schemas: Object.values(schemas),
77
useDefaults: true,
8-
allErrors: true
8+
allErrors: true,
9+
strict: true
910
})
1011
addFormats(ajv)
1112
const validator = ajv.getSchema(schemas.default.$id)

schemas/Duration.schema.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
"anyOf": [
1111
{ "$ref": "#/$defs/unit" },
1212
{ "$ref": "schema.json#/$defs/function" }
13-
],
14-
"default": "seconds"
13+
]
1514
}
1615
],
17-
"minItems": 1,
16+
"minItems": 2,
1817
"maxItems": 2,
1918
"$defs": {
2019
"unit": {

0 commit comments

Comments
 (0)