fix: allOf with empty schemas failing compilation, fixes #381

master
Evgeny Poberezkin 2016-12-24 23:32:22 +00:00
parent 17de8aba47
commit c4335abf53
3 changed files with 86 additions and 3 deletions

View File

@ -3,11 +3,15 @@
{{# def.setupKeyword }}
{{# def.setupNextLevel }}
{{ var $currentBaseId = $it.baseId; }}
{{
var $currentBaseId = $it.baseId
, $allSchemasEmpty = true;
}}
{{~ $schema:$sch:$i }}
{{? {{# def.nonEmptySchema:$sch }} }}
{{
$allSchemasEmpty = false;
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
$it.errSchemaPath = $errSchemaPath + '/' + $i;
@ -20,7 +24,11 @@
{{~}}
{{? $breakOnError }}
{{= $closingBraces.slice(0,-1) }}
{{? $allSchemasEmpty }}
if (true) {
{{??}}
{{= $closingBraces.slice(0,-1) }}
{{?}}
{{?}}
{{# def.cleanUp }}

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "4.10.2",
"version": "4.10.3",
"description": "Another JSON Schema Validator",
"main": "lib/ajv.js",
"webpack": "dist/ajv.bundle.js",

View File

@ -0,0 +1,75 @@
[
{
"description": "allOf with one empty schema",
"schema": {
"allOf": [
{}
]
},
"tests": [
{
"description": "any data is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "allOf with two empty schemas",
"schema": {
"allOf": [
{},
{}
]
},
"tests": [
{
"description": "any data is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "allOf with two schemas, the first is empty",
"schema": {
"allOf": [
{},
{ "type": "number" }
]
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "allOf with two schemas, the second is empty",
"schema": {
"allOf": [
{ "type": "number" },
{}
]
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
}
]