You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

4 years ago
  1. {{## def.assignDefault:
  2. {{? it.compositeRule }}
  3. {{
  4. if (it.opts.strictDefaults) {
  5. var $defaultMsg = 'default is ignored for: ' + $passData;
  6. if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
  7. else throw new Error($defaultMsg);
  8. }
  9. }}
  10. {{??}}
  11. if ({{=$passData}} === undefined
  12. {{? it.opts.useDefaults == 'empty' }}
  13. || {{=$passData}} === null
  14. || {{=$passData}} === ''
  15. {{?}}
  16. )
  17. {{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
  18. {{= it.useDefault($sch.default) }}
  19. {{??}}
  20. {{= JSON.stringify($sch.default) }}
  21. {{?}};
  22. {{?}}
  23. #}}
  24. {{## def.defaultProperties:
  25. {{
  26. var $schema = it.schema.properties
  27. , $schemaKeys = Object.keys($schema); }}
  28. {{~ $schemaKeys:$propertyKey }}
  29. {{ var $sch = $schema[$propertyKey]; }}
  30. {{? $sch.default !== undefined }}
  31. {{ var $passData = $data + it.util.getProperty($propertyKey); }}
  32. {{# def.assignDefault }}
  33. {{?}}
  34. {{~}}
  35. #}}
  36. {{## def.defaultItems:
  37. {{~ it.schema.items:$sch:$i }}
  38. {{? $sch.default !== undefined }}
  39. {{ var $passData = $data + '[' + $i + ']'; }}
  40. {{# def.assignDefault }}
  41. {{?}}
  42. {{~}}
  43. #}}