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

minContains: 0 broken, requires at least one element. #1819

Closed
Zubnix opened this issue Nov 16, 2021 · 4 comments
Closed

minContains: 0 broken, requires at least one element. #1819

Zubnix opened this issue Nov 16, 2021 · 4 comments

Comments

@Zubnix
Copy link

Zubnix commented Nov 16, 2021

What version of Ajv are you using? Does the issue happen if you use the latest version?
8.8.0. Yes

Example code

        import Ajv from 'ajv/dist/2020'
        const ajv = new Ajv()
        const validate = ajv.compile({
            type: 'array',
            minContains: 0,
            maxContains: 1,
            contains: { type: 'number' },
        })
       // outputs false, should be true
        console.log(validate(['apple']))
       // outputs true
        console.log(validate(['apple', 1]))
       // outputs false
        console.log(validate(['apple', 1, 2]))
@epoberezkin
Copy link
Member

surprised it's not caught by JSON Schema test-suite

epoberezkin added a commit that referenced this issue Nov 16, 2021
@epoberezkin
Copy link
Member

epoberezkin commented Nov 16, 2021

also at first I thought it was a regression in 8.7 from fixing some JSON Schema Test Suite tests, but it looks like it was there before... Which means it's not particularly widely used.

Anyway, good catch, thanks @Zubnix

epoberezkin added a commit that referenced this issue Nov 16, 2021
@epoberezkin
Copy link
Member

fixed in 8.8.1

@SoAsEr
Copy link
Contributor

SoAsEr commented Jun 6, 2023

This works for me if I use 2020 spec, but not 2019 spec. Is this intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants