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: v7.0.2
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: v7.0.3
Choose a head ref
  • 12 commits
  • 7 files changed
  • 4 contributors

Commits on Dec 20, 2020

  1. Copy the full SHA
    d153e81 View commit details

Commits on Dec 22, 2020

  1. Unverified

    The email in this signature doesn’t match the committer email.
    Copy the full SHA
    286ca0f View commit details
  2. Verified

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

Commits on Dec 23, 2020

  1. Merge pull request #1368 from G-Rath/patch-2

    fix: add `| null` to `OneOfError` param property
    epoberezkin authored Dec 23, 2020

    Verified

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

Commits on Dec 26, 2020

  1. fix range example typos

    caub committed Dec 26, 2020

    Verified

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

Commits on Dec 27, 2020

  1. Merge pull request #1370 from caub/patch-1

    fix range example typos
    epoberezkin authored Dec 27, 2020
    Copy the full SHA
    97bfa50 View commit details

Commits on Dec 30, 2020

  1. Verified

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

Commits on Jan 2, 2021

  1. Copy the full SHA
    9200e92 View commit details
  2. Merge branch 'issue1364' of https://github.com/hello-weiran/ajv into …

    …hello-weiran-issue1364
    epoberezkin committed Jan 2, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d0b1368 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
    c44597e View commit details
  4. Verified

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

    epoberezkin committed Jan 2, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ca2ae61 View commit details
Showing with 57 additions and 6 deletions.
  1. +14 −0 README.md
  2. +2 −2 docs/keywords.md
  3. +1 −0 docs/security.md
  4. +1 −2 lib/compile/validate/iterate.ts
  5. +5 −1 lib/vocabularies/applicator/oneOf.ts
  6. +1 −1 package.json
  7. +33 −0 spec/standalone.spec.ts
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ Please review [Contributing guidelines](./CONTRIBUTING.md) and [Code components]
- [Frequently Asked Questions](./docs/faq.md)
- [Using in browser](#using-in-browser)
- [Content Security Policy](./docs/security.md#content-security-policy)
- [Using in ES5 environment](#using-in-es5-environment)
- [Command line interface](#command-line-interface)
- [API reference](./docs/api.md)
- [Methods](./docs/api.md#ajv-constructor-and-methods)
@@ -307,6 +308,19 @@ The browser bundle is available on [cdnjs](https://cdnjs.com/libraries/ajv).

**Please note**: some frameworks, e.g. Dojo, may redefine global require in a way that is not compatible with CommonJS module format. In this case Ajv bundle has to be loaded before the framework and then you can use global `ajv` (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)).

## Using in ES5 environment

You need to:

- recompile Typescript to ES5 target - it is set to 2018 in the bundled compiled code.
- generate ES5 validation code:

```javascript
const ajv = new Ajv({code: {es5: true}})
```

See [Advanced options](https://github.com/ajv-validator/ajv/blob/master/docs/api.md#advanced-options).

## Command line interface

CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports:
4 changes: 2 additions & 2 deletions docs/keywords.md
Original file line number Diff line number Diff line change
@@ -87,12 +87,12 @@ ajv.addKeyword({
const {schema, parentSchema, data} = cxt
const [min, max] = schema
const eq: Code = parentSchema.exclusiveRange ? _`=` : nil
gen.fail(_`${data} <${eq} ${min} || ${data} >${eq} ${max}`)
cxt.fail(_`${data} <${eq} ${min} || ${data} >${eq} ${max}`)
},
metaSchema: {
type: "array",
items: [{type: "number"}, {type: "number"}],
minItems: 2
minItems: 2,
additionalItems: false,
},
})
1 change: 1 addition & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ Some keywords in JSON Schemas can lead to very slow validation for certain data.
You can validate your JSON schemas against [this meta-schema](../lib/refs/json-schema-secure.json) to check that these recommendations are followed:

```javascript
ajv = new Ajv({strictTypes: false}) // this option is required for this schema
const isSchemaSecure = ajv.compile(require("ajv/lib/refs/json-schema-secure.json"))

const schema1 = {format: "email"}
3 changes: 1 addition & 2 deletions lib/compile/validate/iterate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {SchemaObjCxt} from ".."
import type {JSONType, Rule, RuleGroup} from "../rules"
import {shouldUseGroup, shouldUseRule} from "./applicability"
import {checkDataType} from "./dataType"
import {checkDataType, reportTypeError} from "./dataType"
import {assignDefaults} from "./defaults"
import {reportTypeError} from "./dataType"
import {keywordCode} from "./keyword"
import {schemaHasRulesButRef} from "../util"
import {checkStrictMode} from "."
6 changes: 5 additions & 1 deletion lib/vocabularies/applicator/oneOf.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,11 @@ import {_, Name} from "../../compile/codegen"
import {alwaysValidSchema} from "../../compile/util"
import {SchemaCxt} from "../../compile"

export type OneOfError = ErrorObject<"oneOf", {passingSchemas: [number, number]}, AnySchema[]>
export type OneOfError = ErrorObject<
"oneOf",
{passingSchemas: [number, number] | null},
AnySchema[]
>

const error: KeywordErrorDefinition = {
message: "should match exactly one schema in oneOf",
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": "7.0.2",
"version": "7.0.3",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
33 changes: 33 additions & 0 deletions spec/standalone.spec.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type Ajv from "../dist/core"
import type {AnyValidateFunction} from "../dist/core"
import _Ajv from "./ajv"
import standaloneCode from "../dist/standalone"
import ajvFormats from "ajv-formats"
import requireFromString = require("require-from-string")
import assert = require("assert")

@@ -179,4 +180,36 @@ describe("standalone code generation", () => {
assert.strictEqual(validate("1"), false)
}
})

describe("standalone code with ajv-formats", () => {
const schema = {
$schema: "http://json-schema.org/draft-07/schema#",
definitions: {
User: {
type: "object",
properties: {
email: {
type: "string",
format: "email",
},
},
required: ["email"],
additionalProperties: false,
},
},
}

it("should support formats with standalone code", () => {
const ajv = new _Ajv({code: {source: true}})
ajvFormats(ajv)
ajv.addSchema(schema)
const moduleCode = standaloneCode(ajv, {validateUser: "#/definitions/User"})
const {validateUser} = requireFromString(moduleCode)

assert(typeof validateUser == "function")
assert.strictEqual(validateUser({}), false)
assert.strictEqual(validateUser({email: "foo"}), false)
assert.strictEqual(validateUser({email: "foo@bar.com"}), true)
})
})
})