Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.8.0
Choose a base ref
...
head repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.8.1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Nov 16, 2021

  1. Copy the full SHA
    683de4e View commit details
  2. Unverified

    The email in this signature doesn’t match the committer email.
    Copy the full SHA
    1959de4 View commit details
  3. 8.8.1

    epoberezkin committed Nov 16, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4cc0cad View commit details
Showing with 26 additions and 8 deletions.
  1. +2 −2 docs/standalone.md
  2. +4 −5 lib/vocabularies/applicator/contains.ts
  3. +1 −1 package.json
  4. +19 −0 spec/issues/1819_mincontains.spec.ts
4 changes: 2 additions & 2 deletions docs/standalone.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ This functionality in Ajv v7 supersedes deprecated package ajv-pack that can be

## Usage with CLI

In most cases you would use this functionality via [ajv-cli](https://github.com/jessedc/ajv-cli) (>= 4.0.0) to generate module that exports validation function.
In most cases you would use this functionality via [ajv-cli](https://github.com/ajv-validator/ajv-cli) (>= 4.0.0) to generate module that exports validation function.

```sh
npm install -g ajv-cli
@@ -21,7 +21,7 @@ ajv compile -s schema.json -o validate_schema.js

`validate_schema.js` will contain the module exporting validation function that can be bundled into your application.

See [ajv-cli](https://github.com/jessedc/ajv-cli) docs for additional information.
See [ajv-cli](https://github.com/ajv-validator/ajv-cli) docs for additional information.

## Usage from code

9 changes: 4 additions & 5 deletions lib/vocabularies/applicator/contains.ts
Original file line number Diff line number Diff line change
@@ -63,13 +63,12 @@ const def: CodeKeywordDefinition = {
const valid = gen.name("valid")
if (max === undefined && min === 1) {
validateItems(valid, () => gen.if(valid, () => gen.break()))
} else if (min === 0) {
gen.let(valid, true)
if (max !== undefined) gen.if(_`${data}.length > 0`, validateItemsWithCount)
} else {
gen.let(valid, false)
if (min === 0) {
gen.if(_`${data}.length > 0`, validateItemsWithCount, () => gen.assign(valid, true))
} else {
validateItemsWithCount()
}
validateItemsWithCount()
}
cxt.result(valid, () => cxt.reset())

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "8.8.0",
"version": "8.8.1",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
19 changes: 19 additions & 0 deletions spec/issues/1819_mincontains.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import _Ajv from "../ajv2020"
import * as assert from "assert"

describe("`minContains: 0` without valid items (issue #1819)", () => {
const ajv = new _Ajv()

const schema = {
type: "array",
minContains: 0,
maxContains: 1,
contains: {type: "number"},
}

const validate = ajv.compile(schema)

it("no items valid", () => assert.strictEqual(validate(["foo"]), true))
it("1 item valid", () => assert.strictEqual(validate(["foo", 1]), true))
it("2 items invalid", () => assert.strictEqual(validate(["foo", 1, 2]), false))
})