ajv-validator / ajv-validator/ajv
Unexpected behavior when using `removeAdditional`
- 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?**
```
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
```
**Ajv options object**
```javascript
{ keywords: ['example'], removeAdditional: "all", allErrors: true }
```
**JSON Schema**
```json
{
allOf: [
{
type: "object",
properties: {
test1: {
type: "string",
description: "Test 1",
}
}
},
{
type: "object",
properties: {
test2: {
type: "number",
description: "Test 2",
}
}
}
]
}
```
**Sample data**
```json
{
test1: "test",
test2: 123,
}
```
**Your code**
```javascript
import Ajv from "ajv";
import AjvAddFormats from "ajv-formats";
export const ajv = new Ajv({ keywords: ['example'], removeAdditional: "all", allErrors: true });
AjvAddFormats(ajv);
const validate = ajv.compile(/*sample schema*/);
const data = /*sample data*/;
console.log("Before:", data);
validate(data);
console.log("After:", data);
console.log("Errors:", validate.errors);
```
**Validation result, data AFTER validation, error messages**
```
Before: {
test1: "test",
test2: 123,
}
After: {}
Errors: null
```
**What results did you expect?**
I expected that the sample data would not be modified because it fits the schema.
**Are you going to resolve the issue?**
Most likely not.
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.