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), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.5k stars 238 forks source link

Using overrides to disable some rules fails #2469

Closed antusus closed 1 year ago

antusus commented 1 year ago

Chore summary I'm using spectral as a JS dependency in version 5.9.2. I'm validating output json file and some paths have lots of errors that I must postpone addressing. I wanted to use overrides to disable rules but it is not working and I have no idea what I'm doing wrong.

In my root folder I have

.spectral.yml

extends: [[spectral:oas, all]]

overrides:
  - files:
      - "**#/components/schemas/Activity/properties/tags/example"
    rules:
      oas3-valid-schema-example : "info"

openapi.json

I'm including only very small portion of my file

{
  "openapi": "3.0.2",
  "info": {
    "title": "Test",
    "version": "1.0.0"
  },
  "paths": {
  },
  "components": {
    "schemas": {
      "Activity": {
        "title": "Activity",
        "type": "object",
        "properties": {
          "tags": {
            "type": "array",
            "example": "1"
          }
        }
      }
    }
  }
}

The example is not a proper array so the validation fails as expected with:

 17:24    error  oas3-valid-schema-example      `example` property type should be array                                  components.schemas.Activity.properties.tags.example

But I specified that this should be reported as info and should not fail my test.

I'm using command

spectral lint openapi.json -F error --fail-on-unmatched-globs -v

Can you tell me what I'm doing wrong? Can I disable the oas3-valid-schema-example rule? I was trying with path: "openapi.json#/components/schemas/Activity/properties/tags/example" and it also fails.

Additional context If needed I've created sample project here: https://github.com/antusus/spectral-test and you should be able to use any node version.

P0lip commented 1 year ago

Hey! You should use Spectral 6.x. 5.9.2 does not support overrides. With 6.x it works just fine.

image

If you chose npm/yarn installation, make sure to remove @stoplight/spectral and install @stoplight/spectral-cli instead.

antusus commented 1 year ago

Hi, @P0lip any suggestion what I can use to ignore those errors in version 5 of spectral? I cannot easily upgrade to v6... looks like I have some dependency clashes.

P0lip commented 1 year ago

Spectral v5 only lets you disable the rule entirely via exceptions. You'll need to upgrade to v6 if you want to leverage overrides.

antusus commented 1 year ago

Thanks for all the answers.