_limit.jst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.$data }}
  5. {{## def.setExclusiveLimit:
  6. $exclusive = true;
  7. $errorKeyword = $exclusiveKeyword;
  8. $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
  9. #}}
  10. {{
  11. var $isMax = $keyword == 'maximum'
  12. , $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
  13. , $schemaExcl = it.schema[$exclusiveKeyword]
  14. , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
  15. , $op = $isMax ? '<' : '>'
  16. , $notOp = $isMax ? '>' : '<'
  17. , $errorKeyword = undefined;
  18. }}
  19. {{? $isDataExcl }}
  20. {{
  21. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
  22. , $exclusive = 'exclusive' + $lvl
  23. , $exclType = 'exclType' + $lvl
  24. , $exclIsNumber = 'exclIsNumber' + $lvl
  25. , $opExpr = 'op' + $lvl
  26. , $opStr = '\' + ' + $opExpr + ' + \'';
  27. }}
  28. var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
  29. {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
  30. var {{=$exclusive}};
  31. var {{=$exclType}} = typeof {{=$schemaValueExcl}};
  32. if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
  33. {{ var $errorKeyword = $exclusiveKeyword; }}
  34. {{# def.error:'_exclusiveLimit' }}
  35. } else if ({{# def.$dataNotType:'number' }}
  36. {{=$exclType}} == 'number'
  37. ? (
  38. ({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
  39. ? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
  40. : {{=$data}} {{=$notOp}} {{=$schemaValue}}
  41. )
  42. : (
  43. ({{=$exclusive}} = {{=$schemaValueExcl}} === true)
  44. ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
  45. : {{=$data}} {{=$notOp}} {{=$schemaValue}}
  46. )
  47. || {{=$data}} !== {{=$data}}) {
  48. var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
  49. {{??}}
  50. {{
  51. var $exclIsNumber = typeof $schemaExcl == 'number'
  52. , $opStr = $op; /*used in error*/
  53. }}
  54. {{? $exclIsNumber && $isData }}
  55. {{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
  56. if ({{# def.$dataNotType:'number' }}
  57. ( {{=$schemaValue}} === undefined
  58. || {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
  59. ? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
  60. : {{=$data}} {{=$notOp}} {{=$schemaValue}} )
  61. || {{=$data}} !== {{=$data}}) {
  62. {{??}}
  63. {{
  64. if ($exclIsNumber && $schema === undefined) {
  65. {{# def.setExclusiveLimit }}
  66. $schemaValue = $schemaExcl;
  67. $notOp += '=';
  68. } else {
  69. if ($exclIsNumber)
  70. $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
  71. if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
  72. {{# def.setExclusiveLimit }}
  73. $notOp += '=';
  74. } else {
  75. $exclusive = false;
  76. $opStr += '=';
  77. }
  78. }
  79. var $opExpr = '\'' + $opStr + '\''; /*used in error*/
  80. }}
  81. if ({{# def.$dataNotType:'number' }}
  82. {{=$data}} {{=$notOp}} {{=$schemaValue}}
  83. || {{=$data}} !== {{=$data}}) {
  84. {{?}}
  85. {{?}}
  86. {{ $errorKeyword = $errorKeyword || $keyword; }}
  87. {{# def.error:'_limit' }}
  88. } {{? $breakOnError }} else { {{?}}