MCPcopy Index your code
hub / github.com/json-editor/json-editor / dynamicRef

Function dynamicRef

docs/scripts/ajv-validator.js:6007–6043  ·  view source on GitHub ↗
(cxt, ref)

Source from the content-addressed store, hash-verified

6005 code: (cxt) => dynamicRef(cxt, cxt.schema),
6006 };
6007 function dynamicRef(cxt, ref) {
6008 const { gen, keyword, it } = cxt;
6009 if (ref[0] !== "#")
6010 throw new Error(`"${keyword}" only supports hash fragment reference`);
6011 const anchor = ref.slice(1);
6012 if (it.allErrors) {
6013 _dynamicRef();
6014 }
6015 else {
6016 const valid = gen.let("valid", false);
6017 _dynamicRef(valid);
6018 cxt.ok(valid);
6019 }
6020 function _dynamicRef(valid) {
6021 // TODO the assumption here is that `recursiveRef: #` always points to the root
6022 // of the schema object, which is not correct, because there may be $id that
6023 // makes # point to it, and the target schema may not contain dynamic/recursiveAnchor.
6024 // Because of that 2 tests in recursiveRef.json fail.
6025 // This is a similar problem to #815 (`$id` doesn't alter resolution scope for `{ "$ref": "#" }`).
6026 // (This problem is not tested in JSON-Schema-Test-Suite)
6027 if (it.schemaEnv.root.dynamicAnchors[anchor]) {
6028 const v = gen.let("_v", (0, codegen_1._) `${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`);
6029 gen.if(v, _callRef(v, valid), _callRef(it.validateName, valid));
6030 }
6031 else {
6032 _callRef(it.validateName, valid)();
6033 }
6034 }
6035 function _callRef(validate, valid) {
6036 return valid
6037 ? () => gen.block(() => {
6038 (0, ref_1.callRef)(cxt, validate);
6039 gen.let(valid, true);
6040 })
6041 : () => (0, ref_1.callRef)(cxt, validate);
6042 }
6043 }
6044 exports.dynamicRef = dynamicRef;
6045 exports.default = def;
6046//# sourceMappingURL=dynamicRef.js.map

Callers 1

ajv-validator.jsFile · 0.85

Calls 3

_dynamicRefFunction · 0.85
letMethod · 0.80
okMethod · 0.80

Tested by

no test coverage detected