Comparing version 8.9.0 to 8.10.0
@@ -10,3 +10,2 @@ "use strict"; | ||
const validate_1 = require("./validate"); | ||
const URI = require("uri-js"); | ||
class SchemaEnv { | ||
@@ -40,3 +39,3 @@ constructor(env) { | ||
return _sch; | ||
const rootId = (0, resolve_1.getFullPath)(sch.root.baseId); // TODO if getFullPath removed 1 tests fails | ||
const rootId = (0, resolve_1.getFullPath)(this.opts.uriResolver, sch.root.baseId); // TODO if getFullPath removed 1 tests fails | ||
const { es5, lines } = this.opts.code; | ||
@@ -132,3 +131,3 @@ const { ownProperties } = this.opts; | ||
var _a; | ||
ref = (0, resolve_1.resolveUrl)(baseId, ref); | ||
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref); | ||
const schOrFunc = root.refs[ref]; | ||
@@ -179,5 +178,5 @@ if (schOrFunc) | ||
) { | ||
const p = URI.parse(ref); | ||
const refPath = (0, resolve_1._getFullPath)(p); | ||
let baseId = (0, resolve_1.getFullPath)(root.baseId); | ||
const p = this.opts.uriResolver.parse(ref); | ||
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver, p); | ||
let baseId = (0, resolve_1.getFullPath)(this.opts.uriResolver, root.baseId, undefined); | ||
// TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests | ||
@@ -204,3 +203,3 @@ if (Object.keys(root.schema).length > 0 && refPath === baseId) { | ||
if (schId) | ||
baseId = (0, resolve_1.resolveUrl)(baseId, schId); | ||
baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId); | ||
return new SchemaEnv({ schema, schemaId, root, baseId }); | ||
@@ -232,3 +231,3 @@ } | ||
if (!PREVENT_SCOPE_CHANGE.has(part) && schId) { | ||
baseId = (0, resolve_1.resolveUrl)(baseId, schId); | ||
baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId); | ||
} | ||
@@ -238,3 +237,3 @@ } | ||
if (typeof schema != "boolean" && schema.$ref && !(0, util_1.schemaHasRulesButRef)(schema, this.RULES)) { | ||
const $ref = (0, resolve_1.resolveUrl)(baseId, schema.$ref); | ||
const $ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schema.$ref); | ||
env = resolveSchema.call(this, root, $ref); | ||
@@ -241,0 +240,0 @@ } |
@@ -298,3 +298,3 @@ "use strict"; | ||
if (!refSchema) | ||
throw new ref_error_1.default("", ref, `No definition ${ref}`); | ||
throw new ref_error_1.default(self.opts.uriResolver, "", ref, `No definition ${ref}`); | ||
if (!(0, ref_1.hasRef)(refSchema)) | ||
@@ -301,0 +301,0 @@ return parseCode({ ...cxt, schema: refSchema }); |
@@ -200,3 +200,3 @@ "use strict"; | ||
if (!refSchema) | ||
throw new ref_error_1.default("", ref, `No definition ${ref}`); | ||
throw new ref_error_1.default(self.opts.uriResolver, "", ref, `No definition ${ref}`); | ||
if (!(0, ref_1.hasRef)(refSchema)) | ||
@@ -203,0 +203,0 @@ return serializeCode({ ...cxt, schema: refSchema }); |
@@ -0,5 +1,6 @@ | ||
import type { UriResolver } from "../types"; | ||
export default class MissingRefError extends Error { | ||
readonly missingRef: string; | ||
readonly missingSchema: string; | ||
constructor(baseId: string, ref: string, msg?: string); | ||
constructor(resolver: UriResolver, baseId: string, ref: string, msg?: string); | ||
} |
@@ -5,6 +5,6 @@ "use strict"; | ||
class MissingRefError extends Error { | ||
constructor(baseId, ref, msg) { | ||
constructor(resolver, baseId, ref, msg) { | ||
super(msg || `can't resolve reference ${ref} from id ${baseId}`); | ||
this.missingRef = (0, resolve_1.resolveUrl)(baseId, ref); | ||
this.missingSchema = (0, resolve_1.normalizeId)((0, resolve_1.getFullPath)(this.missingRef)); | ||
this.missingRef = (0, resolve_1.resolveUrl)(resolver, baseId, ref); | ||
this.missingSchema = (0, resolve_1.normalizeId)((0, resolve_1.getFullPath)(resolver, this.missingRef)); | ||
} | ||
@@ -11,0 +11,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import type { AnySchema, AnySchemaObject } from "../types"; | ||
import type { AnySchema, AnySchemaObject, UriResolver } from "../types"; | ||
import type Ajv from "../ajv"; | ||
import * as URI from "uri-js"; | ||
import type { URIComponents } from "uri-js"; | ||
export declare type LocalRefs = { | ||
@@ -8,6 +8,6 @@ [Ref in string]?: AnySchemaObject; | ||
export declare function inlineRef(schema: AnySchema, limit?: boolean | number): boolean; | ||
export declare function getFullPath(id?: string, normalize?: boolean): string; | ||
export declare function _getFullPath(p: URI.URIComponents): string; | ||
export declare function getFullPath(resolver: UriResolver, id?: string, normalize?: boolean): string; | ||
export declare function _getFullPath(resolver: UriResolver, p: URIComponents): string; | ||
export declare function normalizeId(id: string | undefined): string; | ||
export declare function resolveUrl(baseId: string, id: string): string; | ||
export declare function resolveUrl(resolver: UriResolver, baseId: string, id: string): string; | ||
export declare function getSchemaRefs(this: Ajv, schema: AnySchema, baseId: string): LocalRefs; |
@@ -7,3 +7,2 @@ "use strict"; | ||
const traverse = require("json-schema-traverse"); | ||
const URI = require("uri-js"); | ||
// TODO refactor to use keyword definitions | ||
@@ -73,11 +72,12 @@ const SIMPLE_INLINED = new Set([ | ||
} | ||
function getFullPath(id = "", normalize) { | ||
function getFullPath(resolver, id = "", normalize) { | ||
if (normalize !== false) | ||
id = normalizeId(id); | ||
const p = URI.parse(id); | ||
return _getFullPath(p); | ||
const p = resolver.parse(id); | ||
return _getFullPath(resolver, p); | ||
} | ||
exports.getFullPath = getFullPath; | ||
function _getFullPath(p) { | ||
return URI.serialize(p).split("#")[0] + "#"; | ||
function _getFullPath(resolver, p) { | ||
const serialized = resolver.serialize(p); | ||
return serialized.split("#")[0] + "#"; | ||
} | ||
@@ -90,5 +90,5 @@ exports._getFullPath = _getFullPath; | ||
exports.normalizeId = normalizeId; | ||
function resolveUrl(baseId, id) { | ||
function resolveUrl(resolver, baseId, id) { | ||
id = normalizeId(id); | ||
return URI.resolve(baseId, id); | ||
return resolver.resolve(baseId, id); | ||
} | ||
@@ -100,6 +100,6 @@ exports.resolveUrl = resolveUrl; | ||
return {}; | ||
const { schemaId } = this.opts; | ||
const { schemaId, uriResolver } = this.opts; | ||
const schId = normalizeId(schema[schemaId] || baseId); | ||
const baseIds = { "": schId }; | ||
const pathPrefix = getFullPath(schId, false); | ||
const pathPrefix = getFullPath(uriResolver, schId, false); | ||
const localRefs = {}; | ||
@@ -118,3 +118,5 @@ const schemaRefs = new Set(); | ||
function addRef(ref) { | ||
ref = normalizeId(baseId ? URI.resolve(baseId, ref) : ref); | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const _resolve = this.opts.uriResolver.resolve; | ||
ref = normalizeId(baseId ? _resolve(baseId, ref) : ref); | ||
if (schemaRefs.has(ref)) | ||
@@ -121,0 +123,0 @@ throw ambiguos(ref); |
@@ -145,3 +145,3 @@ "use strict"; | ||
if (schId) | ||
it.baseId = (0, resolve_1.resolveUrl)(it.baseId, schId); | ||
it.baseId = (0, resolve_1.resolveUrl)(it.opts.uriResolver, it.baseId, schId); | ||
} | ||
@@ -148,0 +148,0 @@ function checkAsyncSchema(it) { |
@@ -13,3 +13,3 @@ export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, ErrorNoParams, } from "./types"; | ||
export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen"; | ||
import type { Schema, AnySchema, AnySchemaObject, SchemaObject, AsyncSchema, Vocabulary, KeywordDefinition, AddedKeywordDefinition, AnyValidateFunction, ValidateFunction, AsyncValidateFunction, ErrorObject, Format, AddedFormat, RegExpEngine } from "./types"; | ||
import type { Schema, AnySchema, AnySchemaObject, SchemaObject, AsyncSchema, Vocabulary, KeywordDefinition, AddedKeywordDefinition, AnyValidateFunction, ValidateFunction, AsyncValidateFunction, ErrorObject, Format, AddedFormat, RegExpEngine, UriResolver } from "./types"; | ||
import type { JSONSchemaType } from "./types/json-schema"; | ||
@@ -72,2 +72,3 @@ import type { JTDSchemaType, SomeJTDSchemaType, JTDDataType } from "./types/jtd-schema"; | ||
code?: CodeOptions; | ||
uriResolver?: UriResolver; | ||
} | ||
@@ -97,3 +98,3 @@ export interface CodeOptions { | ||
declare type RequiredInstanceOptions = { | ||
[K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "schemaId" | "addUsedSchema" | "validateSchema" | "validateFormats" | "int32range" | "unicodeRegExp"]: NonNullable<Options[K]>; | ||
[K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "schemaId" | "addUsedSchema" | "validateSchema" | "validateFormats" | "int32range" | "unicodeRegExp" | "uriResolver"]: NonNullable<Options[K]>; | ||
} & { | ||
@@ -100,0 +101,0 @@ code: InstanceCodeOptions; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const $dataRefSchema = require("./refs/data.json"); | ||
const uri_1 = require("./runtime/uri"); | ||
const defaultRegExp = (str, flags) => new RegExp(str, flags); | ||
@@ -66,3 +67,3 @@ defaultRegExp.code = "new RegExp"; | ||
function requiredOptions(o) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; | ||
const s = o.strict; | ||
@@ -72,20 +73,22 @@ const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize; | ||
const regExp = (_c = (_b = o.code) === null || _b === void 0 ? void 0 : _b.regExp) !== null && _c !== void 0 ? _c : defaultRegExp; | ||
const uriResolver = (_d = o.uriResolver) !== null && _d !== void 0 ? _d : uri_1.default; | ||
return { | ||
strictSchema: (_e = (_d = o.strictSchema) !== null && _d !== void 0 ? _d : s) !== null && _e !== void 0 ? _e : true, | ||
strictNumbers: (_g = (_f = o.strictNumbers) !== null && _f !== void 0 ? _f : s) !== null && _g !== void 0 ? _g : true, | ||
strictTypes: (_j = (_h = o.strictTypes) !== null && _h !== void 0 ? _h : s) !== null && _j !== void 0 ? _j : "log", | ||
strictTuples: (_l = (_k = o.strictTuples) !== null && _k !== void 0 ? _k : s) !== null && _l !== void 0 ? _l : "log", | ||
strictRequired: (_o = (_m = o.strictRequired) !== null && _m !== void 0 ? _m : s) !== null && _o !== void 0 ? _o : false, | ||
strictSchema: (_f = (_e = o.strictSchema) !== null && _e !== void 0 ? _e : s) !== null && _f !== void 0 ? _f : true, | ||
strictNumbers: (_h = (_g = o.strictNumbers) !== null && _g !== void 0 ? _g : s) !== null && _h !== void 0 ? _h : true, | ||
strictTypes: (_k = (_j = o.strictTypes) !== null && _j !== void 0 ? _j : s) !== null && _k !== void 0 ? _k : "log", | ||
strictTuples: (_m = (_l = o.strictTuples) !== null && _l !== void 0 ? _l : s) !== null && _m !== void 0 ? _m : "log", | ||
strictRequired: (_p = (_o = o.strictRequired) !== null && _o !== void 0 ? _o : s) !== null && _p !== void 0 ? _p : false, | ||
code: o.code ? { ...o.code, optimize, regExp } : { optimize, regExp }, | ||
loopRequired: (_p = o.loopRequired) !== null && _p !== void 0 ? _p : MAX_EXPRESSION, | ||
loopEnum: (_q = o.loopEnum) !== null && _q !== void 0 ? _q : MAX_EXPRESSION, | ||
meta: (_r = o.meta) !== null && _r !== void 0 ? _r : true, | ||
messages: (_s = o.messages) !== null && _s !== void 0 ? _s : true, | ||
inlineRefs: (_t = o.inlineRefs) !== null && _t !== void 0 ? _t : true, | ||
schemaId: (_u = o.schemaId) !== null && _u !== void 0 ? _u : "$id", | ||
addUsedSchema: (_v = o.addUsedSchema) !== null && _v !== void 0 ? _v : true, | ||
validateSchema: (_w = o.validateSchema) !== null && _w !== void 0 ? _w : true, | ||
validateFormats: (_x = o.validateFormats) !== null && _x !== void 0 ? _x : true, | ||
unicodeRegExp: (_y = o.unicodeRegExp) !== null && _y !== void 0 ? _y : true, | ||
int32range: (_z = o.int32range) !== null && _z !== void 0 ? _z : true, | ||
loopRequired: (_q = o.loopRequired) !== null && _q !== void 0 ? _q : MAX_EXPRESSION, | ||
loopEnum: (_r = o.loopEnum) !== null && _r !== void 0 ? _r : MAX_EXPRESSION, | ||
meta: (_s = o.meta) !== null && _s !== void 0 ? _s : true, | ||
messages: (_t = o.messages) !== null && _t !== void 0 ? _t : true, | ||
inlineRefs: (_u = o.inlineRefs) !== null && _u !== void 0 ? _u : true, | ||
schemaId: (_v = o.schemaId) !== null && _v !== void 0 ? _v : "$id", | ||
addUsedSchema: (_w = o.addUsedSchema) !== null && _w !== void 0 ? _w : true, | ||
validateSchema: (_x = o.validateSchema) !== null && _x !== void 0 ? _x : true, | ||
validateFormats: (_y = o.validateFormats) !== null && _y !== void 0 ? _y : true, | ||
unicodeRegExp: (_z = o.unicodeRegExp) !== null && _z !== void 0 ? _z : true, | ||
int32range: (_0 = o.int32range) !== null && _0 !== void 0 ? _0 : true, | ||
uriResolver: uriResolver, | ||
}; | ||
@@ -92,0 +95,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import * as URI from "uri-js"; | ||
import type { CodeGen, Code, Name, ScopeValueSets, ValueScopeName } from "../compile/codegen"; | ||
@@ -177,2 +178,7 @@ import type { SchemaEnv, SchemaCxt, SchemaObjCxt } from "../compile"; | ||
} | ||
export interface UriResolver { | ||
parse(uri: string): URI.URIComponents; | ||
resolve(base: string, path: string): string; | ||
serialize(component: URI.URIComponents): string; | ||
} | ||
export {}; |
@@ -21,3 +21,3 @@ "use strict"; | ||
if (schOrEnv === undefined) | ||
throw new ref_error_1.default(baseId, $ref); | ||
throw new ref_error_1.default(it.opts.uriResolver, baseId, $ref); | ||
if (schOrEnv instanceof compile_1.SchemaEnv) | ||
@@ -24,0 +24,0 @@ return callValidate(schOrEnv); |
@@ -30,4 +30,5 @@ "use strict"; | ||
const refSchema = (_a = root.schema.definitions) === null || _a === void 0 ? void 0 : _a[ref]; | ||
if (!refSchema) | ||
throw new ref_error_1.default("", ref, `No definition ${ref}`); | ||
if (!refSchema) { | ||
throw new ref_error_1.default(it.opts.uriResolver, "", ref, `No definition ${ref}`); | ||
} | ||
if (hasRef(refSchema) || !it.opts.inlineRefs) | ||
@@ -34,0 +35,0 @@ callValidate(refSchema); |
@@ -115,3 +115,3 @@ import type { | ||
if (_sch) return _sch | ||
const rootId = getFullPath(sch.root.baseId) // TODO if getFullPath removed 1 tests fails | ||
const rootId = getFullPath(this.opts.uriResolver, sch.root.baseId) // TODO if getFullPath removed 1 tests fails | ||
const {es5, lines} = this.opts.code | ||
@@ -212,3 +212,3 @@ const {ownProperties} = this.opts | ||
): AnySchema | SchemaEnv | undefined { | ||
ref = resolveUrl(baseId, ref) | ||
ref = resolveUrl(this.opts.uriResolver, baseId, ref) | ||
const schOrFunc = root.refs[ref] | ||
@@ -262,5 +262,5 @@ if (schOrFunc) return schOrFunc | ||
): SchemaEnv | undefined { | ||
const p = URI.parse(ref) | ||
const refPath = _getFullPath(p) | ||
let baseId = getFullPath(root.baseId) | ||
const p = this.opts.uriResolver.parse(ref) | ||
const refPath = _getFullPath(this.opts.uriResolver, p) | ||
let baseId = getFullPath(this.opts.uriResolver, root.baseId, undefined) | ||
// TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests | ||
@@ -285,3 +285,3 @@ if (Object.keys(root.schema).length > 0 && refPath === baseId) { | ||
const schId = schema[schemaId] | ||
if (schId) baseId = resolveUrl(baseId, schId) | ||
if (schId) baseId = resolveUrl(this.opts.uriResolver, baseId, schId) | ||
return new SchemaEnv({schema, schemaId, root, baseId}) | ||
@@ -314,3 +314,3 @@ } | ||
if (!PREVENT_SCOPE_CHANGE.has(part) && schId) { | ||
baseId = resolveUrl(baseId, schId) | ||
baseId = resolveUrl(this.opts.uriResolver, baseId, schId) | ||
} | ||
@@ -320,3 +320,3 @@ } | ||
if (typeof schema != "boolean" && schema.$ref && !schemaHasRulesButRef(schema, this.RULES)) { | ||
const $ref = resolveUrl(baseId, schema.$ref) | ||
const $ref = resolveUrl(this.opts.uriResolver, baseId, schema.$ref) | ||
env = resolveSchema.call(this, root, $ref) | ||
@@ -323,0 +323,0 @@ } |
@@ -345,3 +345,3 @@ import type Ajv from "../../core" | ||
const refSchema = definitions[ref] | ||
if (!refSchema) throw new MissingRefError("", ref, `No definition ${ref}`) | ||
if (!refSchema) throw new MissingRefError(self.opts.uriResolver, "", ref, `No definition ${ref}`) | ||
if (!hasRef(refSchema)) return parseCode({...cxt, schema: refSchema}) | ||
@@ -348,0 +348,0 @@ const {root} = schemaEnv |
@@ -237,3 +237,3 @@ import type Ajv from "../../core" | ||
const refSchema = definitions[ref] | ||
if (!refSchema) throw new MissingRefError("", ref, `No definition ${ref}`) | ||
if (!refSchema) throw new MissingRefError(self.opts.uriResolver, "", ref, `No definition ${ref}`) | ||
if (!hasRef(refSchema)) return serializeCode({...cxt, schema: refSchema}) | ||
@@ -240,0 +240,0 @@ const {root} = schemaEnv |
import {resolveUrl, normalizeId, getFullPath} from "./resolve" | ||
import type {UriResolver} from "../types" | ||
@@ -7,7 +8,7 @@ export default class MissingRefError extends Error { | ||
constructor(baseId: string, ref: string, msg?: string) { | ||
constructor(resolver: UriResolver, baseId: string, ref: string, msg?: string) { | ||
super(msg || `can't resolve reference ${ref} from id ${baseId}`) | ||
this.missingRef = resolveUrl(baseId, ref) | ||
this.missingSchema = normalizeId(getFullPath(this.missingRef)) | ||
this.missingRef = resolveUrl(resolver, baseId, ref) | ||
this.missingSchema = normalizeId(getFullPath(resolver, this.missingRef)) | ||
} | ||
} |
@@ -1,7 +0,7 @@ | ||
import type {AnySchema, AnySchemaObject} from "../types" | ||
import type {AnySchema, AnySchemaObject, UriResolver} from "../types" | ||
import type Ajv from "../ajv" | ||
import type {URIComponents} from "uri-js" | ||
import {eachItem} from "./util" | ||
import * as equal from "fast-deep-equal" | ||
import * as traverse from "json-schema-traverse" | ||
import * as URI from "uri-js" | ||
@@ -70,10 +70,11 @@ // the hash of local references inside the schema (created by getSchemaRefs), used for inline resolution | ||
export function getFullPath(id = "", normalize?: boolean): string { | ||
export function getFullPath(resolver: UriResolver, id = "", normalize?: boolean): string { | ||
if (normalize !== false) id = normalizeId(id) | ||
const p = URI.parse(id) | ||
return _getFullPath(p) | ||
const p = resolver.parse(id) | ||
return _getFullPath(resolver, p) | ||
} | ||
export function _getFullPath(p: URI.URIComponents): string { | ||
return URI.serialize(p).split("#")[0] + "#" | ||
export function _getFullPath(resolver: UriResolver, p: URIComponents): string { | ||
const serialized = resolver.serialize(p) | ||
return serialized.split("#")[0] + "#" | ||
} | ||
@@ -86,5 +87,5 @@ | ||
export function resolveUrl(baseId: string, id: string): string { | ||
export function resolveUrl(resolver: UriResolver, baseId: string, id: string): string { | ||
id = normalizeId(id) | ||
return URI.resolve(baseId, id) | ||
return resolver.resolve(baseId, id) | ||
} | ||
@@ -96,6 +97,6 @@ | ||
if (typeof schema == "boolean") return {} | ||
const {schemaId} = this.opts | ||
const {schemaId, uriResolver} = this.opts | ||
const schId = normalizeId(schema[schemaId] || baseId) | ||
const baseIds: {[JsonPtr in string]?: string} = {"": schId} | ||
const pathPrefix = getFullPath(schId, false) | ||
const pathPrefix = getFullPath(uriResolver, schId, false) | ||
const localRefs: LocalRefs = {} | ||
@@ -114,3 +115,5 @@ const schemaRefs: Set<string> = new Set() | ||
function addRef(this: Ajv, ref: string): string { | ||
ref = normalizeId(baseId ? URI.resolve(baseId, ref) : ref) | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const _resolve = this.opts.uriResolver.resolve | ||
ref = normalizeId(baseId ? _resolve(baseId, ref) : ref) | ||
if (schemaRefs.has(ref)) throw ambiguos(ref) | ||
@@ -117,0 +120,0 @@ schemaRefs.add(ref) |
@@ -180,3 +180,3 @@ import type { | ||
const schId = it.schema[it.opts.schemaId] | ||
if (schId) it.baseId = resolveUrl(it.baseId, schId) | ||
if (schId) it.baseId = resolveUrl(it.opts.uriResolver, it.baseId, schId) | ||
} | ||
@@ -183,0 +183,0 @@ |
@@ -52,2 +52,3 @@ export { | ||
RegExpEngine, | ||
UriResolver, | ||
} from "./types" | ||
@@ -64,5 +65,6 @@ import type {JSONSchemaType} from "./types/json-schema" | ||
import {eachItem} from "./compile/util" | ||
import * as $dataRefSchema from "./refs/data.json" | ||
import DefaultUriResolver from "./runtime/uri" | ||
const defaultRegExp: RegExpEngine = (str, flags) => new RegExp(str, flags) | ||
@@ -141,2 +143,3 @@ defaultRegExp.code = "new RegExp" | ||
code?: CodeOptions // NEW | ||
uriResolver?: UriResolver | ||
} | ||
@@ -232,3 +235,4 @@ | ||
| "int32range" | ||
| "unicodeRegExp"]: NonNullable<Options[K]> | ||
| "unicodeRegExp" | ||
| "uriResolver"]: NonNullable<Options[K]> | ||
} & {code: InstanceCodeOptions} | ||
@@ -246,2 +250,3 @@ | ||
const regExp = o.code?.regExp ?? defaultRegExp | ||
const uriResolver = o.uriResolver ?? DefaultUriResolver | ||
return { | ||
@@ -265,2 +270,3 @@ strictSchema: o.strictSchema ?? s ?? true, | ||
int32range: o.int32range ?? true, | ||
uriResolver: uriResolver, | ||
} | ||
@@ -267,0 +273,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import * as URI from "uri-js" | ||
import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen" | ||
@@ -234,1 +235,7 @@ import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile" | ||
} | ||
export interface UriResolver { | ||
parse(uri: string): URI.URIComponents | ||
resolve(base: string, path: string): string | ||
serialize(component: URI.URIComponents): string | ||
} |
@@ -19,3 +19,3 @@ import type {CodeKeywordDefinition, AnySchema} from "../../types" | ||
const schOrEnv = resolveRef.call(self, root, baseId, $ref) | ||
if (schOrEnv === undefined) throw new MissingRefError(baseId, $ref) | ||
if (schOrEnv === undefined) throw new MissingRefError(it.opts.uriResolver, baseId, $ref) | ||
if (schOrEnv instanceof SchemaEnv) return callValidate(schOrEnv) | ||
@@ -22,0 +22,0 @@ return inlineRefSchema(schOrEnv) |
@@ -31,3 +31,5 @@ import type {CodeKeywordDefinition, AnySchemaObject} from "../../types" | ||
const refSchema = (root.schema as AnySchemaObject).definitions?.[ref] | ||
if (!refSchema) throw new MissingRefError("", ref, `No definition ${ref}`) | ||
if (!refSchema) { | ||
throw new MissingRefError(it.opts.uriResolver, "", ref, `No definition ${ref}`) | ||
} | ||
if (hasRef(refSchema) || !it.opts.inlineRefs) callValidate(refSchema) | ||
@@ -34,0 +36,0 @@ else inlineRefSchema(refSchema) |
{ | ||
"name": "ajv", | ||
"version": "8.9.0", | ||
"version": "8.10.0", | ||
"description": "Another JSON Schema Validator", | ||
@@ -86,2 +86,3 @@ "main": "dist/ajv.js", | ||
"eslint-config-prettier": "^7.0.0", | ||
"fast-uri": "^1.0.0", | ||
"glob": "^7.0.0", | ||
@@ -88,0 +89,0 @@ "husky": "^7.0.1", |
@@ -15,2 +15,3 @@ <img align="right" alt="Ajv logo" width="160" src="https://ajv.js.org/img/ajv.svg"> | ||
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master) | ||
[![SimpleX](https://img.shields.io/badge/chat-on%20SimpleX-%2307b4b9)](https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2Fap4lMFzfXF8Hzmh-Vz0WNxp_1jKiOa-h%23MCowBQYDK2VuAyEAcdefddRvDfI8iAuBpztm_J3qFucj8MDZoVs_2EcMTzU%3D) | ||
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) | ||
@@ -17,0 +18,0 @@ [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1016629
466
19860
194
41