Skip to content

Allow null as default value for nullable strings #1980

Closed
@wedi

Description

@wedi

Describe the bug

myProperty:
  type: string
  nullable: true
  default: null

fails validation with an obscure error message:

Cannot read properties of null (reading 'in')
error Command failed with exit code 2.

Setting null as default value is perfectly fine which has been clarified in the spec version 3.0.3.
See: OAI/OpenAPI-Specification#2057 (comment) and OAI/OpenAPI-Specification#2115 (comment).

To Reproduce

  1. Given this OpenAPI/AsyncAPI document '...'
cat <<EOF > test.yaml
openapi: 3.0.3
components:
  schemas:
    myProperty:
      type: string
      default: null
      nullable: true
EOF
  1. Run this CLI command '....'

yarn spectral lint test.yaml

  1. See error
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

  • I expected the schema to pass validation.
  • I expected a clearer error message but I'll fill another issue for this – probably buggy – behaviour.

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.

Metadata

Metadata

Assignees

Labels

t/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions