Do not coerce nulls to strings and numbers without explicit option
parent
60c293637d
commit
b9369ed663
|
@ -179,6 +179,7 @@ declare namespace ajv {
|
||||||
loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
|
loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
|
||||||
removeAdditional?: boolean | 'all' | 'failing';
|
removeAdditional?: boolean | 'all' | 'failing';
|
||||||
useDefaults?: boolean | 'empty' | 'shared';
|
useDefaults?: boolean | 'empty' | 'shared';
|
||||||
|
coerceNulls?: boolean;
|
||||||
coerceTypes?: boolean | 'array';
|
coerceTypes?: boolean | 'array';
|
||||||
strictDefaults?: boolean | 'log';
|
strictDefaults?: boolean | 'log';
|
||||||
strictKeywords?: boolean | 'log';
|
strictKeywords?: boolean | 'log';
|
||||||
|
|
|
@ -28,10 +28,12 @@
|
||||||
{{? $type == 'string' }}
|
{{? $type == 'string' }}
|
||||||
if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean')
|
if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean')
|
||||||
{{=$coerced}} = '' + {{=$data}};
|
{{=$coerced}} = '' + {{=$data}};
|
||||||
|
{{? it.opts.coerceNulls }}
|
||||||
else if ({{=$data}} === null) {{=$coerced}} = '';
|
else if ({{=$data}} === null) {{=$coerced}} = '';
|
||||||
|
{{?}}
|
||||||
{{?? $type == 'number' || $type == 'integer' }}
|
{{?? $type == 'number' || $type == 'integer' }}
|
||||||
if ({{=$dataType}} == 'boolean' || {{=$data}} === null
|
if ({{? it.opts.coerceNulls }}{{=$data}} === null ||{{?}}
|
||||||
|| ({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}}
|
({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}}
|
||||||
{{? $type == 'integer' }} && !({{=$data}} % 1){{?}}))
|
{{? $type == 'integer' }} && !({{=$data}} % 1){{?}}))
|
||||||
{{=$coerced}} = +{{=$data}};
|
{{=$coerced}} = +{{=$data}};
|
||||||
{{?? $type == 'boolean' }}
|
{{?? $type == 'boolean' }}
|
||||||
|
@ -39,7 +41,7 @@
|
||||||
{{=$coerced}} = false;
|
{{=$coerced}} = false;
|
||||||
else if ({{=$data}} === 'true' || {{=$data}} === 1)
|
else if ({{=$data}} === 'true' || {{=$data}} === 1)
|
||||||
{{=$coerced}} = true;
|
{{=$coerced}} = true;
|
||||||
{{?? $type == 'null' }}
|
{{?? $type == 'null' && it.opts.coerceNulls }}
|
||||||
if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false)
|
if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false)
|
||||||
{{=$coerced}} = null;
|
{{=$coerced}} = null;
|
||||||
{{?? it.opts.coerceTypes == 'array' && $type == 'array' }}
|
{{?? it.opts.coerceTypes == 'array' && $type == 'array' }}
|
||||||
|
|
Loading…
Reference in New Issue