ajv-validator / ajv-validator/ajv

`minProperties` and `removeAdditional` does not collaborate well

未關閉
#2,541 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug report
主要語言
TypeScript
星號
14.8k
分支
1k
PR 合併指標
30 天內沒有已合併 PR

描述

**What version of Ajv are you using? Does the issue happen if you use the latest version?**

latest (8.17.1)

**Ajv options object**

```javascript
{ removeAdditional: "all" }
```

**JSON Schema**

```json
{
"type": "object",
"minProperties": 1,
"properties": {
"foo": {
"type": "string"
},
"bar": {
"type": "string"
}
}
}
```

**Sample data**

```javascript
const shouldError1 = {};
const shouldError2 = { foobar: "baz" };
const shouldPass = { foo: "bar" };
```

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

```javascript
const validate = new Ajv(options).compile(schema);

const shouldError1 = {};
console.log(validate(shouldError1), shouldError1); // valid = false, data = {}

const shouldError2 = { foobar: "baz" };
console.log(validate(shouldError2), shouldError2); // valid = true, data = {}

const shouldPass = { foo: "bar" };
console.log(validate(shouldPass), shouldPass); // valid = true, data = { foo: "bar" }
```

**What results did you expect?**

The object with only additional properties is expected to have error for not satisfy the `minProperties` constraint after additional properties has been removed.

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

Currently not yet.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。