ajv-validator / ajv-validator/ajv

[Proposal] no need to check `type`, if `enum` is provided

Open
#1,965 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
14.8k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Given:

```ts
example: {
type: `string`,
enum: [`0`, `1`]
}
```

The following **shouldn't** be generated/checked:
- as it will be further checked as part of the `enum` check for the exact values

```ts
if (typeof data1 !== `string`) {
const err0 = {
instancePath: instancePath + `/example`,
schemaPath: `#/properties/example`,
keyword: `type`,
params: { type: `string` },
}
if (vErrors === null) {
vErrors = [err0]
} else {
vErrors.push(err0)
}
errors++
}
```

**What version of Ajv you are you using?** `8.11.0`

**What problem do you want to solve?** To have less generated code.

**What do you think is the correct solution to problem?** Not to check `type`, if `enum` is provided.

**Will you be able to implement it?** Yes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.