ajv-validator / ajv-validator/ajv

[JTD] async keywords are not supported

Aperta
#2,029 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
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?**

I use the latest version (8.11.0).

**Ajv options object**

```javascript
{
jtd: true,
strictSchema: 'log',
strictNumbers: true,
strictTypes: true,
strictTuples: true,
verbose: true,
allErrors: true,
timestamp: 'date',
parseDate: true,
allowDate: true,
int32range: true,
passContext: true,
messages: true,
keywords: [someAsyncValidator]
}
```

**JTD Schema**

```json
{
"properties": {
"id": { "type": "string", "metadata": { "someAsyncValidator": true } }
},
"$async": true
}
```

**Sample data**

```json
{
"id": "foo_bar"
}
```

**Validation result, data AFTER validation, error messages**

With `$async: true`:
```
[Jest] Error: schema is invalid
```

Without `$async: true` (or with `metadata: { $async: true }`):
```
[Jest] Error: async keyword in sync schema
[Jest]
[Jest] at checkAsyncKeyword (../../../node_modules/ajv/lib/compile/validate/keyword.ts:117:45)
[Jest] at funcKeywordCode (../../../node_modules/ajv/lib/compile/validate/keyword.ts:41:3)
[Jest] at keywordCode (../../../node_modules/ajv/lib/compile/validate/index.ts:531:2)
[Jest] at ../../../node_modules/ajv/lib/compile/validate/index.ts:267:6
[Jest] at CodeGen.code (../../../node_modules/ajv/lib/compile/codegen/index.ts:525:33)
[Jest] at CodeGen.block (../../../node_modules/ajv/lib/compile/codegen/index.ts:680:20)
[Jest] at iterateKeywords (../../../node_modules/ajv/dist/compile/validate/index.js:221:9)
[Jest] at groupKeywords (../../../node_modules/ajv/lib/compile/validate/index.ts:250:5)
[Jest] at ../../../node_modules/ajv/lib/compile/validate/index.ts:235:5
[Jest] at CodeGen.code (../../../node_modules/ajv/lib/compile/codegen/index.ts:525:33)
```

**What results did you expect?**

For JTD schemas, the schema should be considered as async if `async: true` is present in the `metadata` object.

**Are you going to resolve the issue?**

Yes, I'll create a PR to handle `metadata.async`.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.