ajv-validator / ajv-validator/ajv

Unexpected behavior when using `removeAdditional`

Offen
#2,546 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug report
Vorherrschende Sprache
TypeScript
Sterne
14.8k
Forks
1k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.