ajv-validator / ajv-validator/ajv

[JTD] async keywords are not supported

Đang mở
#2,029 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
14.8k
Fork
1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.