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.6.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.6.1
Choose a head ref
  • 5 commits
  • 6 files changed
  • 4 contributors

Commits on Jun 30, 2021

  1. Update typescript.md (#1661)

    pskfyi authored Jun 30, 2021
    Copy the full SHA
    c739c1e View commit details
  2. Unverified

    The email in this signature doesn’t match the committer email.
    Copy the full SHA
    f6a9ba4 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4706efd View commit details

Commits on Jul 4, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    674688c View commit details
  2. 8.6.1

    epoberezkin committed Jul 4, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9166e38 View commit details
Showing with 124 additions and 11 deletions.
  1. +7 −2 README.md
  2. +3 −3 docs/guide/typescript.md
  3. +6 −2 lib/compile/validate/index.ts
  4. +3 −3 lib/vocabularies/applicator/not.ts
  5. +1 −1 package.json
  6. +104 −0 spec/tests/issues/1668_not_with_other_keywords.json
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -105,8 +105,8 @@ Performance of different validators by [json-schema-benchmark](https://github.co
- Ajv implements JSON Schema [draft-06/07/2019-09/2020-12](http://json-schema.org/) standards (draft-04 is supported in v6):
- all validation keywords (see [JSON Schema validation keywords](https://ajv.js.org/json-schema.html))
- [OpenAPI](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) extensions:
- NEW: keyword [discriminator](https://ajv.js.org/json-schema.md#discriminator).
- keyword [nullable](https://ajv.js.org/json-schema.md#nullable).
- NEW: keyword [discriminator](https://ajv.js.org/json-schema.html#discriminator).
- keyword [nullable](https://ajv.js.org/json-schema.html#nullable).
- full support of remote references (remote schemas have to be added with `addSchema` or compiled to be available)
- support of recursive references between schemas
- correct string lengths for strings with unicode pairs
@@ -161,6 +161,11 @@ const schema = {
additionalProperties: false,
}

const data = {
foo: 1,
bar: "abc"
}

const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) console.log(validate.errors)
6 changes: 3 additions & 3 deletions docs/guide/typescript.md
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ const schema: JSONSchemaType<MyData> = {
type: "object",
properties: {
foo: {type: "integer"},
bar: {type: "string", nullable: "true"}
bar: {type: "string", nullable: true}
},
required: ["foo"],
additionalProperties: false
@@ -45,7 +45,7 @@ const validate = ajv.compile(schema)
// type parameter can be used to make it type guard:
// const validate = ajv.compile<MyData>(schema)

const validData = {
const data = {
foo: 1,
bar: "abc"
}
@@ -86,7 +86,7 @@ const validate = ajv.compile(schema)
// type parameter can be used to make it type guard:
// const validate = ajv.compile<MyData>(schema)

const validData = {
const data = {
foo: 1,
bar: "abc"
}
8 changes: 6 additions & 2 deletions lib/compile/validate/index.ts
Original file line number Diff line number Diff line change
@@ -369,7 +369,11 @@ export class KeywordCxt implements KeywordErrorCxt {
}

result(condition: Code, successAction?: () => void, failAction?: () => void): void {
this.gen.if(not(condition))
this.failResult(not(condition), successAction, failAction)
}

failResult(condition: Code, successAction?: () => void, failAction?: () => void): void {
this.gen.if(condition)
if (failAction) failAction()
else this.error()
if (successAction) {
@@ -383,7 +387,7 @@ export class KeywordCxt implements KeywordErrorCxt {
}

pass(condition: Code, failAction?: () => void): void {
this.result(condition, undefined, failAction)
this.failResult(not(condition), undefined, failAction)
}

fail(condition?: Code): void {
6 changes: 3 additions & 3 deletions lib/vocabularies/applicator/not.ts
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@ const def: CodeKeywordDefinition = {
valid
)

cxt.result(
cxt.failResult(
valid,
() => cxt.error(),
() => cxt.reset()
() => cxt.reset(),
() => cxt.error()
)
},
error: {message: "must NOT be valid"},
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.6.0",
"version": "8.6.1",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
104 changes: 104 additions & 0 deletions spec/tests/issues/1668_not_with_other_keywords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[
{
"description": "not with allOf",
"schema": {
"allOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with anyOf",
"schema": {
"anyOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with oneOf",
"schema": {
"oneOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with properties",
"schema": {
"not": {
"properties": {
"foo": {"const": true}
}
},
"properties": {
"foo": {"const": 1}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "invalid (const)",
"data": {"foo": 3},
"valid": false
},
{
"description": "invalid (not)",
"data": {"foo": true},
"valid": false
}
]
}
]