ajv-validator / ajv-validator/ajv
ajv-keywords typeof function and default
- Lingua principale
- TypeScript
- Stelle
- 14.8k
- Fork
- 1k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
**What version of Ajv are you using? Does the issue happen if you use the latest version?**
6.12.2
**Ajv options object**
```javascript
{ useDefaults: true }
```
**JSON Schema**
```js
{
"type": "object",
"properties": {
"foo": { "typeof": "function", "default": () => {} }
}
}
```
**Sample data**
See below.
**Your code**
https://runkit.com/satazor/5eac34960c2691001afd90ab
**Validation result, data AFTER validation, error messages**
Throws:
> should pass \"typeof\" keyword validation
**What results did you expect?**
Because the `foo` prop has a default set to `() => {}`, it should not throw.
The **issue** is that `ajv` is doing `JSON.stringify` on the default value, to clone values. However, that should not be done for functions, and possible other types.
~~Using `{ useDefaults: 'shared' }` fixes the issue, but it does introduce other problematic side-effects.~~ Actually, there's a missing `function` entry here: https://github.com/epoberezkin/ajv/blob/3b735371e74bf847146e07b59172a6d4485cc44a/lib/compile/index.js#L238
**Are you going to resolve the issue?**
I may try.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.