Skip to content

Commit

Permalink
feat: option ignoredDefaults to log when defaults are ignored, #957
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Feb 23, 2019
1 parent 2aa49ae commit f59c995
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
26 changes: 16 additions & 10 deletions lib/dot/defaults.def
@@ -1,15 +1,21 @@
{{## def.assignDefault:
if ({{=$passData}} === undefined
{{? it.opts.useDefaults == 'empty' }}
|| {{=$passData}} === null
|| {{=$passData}} === ''
{{? it.compositeRule }}
{{? it.opts.ignoredDefaults }}
{{ it.logger.warn('default is ignored for: ' + $passData); }}
{{?}}
)
{{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
{{= it.useDefault($sch.default) }}
{{??}}
{{= JSON.stringify($sch.default) }}
{{?}};
{{??}}
if ({{=$passData}} === undefined
{{? it.opts.useDefaults == 'empty' }}
|| {{=$passData}} === null
|| {{=$passData}} === ''
{{?}}
)
{{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
{{= it.useDefault($sch.default) }}
{{??}}
{{= JSON.stringify($sch.default) }}
{{?}};
{{?}}
#}}


Expand Down
5 changes: 4 additions & 1 deletion lib/dot/validate.jst
Expand Up @@ -72,6 +72,9 @@

it.dataPathArr = [undefined];
}}
{{? it.opts.ignoredDefaults && it.schema.default !== undefined }}
{{ it.logger.warn('default is ignored in the schema root'); }}
{{?}}

var vErrors = null; {{ /* don't edit, used in replace */ }}
var errors = 0; {{ /* don't edit, used in replace */ }}
Expand Down Expand Up @@ -177,7 +180,7 @@
{{? $rulesGroup.type }}
if ({{= it.util.checkDataType($rulesGroup.type, $data) }}) {
{{?}}
{{? it.opts.useDefaults && !it.compositeRule }}
{{? it.opts.useDefaults }}
{{? $rulesGroup.type == 'object' && it.schema.properties }}
{{# def.defaultProperties }}
{{?? $rulesGroup.type == 'array' && Array.isArray(it.schema.items) }}
Expand Down

0 comments on commit f59c995

Please sign in to comment.