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.53k stars 241 forks source link

Spectral parsing chokes on unexpected `null` values #1981

Open wedi opened 2 years ago

wedi commented 2 years ago

Describe the bug

Spectral fails with Cannot read properties of null (reading 'in') and exit code 2 when you use null where spectral doesn't expect it.

To Reproduce

  1. Given this

    • valid spec (#1980)
      openapi: 3.0.3
      components:
      schemas:
      test:
        type: string
        default: null
        nullable: true
    • valid spec (https://swagger.io/docs/specification/data-models/enums/#nullable)
      openapi: 3.0.3
      components:
      schemas:
      test:
        type: string
        enum:
          - foo
          - null
    • invalid Spec
      openapi: 3.0.3
      components:
      schemas:
      test:
        type: string
        enum:

    and more similar cases.

  2. Run this CLI command '....'

    yarn spectral lint test.yaml

  3. See error

    The error is always exactly the same:

    yarn spectral lint test.yaml
    yarn run v1.22.17
    $ /Users/weise/code/spectral_example/node_modules/.bin/spectral lint test.yaml
    Cannot read properties of null (reading 'in')
    error Command failed with exit code 2.

Expected behavior A clear and concise description of what's wrong or at least a hint where this happened. If you have a big file with $refs to other files it's trial and error (or diffing).

Environment (remove any that are not applicable):

yarn spectral --version     
yarn run v1.22.17
$ /Users/weise/code/spectral_example/node_modules/.bin/spectral --version
6.1.0
✨  Done in 0.87s.
tinomthomas commented 1 year ago

+1

hakandilek commented 1 year ago

null values are valid and needed especially for the enums. Is there a plan to fix this?

mikekistler commented 1 year ago

I have hit this multiple times now. Please bump up the priority on this.

hakandilek commented 1 year ago

Anyone bumping into this, please check your custom rules. You most probably have a null reference there.