ajv-validator / ajv-validator/ajv

Unexpected behavior when using `removeAdditional`

Aperta
#2,546 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub
bug report
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?**
```
"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.

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.