Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null as default value for nullable strings #1980

Closed
wedi opened this issue Dec 2, 2021 · 3 comments
Closed

Allow null as default value for nullable strings #1980

wedi opened this issue Dec 2, 2021 · 3 comments
Assignees
Labels
t/bug Something isn't working

Comments

@wedi
Copy link

wedi commented Dec 2, 2021

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.
@wedi wedi changed the title Allow null as default value when nullable Allow null as default value for nullable strings Dec 2, 2021
@P0lip
Copy link
Contributor

P0lip commented Dec 29, 2021

This should be fixed by #1986.
LMK if it works.
Just make sure to upgrade @stoplight/spectral-rulesets beforehand.

@P0lip P0lip self-assigned this Dec 29, 2021
@P0lip P0lip added the t/bug Something isn't working label Dec 29, 2021
@P0lip
Copy link
Contributor

P0lip commented Dec 29, 2021

I'll close this one out in the meantime.
If you experience issues, please reach out here.
Thank you!

@P0lip P0lip closed this as completed Dec 29, 2021
@wedi
Copy link
Author

wedi commented Dec 29, 2021

I can confirm it's solved Thanks! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants