feat: support numeric exclusiveMaximum/Minimum with $data, #367

master
Evgeny Poberezkin 2016-12-29 19:44:08 +00:00
parent 4a9d765e5a
commit 19512861d2
3 changed files with 18 additions and 11 deletions

View File

@ -16,22 +16,33 @@
{{
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
, $exclusive = 'exclusive' + $lvl
, $exclType = 'exclType' + $lvl
, $exclIsNumber = 'exclIsNumber' + $lvl
, $opExpr = 'op' + $lvl
, $opStr = '\' + ' + $opExpr + ' + \'';
}}
var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
{{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
var exclusive{{=$lvl}};
if (typeof {{=$schemaValueExcl}} != 'boolean' && typeof {{=$schemaValueExcl}} != 'undefined') {
var {{=$exclusive}};
var {{=$exclType}} = typeof {{=$schemaValueExcl}};
if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
{{ var $errorKeyword = $exclusiveKeyword; }}
{{# def.error:'_exclusiveLimit' }}
} else if({{# def.$dataNotType:'number' }}
((exclusive{{=$lvl}} = {{=$schemaValueExcl}} === true)
? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
: {{=$data}} {{=$notOp}} {{=$schemaValue}})
} else if ({{# def.$dataNotType:'number' }}
{{=$exclType}} == 'number'
? (
({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
: {{=$data}} {{=$notOp}} {{=$schemaValue}}
)
: (
({{=$exclusive}} = {{=$schemaValueExcl}} === true)
? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
: {{=$data}} {{=$notOp}} {{=$schemaValue}}
)
|| {{=$data}} !== {{=$data}}) {
var op{{=$lvl}} = exclusive{{=$lvl}} ? '{{=$op}}' : '{{=$op}}=';
var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
{{??}}
{{
var $exclIsNumber = typeof $schemaExcl == 'number'

View File

@ -11,7 +11,6 @@
},
"tests": [
{
"skip": true,
"description": "below the exclusiveMaximum is valid",
"data": {
"larger": 3,
@ -183,7 +182,6 @@
},
"tests": [
{
"skip": true,
"description": "valid array",
"data": ["", 0, 1, 2, 3, 4],
"valid": true

View File

@ -11,7 +11,6 @@
},
"tests": [
{
"skip": true,
"description": "above the exclusiveMinimum is valid",
"data": {
"smaller": 3,
@ -176,7 +175,6 @@
},
"tests": [
{
"skip": true,
"description": "valid array",
"data": [1, 2, 3, 4, 5, 6],
"valid": true