ajv-validator / ajv-validator/ajv
Array `items` property should not be required in all array schemas
- 主要语言
- TypeScript
- 星标
- 14.8k
- 派生
- 1k
- PR 合并指标
- 30 天内没有已合并 PR
描述
**What version of Ajv are you using? Does the issue happen if you use the latest version?**
ajv@8.9.0
**Your typescript code**
```typescript
const schema: JSONSchemaType = { type: 'array' }
```
OR
```typescript
const schema: JSONSchemaType = { type: 'array', contains: { type: 'number' } }
```
**Typescript compiler error messages**
```
TS2322: Type '{ type: "array"; }' is not assignable to type 'UncheckedJSONSchemaType'. Type '{ type: "array"; }' is not assignable to type '{ type: "array"; items: UncheckedJSONSchemaType; contains?: UncheckedPartialSchema | undefined; minItems?: number | undefined; ... 4 more ...; additionalItems?: undefined; } & { ...; } & { ...; }'. Property 'items' is missing in type '{ type: "array"; }' but required in type '{ type: "array"; items: UncheckedJSONSchemaType; contains?: UncheckedPartialSchema | undefined; minItems?: number | undefined; ... 4 more ...; additionalItems?: undefined; }'.
```
**Describe the change that should be made to address the issue?**
When using the `contains` keyword, the `items` property should not be defined.
Json Schema Docs: https://json-schema.org/understanding-json-schema/reference/array.html#contains
```typescript
type UncheckedJSONSchemaType = (
...
: T extends readonly any[]
? {
type: JSONType<"array", IsPartial>
items: UncheckedJSONSchemaType
// ^^^^ Should be made optional
contains?: UncheckedPartialSchema
minItems?: number
maxItems?: number
minContains?: number
maxContains?: number
uniqueItems?: true
additionalItems?: never
}
...
)
```
**Are you going to resolve the issue?**
This could be as simple as making the `items` property optional. This is the simplest and probably the most accurate solution.
PR https://github.com/ajv-validator/ajv/pull/1888
贡献指南
评估
这个 Issue 还没有评估数据。