if (typeof env.schema == "object")
schema = env.schema;
this.schema = env.schema;
+ this.schemaId = env.schemaId;
this.root = env.root || this;
- this.baseId = (_a = env.baseId) !== null && _a !== void 0 ? _a : resolve_1.normalizeId(schema === null || schema === void 0 ? void 0 : schema.$id);
+ this.baseId = (_a = env.baseId) !== null && _a !== void 0 ? _a : (0, resolve_1.normalizeId)(schema === null || schema === void 0 ? void 0 : schema[env.schemaId || "$id"]);
this.schemaPath = env.schemaPath;
this.localRefs = env.localRefs;
this.meta = env.meta;
const _sch = getCompilingSchema.call(this, sch);
if (_sch)
return _sch;
- const rootId = resolve_1.getFullPath(sch.root.baseId); // TODO if getFullPath removed 1 tests fails
+ const rootId = (0, resolve_1.getFullPath)(sch.root.baseId); // TODO if getFullPath removed 1 tests fails
const { es5, lines } = this.opts.code;
const { ownProperties } = this.opts;
const gen = new codegen_1.CodeGen(this.scope, { es5, lines, ownProperties });
if (sch.$async) {
_ValidationError = gen.scopeValue("Error", {
ref: validation_error_1.default,
- code: codegen_1._ `require("ajv/dist/runtime/validation_error").default`,
+ code: (0, codegen_1._) `require("ajv/dist/runtime/validation_error").default`,
});
}
const validateName = gen.scopeName("validate");
dataTypes: [],
definedProperties: new Set(),
topSchemaRef: gen.scopeValue("schema", this.opts.code.source === true
- ? { ref: sch.schema, code: codegen_1.stringify(sch.schema) }
+ ? { ref: sch.schema, code: (0, codegen_1.stringify)(sch.schema) }
: { ref: sch.schema }),
validateName,
ValidationError: _ValidationError,
baseId: sch.baseId || rootId,
schemaPath: codegen_1.nil,
errSchemaPath: sch.schemaPath || (this.opts.jtd ? "" : "#"),
- errorPath: codegen_1._ `""`,
+ errorPath: (0, codegen_1._) `""`,
opts: this.opts,
self: this,
};
let sourceCode;
try {
this._compilations.add(sch);
- validate_1.validateFunctionCode(schemaCxt);
+ (0, validate_1.validateFunctionCode)(schemaCxt);
gen.optimize(this.opts.code.optimize);
// gen.optimize(1)
const validateCode = gen.toString();
dynamicItems: items instanceof codegen_1.Name,
};
if (validate.source)
- validate.source.evaluated = codegen_1.stringify(validate.evaluated);
+ validate.source.evaluated = (0, codegen_1.stringify)(validate.evaluated);
}
sch.validate = validate;
return sch;
exports.compileSchema = compileSchema;
function resolveRef(root, baseId, ref) {
var _a;
- ref = resolve_1.resolveUrl(baseId, ref);
+ ref = (0, resolve_1.resolveUrl)(baseId, ref);
const schOrFunc = root.refs[ref];
if (schOrFunc)
return schOrFunc;
let _sch = resolve.call(this, root, ref);
if (_sch === undefined) {
const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref]; // TODO maybe localRefs should hold SchemaEnv
+ const { schemaId } = this.opts;
if (schema)
- _sch = new SchemaEnv({ schema, root, baseId });
+ _sch = new SchemaEnv({ schema, schemaId, root, baseId });
}
if (_sch === undefined)
return;
}
exports.resolveRef = resolveRef;
function inlineOrCompile(sch) {
- if (resolve_1.inlineRef(sch.schema, this.opts.inlineRefs))
+ if ((0, resolve_1.inlineRef)(sch.schema, this.opts.inlineRefs))
return sch.schema;
return sch.validate ? sch : compileSchema.call(this, sch);
}
ref // reference to resolve
) {
const p = URI.parse(ref);
- const refPath = resolve_1._getFullPath(p);
- let baseId = resolve_1.getFullPath(root.baseId);
+ const refPath = (0, resolve_1._getFullPath)(p);
+ let baseId = (0, resolve_1.getFullPath)(root.baseId);
// TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
return getJsonPointer.call(this, p, root);
}
- const id = resolve_1.normalizeId(refPath);
+ const id = (0, resolve_1.normalizeId)(refPath);
const schOrRef = this.refs[id] || this.schemas[id];
if (typeof schOrRef == "string") {
const sch = resolveSchema.call(this, root, schOrRef);
return;
if (!schOrRef.validate)
compileSchema.call(this, schOrRef);
- if (id === resolve_1.normalizeId(ref)) {
+ if (id === (0, resolve_1.normalizeId)(ref)) {
const { schema } = schOrRef;
- if (schema.$id)
- baseId = resolve_1.resolveUrl(baseId, schema.$id);
- return new SchemaEnv({ schema, root, baseId });
+ const { schemaId } = this.opts;
+ const schId = schema[schemaId];
+ if (schId)
+ baseId = (0, resolve_1.resolveUrl)(baseId, schId);
+ return new SchemaEnv({ schema, schemaId, root, baseId });
}
return getJsonPointer.call(this, p, schOrRef);
}
if (((_a = parsedRef.fragment) === null || _a === void 0 ? void 0 : _a[0]) !== "/")
return;
for (const part of parsedRef.fragment.slice(1).split("/")) {
- if (typeof schema == "boolean")
+ if (typeof schema === "boolean")
return;
- schema = schema[util_1.unescapeFragment(part)];
- if (schema === undefined)
+ const partSchema = schema[(0, util_1.unescapeFragment)(part)];
+ if (partSchema === undefined)
return;
+ schema = partSchema;
// TODO PREVENT_SCOPE_CHANGE could be defined in keyword def?
- if (!PREVENT_SCOPE_CHANGE.has(part) && typeof schema == "object" && schema.$id) {
- baseId = resolve_1.resolveUrl(baseId, schema.$id);
+ const schId = typeof schema === "object" && schema[this.opts.schemaId];
+ if (!PREVENT_SCOPE_CHANGE.has(part) && schId) {
+ baseId = (0, resolve_1.resolveUrl)(baseId, schId);
}
}
let env;
- if (typeof schema != "boolean" && schema.$ref && !util_1.schemaHasRulesButRef(schema, this.RULES)) {
- const $ref = resolve_1.resolveUrl(baseId, schema.$ref);
+ if (typeof schema != "boolean" && schema.$ref && !(0, util_1.schemaHasRulesButRef)(schema, this.RULES)) {
+ const $ref = (0, resolve_1.resolveUrl)(baseId, schema.$ref);
env = resolveSchema.call(this, root, $ref);
}
// even though resolution failed we need to return SchemaEnv to throw exception
// so that compileAsync loads missing schema.
- env = env || new SchemaEnv({ schema, root, baseId });
+ const { schemaId } = this.opts;
+ env = env || new SchemaEnv({ schema, schemaId, root, baseId });
if (env.schema !== env.root.schema)
return env;
return undefined;