stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v3.1, v3.0, and v2.0 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.35k stars 226 forks source link

Rule array-items does not support prefixItems keyword #2646

Open yethee opened 1 week ago

yethee commented 1 week ago

Describe the bug OpenAPI 3.1 inherits data types from JSON Schema 2020-12, where we can use prefixItems keyword to define tuple value, instead of items keyword. After changes from #2638 we got an error, when schema contains prefixItems:

Schemas with "type: array", require a sibling "items" field

To Reproduce

test.yaml:

---
openapi: "3.1.0"
components:
  schemas:
    IssueWithPrefixItems:
      type: array
      prefixItems:
        - type: string
        - type: integer
      minItems: 2
      maxItems: 2
      additionalItems: false

Run validation:

npx @stoplight/spectral-cli lint test.yaml

5:26    error  array-items            Schemas with "type: array", require a sibling "items" field  components.schemas.IssueWithPrefixItems

Expected behavior Field items should not be required when prefixItems field is defined.

Environment (remove any that are not applicable):

npm ls @stoplight/spectral-rulesets

`-- @stoplight/spectral-cli@6.11.1
  +-- @stoplight/spectral-ruleset-bundler@1.5.2
  | `-- @stoplight/spectral-rulesets@1.19.1 deduped
  `-- @stoplight/spectral-rulesets@1.19.1

Additional context This issue related to #2638.