Debian Codegraph @

spec/issues/1344_non_root_recursive_ref_standalone.spec.ts

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import _Ajv from "../ajv"
2 import standaloneCode from "../../dist/standalone"
3 import * as requireFromString from "require-from-string"
4 import * as assert from "assert"
5
6 const schema = {
7 $schema: "http://json-schema.org/draft-07/schema#",
8 $id: "schema",
9 $ref: "#/$defs/foo",
10 $defs: {
11 foo: {
12 type: "object",
13 properties: {
14 bar: {$ref: "#/$defs/bar"},
15 },
16 },
17 bar: {
18 oneOf: [{$ref: "#/$defs/foo"}],
19 },
20 },
21 }
22
23 describe("issue #1344: non-root recursive ref with standalone code", () => {
24 it("should compile to standalone code", () => {
25 const ajv = new _Ajv({code: {source: true}})
26 ajv.addSchema(schema)
27 const validate = ajv.getSchema("schema#/$defs/foo")
28 assert(typeof validate == "function")
29 assert.strictEqual(validate({}), true)
30
31 const moduleCode = standaloneCode(ajv, validate)
32 const standaloneValidate = requireFromString(moduleCode)
33 assert(typeof standaloneValidate == "function")
34 assert.strictEqual(standaloneValidate({}), true)
35 })
36 })