Debian Codegraph @

spec/options/schemaId.spec.ts

raw ◀ ▶
Source reconstructed at patch state 1 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 // @ts-ignore
15 validate("foo").should.equal(true)
16 // @ts-ignore
17 validate(1).should.equal(false)
18
19 should.throw(
20 () => ajv.compile({id: "mySchema2", type: "string"}),
21 /NOT SUPPORTED: keyword "id"/
22 )
23 }
24 })
25
26 it("should use $id and throw exception for id when strict: false", () => {
27 test(new _Ajv({logger: false, strict: false}))
28
29 function test(ajv: Ajv) {
30 ajv.addSchema({$id: "mySchema1", type: "string"})
31 const validate = ajv.getSchema("mySchema1")
32 assert(typeof validate == "function")
33 // @ts-ignore
34 validate("foo").should.equal(true)
35 // @ts-ignore
36 validate(1).should.equal(false)
37
38 should.throw(
39 () => ajv.compile({id: "mySchema2", type: "string"}),
40 /NOT SUPPORTED: keyword "id"/
41 )
42 should.not.exist(ajv.getSchema("mySchema2"))
43 }
44 })
45 })