Debian Codegraph @

spec/options/schemaId.spec.ts

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 import type Ajv from "../.."
2 import _Ajv from "../ajv"
3 import * as assert from "assert"
4 import chai from "../chai"
5 const should = chai.should()
6
7 describe("removed schemaId option", () => {
8 it("should use $id and throw exception when id is used", () => {
9 test(new _Ajv({logger: false}))
10
11 function test(ajv) {
12 ajv.addSchema({$id: "mySchema1", type: "string"})
13 const validate = ajv.getSchema("mySchema1")
14 validate("foo").should.equal(true)
15 validate(1).should.equal(false)
16
17 should.throw(
18 () => ajv.compile({id: "mySchema2", type: "string"}),
19 /NOT SUPPORTED: keyword "id"/
20 )
21 }
22 })
23
24 it("should use $id and throw exception for id when strict: false", () => {
25 test(new _Ajv({logger: false, strict: false}))
26
27 function test(ajv: Ajv) {
28 ajv.addSchema({$id: "mySchema1", type: "string"})
29 const validate = ajv.getSchema("mySchema1")
30 assert(typeof validate == "function")
31 validate("foo").should.equal(true)
32 validate(1).should.equal(false)
33
34 should.throw(
35 () => ajv.compile({id: "mySchema2", type: "string"}),
36 /NOT SUPPORTED: keyword "id"/
37 )
38 should.not.exist(ajv.getSchema("mySchema2"))
39 }
40 })
41 })