mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-29 16:57:00 +08:00
Fix install deps script on Python 3
We ran into "RuntimeError: OrderedDict mutated during iteration" when running this script. The problem was that we were mutating the `pkg_data` while also iterating over it. Per https://stackoverflow.com/a/52549728 the fix is to copy the package data and pop from there. R=jacktfranklin@chromium.org Bug: 1304218 Change-Id: Ibaeb3f1e26ca346c794984311c082bb2f9e672c9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3509847 Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
3ea21da3c7
commit
ece3c51ea2
+1
@@ -12,6 +12,7 @@ Supports JSON Schema draft-04/06/07/2019-09/2020-12 ([draft-04 support](https://
|
||||
[](https://www.npmjs.com/package/ajv)
|
||||
[](https://www.npmjs.com/package/ajv)
|
||||
[](https://coveralls.io/github/ajv-validator/ajv?branch=master)
|
||||
[](https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2Fap4lMFzfXF8Hzmh-Vz0WNxp_1jKiOa-h%23MCowBQYDK2VuAyEAcdefddRvDfI8iAuBpztm_J3qFucj8MDZoVs_2EcMTzU%3D)
|
||||
[](https://gitter.im/ajv-validator/ajv)
|
||||
[](https://github.com/sponsors/epoberezkin)
|
||||
|
||||
|
||||
+8
-9
@@ -7,7 +7,6 @@ const names_1 = require("./names");
|
||||
const resolve_1 = require("./resolve");
|
||||
const util_1 = require("./util");
|
||||
const validate_1 = require("./validate");
|
||||
const URI = require("uri-js");
|
||||
class SchemaEnv {
|
||||
constructor(env) {
|
||||
var _a;
|
||||
@@ -36,7 +35,7 @@ function compileSchema(sch) {
|
||||
const _sch = getCompilingSchema.call(this, sch);
|
||||
if (_sch)
|
||||
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;
|
||||
const { ownProperties } = this.opts;
|
||||
const gen = new codegen_1.CodeGen(this.scope, { es5, lines, ownProperties });
|
||||
@@ -127,7 +126,7 @@ function compileSchema(sch) {
|
||||
exports.compileSchema = compileSchema;
|
||||
function resolveRef(root, baseId, ref) {
|
||||
var _a;
|
||||
ref = (0, resolve_1.resolveUrl)(baseId, ref);
|
||||
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
||||
const schOrFunc = root.refs[ref];
|
||||
if (schOrFunc)
|
||||
return schOrFunc;
|
||||
@@ -173,9 +172,9 @@ ref // reference to resolve
|
||||
function resolveSchema(root, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
|
||||
ref // reference to resolve
|
||||
) {
|
||||
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
|
||||
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
|
||||
return getJsonPointer.call(this, p, root);
|
||||
@@ -197,7 +196,7 @@ ref // reference to resolve
|
||||
const { schemaId } = this.opts;
|
||||
const schId = schema[schemaId];
|
||||
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 });
|
||||
}
|
||||
return getJsonPointer.call(this, p, schOrRef);
|
||||
@@ -224,12 +223,12 @@ function getJsonPointer(parsedRef, { baseId, schema, root }) {
|
||||
// TODO PREVENT_SCOPE_CHANGE could be defined in keyword def?
|
||||
const schId = typeof schema === "object" && schema[this.opts.schemaId];
|
||||
if (!PREVENT_SCOPE_CHANGE.has(part) && schId) {
|
||||
baseId = (0, resolve_1.resolveUrl)(baseId, schId);
|
||||
baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId);
|
||||
}
|
||||
}
|
||||
let env;
|
||||
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);
|
||||
}
|
||||
// even though resolution failed we need to return SchemaEnv to throw exception
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -295,7 +295,7 @@ function parseRef(cxt) {
|
||||
const { ref } = schema;
|
||||
const refSchema = definitions[ref];
|
||||
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))
|
||||
return parseCode({ ...cxt, schema: refSchema });
|
||||
const { root } = schemaEnv;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -197,7 +197,7 @@ function serializeRef(cxt) {
|
||||
const { ref } = schema;
|
||||
const refSchema = definitions[ref];
|
||||
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))
|
||||
return serializeCode({ ...cxt, schema: refSchema });
|
||||
const { root } = schemaEnv;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+2
-1
@@ -1,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);
|
||||
}
|
||||
|
||||
+3
-3
@@ -2,10 +2,10 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const resolve_1 = require("./resolve");
|
||||
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));
|
||||
}
|
||||
}
|
||||
exports.default = MissingRefError;
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"ref_error.js","sourceRoot":"","sources":["../../lib/compile/ref_error.ts"],"names":[],"mappings":";;AAAA,uCAA8D;AAE9D,MAAqB,eAAgB,SAAQ,KAAK;IAIhD,YAAY,MAAc,EAAE,GAAW,EAAE,GAAY;QACnD,KAAK,CAAC,GAAG,IAAI,2BAA2B,GAAG,YAAY,MAAM,EAAE,CAAC,CAAA;QAChE,IAAI,CAAC,UAAU,GAAG,IAAA,oBAAU,EAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QACzC,IAAI,CAAC,aAAa,GAAG,IAAA,qBAAW,EAAC,IAAA,qBAAW,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;IAChE,CAAC;CACF;AATD,kCASC"}
|
||||
{"version":3,"file":"ref_error.js","sourceRoot":"","sources":["../../lib/compile/ref_error.ts"],"names":[],"mappings":";;AAAA,uCAA8D;AAG9D,MAAqB,eAAgB,SAAQ,KAAK;IAIhD,YAAY,QAAqB,EAAE,MAAc,EAAE,GAAW,EAAE,GAAY;QAC1E,KAAK,CAAC,GAAG,IAAI,2BAA2B,GAAG,YAAY,MAAM,EAAE,CAAC,CAAA;QAChE,IAAI,CAAC,UAAU,GAAG,IAAA,oBAAU,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;QACnD,IAAI,CAAC,aAAa,GAAG,IAAA,qBAAW,EAAC,IAAA,qBAAW,EAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF;AATD,kCASC"}
|
||||
+5
-5
@@ -1,12 +1,12 @@
|
||||
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 = {
|
||||
[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;
|
||||
|
||||
+13
-11
@@ -4,7 +4,6 @@ exports.getSchemaRefs = exports.resolveUrl = exports.normalizeId = exports._getF
|
||||
const util_1 = require("./util");
|
||||
const equal = require("fast-deep-equal");
|
||||
const traverse = require("json-schema-traverse");
|
||||
const URI = require("uri-js");
|
||||
// TODO refactor to use keyword definitions
|
||||
const SIMPLE_INLINED = new Set([
|
||||
"type",
|
||||
@@ -69,15 +68,16 @@ function countKeys(schema) {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
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] + "#";
|
||||
}
|
||||
exports._getFullPath = _getFullPath;
|
||||
const TRAILING_SLASH_HASH = /#\/?$/;
|
||||
@@ -85,19 +85,19 @@ function normalizeId(id) {
|
||||
return id ? id.replace(TRAILING_SLASH_HASH, "") : "";
|
||||
}
|
||||
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);
|
||||
}
|
||||
exports.resolveUrl = resolveUrl;
|
||||
const ANCHOR = /^[a-z_][-a-z0-9._]*$/i;
|
||||
function getSchemaRefs(schema, baseId) {
|
||||
if (typeof schema == "boolean")
|
||||
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 = {};
|
||||
const schemaRefs = new Set();
|
||||
traverse(schema, { allKeys: true }, (sch, jsonPtr, _, parentJsonPtr) => {
|
||||
@@ -111,7 +111,9 @@ function getSchemaRefs(schema, baseId) {
|
||||
addAnchor.call(this, sch.$dynamicAnchor);
|
||||
baseIds[jsonPtr] = baseId;
|
||||
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))
|
||||
throw ambiguos(ref);
|
||||
schemaRefs.add(ref);
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../lib/compile/resolve.ts"],"names":[],"mappings":";;;AAEA,iCAA+B;AAC/B,yCAAwC;AACxC,iDAAgD;AAChD,8BAA6B;AAK7B,2CAA2C;AAC3C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,MAAM;IACN,QAAQ;IACR,SAAS;IACT,WAAW;IACX,WAAW;IACX,eAAe;IACf,eAAe;IACf,UAAU;IACV,UAAU;IACV,SAAS;IACT,SAAS;IACT,aAAa;IACb,YAAY;IACZ,UAAU;IACV,MAAM;IACN,OAAO;CACR,CAAC,CAAA;AAEF,SAAgB,SAAS,CAAC,MAAiB,EAAE,QAA0B,IAAI;IACzE,IAAI,OAAO,MAAM,IAAI,SAAS;QAAE,OAAO,IAAI,CAAA;IAC3C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,KAAK,CAAA;AACnC,CAAC;AALD,8BAKC;AAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,MAAM;IACN,eAAe;IACf,kBAAkB;IAClB,aA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ChC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,SAAS,CAAA;IAEhB,SAAS,gBAAgB,CAAC,IAAe,EAAE,IAA2B,EAAE,GAAW;QACjF,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;YAAE,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAA;IACnE,CAAC;IAED,SAAS,QAAQ,CAAC,GAAW;QAC3B,OAAO,IAAI,KAAK,CAAC,cAAc,GAAG,oCAAoC,CAAC,CAAA;IACzE,CAAC;AACH,CAAC;AAxDD,sCAwDC"}
|
||||
+1
-1
@@ -142,7 +142,7 @@ function checkNoDefault(it) {
|
||||
function updateContext(it) {
|
||||
const schId = it.schema[it.opts.schemaId];
|
||||
if (schId)
|
||||
it.baseId = (0, resolve_1.resolveUrl)(it.baseId, schId);
|
||||
it.baseId = (0, resolve_1.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
||||
}
|
||||
function checkAsyncSchema(it) {
|
||||
if (it.schema.$async && !it.schemaEnv.$async)
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+3
-2
@@ -10,7 +10,7 @@ export { JSONType } from "./compile/rules";
|
||||
export { JSONSchemaType } from "./types/json-schema";
|
||||
export { JTDSchemaType, SomeJTDSchemaType, JTDDataType } from "./types/jtd-schema";
|
||||
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";
|
||||
import type { JTDSchemaType, SomeJTDSchemaType, JTDDataType } from "./types/jtd-schema";
|
||||
import ValidationError from "./runtime/validation_error";
|
||||
@@ -68,6 +68,7 @@ export interface CurrentOptions {
|
||||
int32range?: boolean;
|
||||
messages?: boolean;
|
||||
code?: CodeOptions;
|
||||
uriResolver?: UriResolver;
|
||||
}
|
||||
export interface CodeOptions {
|
||||
es5?: boolean;
|
||||
@@ -92,7 +93,7 @@ interface DeprecatedOptions {
|
||||
unicode?: boolean;
|
||||
}
|
||||
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]>;
|
||||
} & {
|
||||
code: InstanceCodeOptions;
|
||||
};
|
||||
|
||||
+20
-17
@@ -19,6 +19,7 @@ const resolve_1 = require("./compile/resolve");
|
||||
const dataType_1 = require("./compile/validate/dataType");
|
||||
const util_1 = require("./compile/util");
|
||||
const $dataRefSchema = require("./refs/data.json");
|
||||
const uri_1 = require("./runtime/uri");
|
||||
const defaultRegExp = (str, flags) => new RegExp(str, flags);
|
||||
defaultRegExp.code = "new RegExp";
|
||||
const META_IGNORE_OPTIONS = ["removeAdditional", "useDefaults", "coerceTypes"];
|
||||
@@ -62,29 +63,31 @@ const deprecatedOptions = {
|
||||
const MAX_EXPRESSION = 200;
|
||||
// eslint-disable-next-line complexity
|
||||
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;
|
||||
const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize;
|
||||
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0;
|
||||
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,
|
||||
};
|
||||
}
|
||||
class Ajv {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+6
@@ -0,0 +1,6 @@
|
||||
import * as uri from "uri-js";
|
||||
declare type URI = typeof uri & {
|
||||
code: string;
|
||||
};
|
||||
declare const _default: URI;
|
||||
export default _default;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const uri = require("uri-js");
|
||||
uri.code = 'require("ajv/dist/runtime/uri").default';
|
||||
exports.default = uri;
|
||||
//# sourceMappingURL=uri.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../../lib/runtime/uri.ts"],"names":[],"mappings":";;AAAA,8BAA6B;AAG3B,GAAW,CAAC,IAAI,GAAG,yCAAyC,CAAA;AAE9D,kBAAe,GAAU,CAAA"}
|
||||
+6
@@ -1,3 +1,4 @@
|
||||
import * as URI from "uri-js";
|
||||
import type { CodeGen, Code, Name, ScopeValueSets, ValueScopeName } from "../compile/codegen";
|
||||
import type { SchemaEnv, SchemaCxt, SchemaObjCxt } from "../compile";
|
||||
import type { JSONType } from "../compile/rules";
|
||||
@@ -174,4 +175,9 @@ export interface RegExpEngine {
|
||||
export interface RegExpLike {
|
||||
test: (s: string) => boolean;
|
||||
}
|
||||
export interface UriResolver {
|
||||
parse(uri: string): URI.URIComponents;
|
||||
resolve(base: string, path: string): string;
|
||||
serialize(component: URI.URIComponents): string;
|
||||
}
|
||||
export {};
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ const def = {
|
||||
return callRootRef();
|
||||
const schOrEnv = compile_1.resolveRef.call(self, root, baseId, $ref);
|
||||
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)
|
||||
return callValidate(schOrEnv);
|
||||
return inlineRefSchema(schOrEnv);
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+3
-2
@@ -27,8 +27,9 @@ const def = {
|
||||
function validateJtdRef() {
|
||||
var _a;
|
||||
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)
|
||||
callValidate(refSchema);
|
||||
else
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../lib/vocabularies/jtd/ref.ts"],"names":[],"mappings":";;;AAEA,2CAAsD;AACtD,mDAA4D;AAC5D,uDAAqD;AACrD,+CAAmC;AACnC,qCAAgD;AAChD,yCAAwC;AAExC,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,QAAQ;IACpB,IAAI,CAAC,GAAe;QAClB,IAAA,wBAAa,EAAC,GAAG,CAAC,CAAA;QAClB,MAAM,EAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,EAAC,GAAG,GAAG,CAAA;QACtD,MAAM,EACJ,SAAS,EAAE,EAAC,IAAI,EAAC,GAClB,GAAG,EAAE,CAAA;QACN,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,IAAI,YAAY,CAAC,QAAQ,EAAE;YACzB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,IAAA,WAAC,EAAA,GAAG,IAAI,WAAW,CAAC,CAAA;YACnC,GAAG,CAAC,EAAE,CAAC,IAAA,aAAG,EAAC,KAAK,CAAC,EAAE,cAAc,CAAC,CAAA;SACnC;aAAM;YACL,GAAG,CAAC,GAAG,CAAC,K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C,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YAChC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAA,WAAC,EAAA,GAAG,SAAS,QAAQ,eAAC,CAAC,MAAM,EAAE,CAAC,CAAA;QACpD,CAAC;QAED,SAAS,eAAe,CAAC,MAAuB;YAC9C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAC5B,QAAQ,EACR,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAA,mBAAS,EAAC,MAAM,CAAC,EAAC,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,MAAM,EAAC,CACtF,CAAA;YACD,GAAG,CAAC,SAAS,CACX;gBACE,MAAM;gBACN,SAAS,EAAE,EAAE;gBACb,UAAU,EAAE,aAAG;gBACf,YAAY,EAAE,OAAO;gBACrB,aAAa,EAAE,gBAAgB,GAAG,EAAE;aACrC,EACD,KAAK,CACN,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAED,SAAgB,MAAM,CAAC,MAAuB;IAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACxB,IAAI,GAAoB,CAAA;QACxB,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,IAAI,CAAA;KAC1F;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAND,wBAMC;AAED,kBAAe,GAAG,CAAA"}
|
||||
+8
-8
@@ -112,7 +112,7 @@ export function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv {
|
||||
// TODO refactor - remove compilations
|
||||
const _sch = getCompilingSchema.call(this, sch)
|
||||
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
|
||||
const {ownProperties} = this.opts
|
||||
const gen = new CodeGen(this.scope, {es5, lines, ownProperties})
|
||||
@@ -208,7 +208,7 @@ export function resolveRef(
|
||||
baseId: string,
|
||||
ref: string
|
||||
): AnySchema | SchemaEnv | undefined {
|
||||
ref = resolveUrl(baseId, ref)
|
||||
ref = resolveUrl(this.opts.uriResolver, baseId, ref)
|
||||
const schOrFunc = root.refs[ref]
|
||||
if (schOrFunc) return schOrFunc
|
||||
|
||||
@@ -257,9 +257,9 @@ export function resolveSchema(
|
||||
root: SchemaEnv, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
|
||||
ref: string // reference to resolve
|
||||
): 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
|
||||
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
|
||||
return getJsonPointer.call(this, p, root)
|
||||
@@ -279,7 +279,7 @@ export function resolveSchema(
|
||||
const {schema} = schOrRef
|
||||
const {schemaId} = this.opts
|
||||
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})
|
||||
}
|
||||
return getJsonPointer.call(this, p, schOrRef)
|
||||
@@ -307,12 +307,12 @@ function getJsonPointer(
|
||||
// TODO PREVENT_SCOPE_CHANGE could be defined in keyword def?
|
||||
const schId = typeof schema === "object" && schema[this.opts.schemaId]
|
||||
if (!PREVENT_SCOPE_CHANGE.has(part) && schId) {
|
||||
baseId = resolveUrl(baseId, schId)
|
||||
baseId = resolveUrl(this.opts.uriResolver, baseId, schId)
|
||||
}
|
||||
}
|
||||
let env: SchemaEnv | undefined
|
||||
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)
|
||||
}
|
||||
// even though resolution failed we need to return SchemaEnv to throw exception
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ function parseRef(cxt: ParseCxt): void {
|
||||
const {gen, self, definitions, schema, schemaEnv} = cxt
|
||||
const {ref} = schema
|
||||
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})
|
||||
const {root} = schemaEnv
|
||||
const sch = compileParser.call(self, new SchemaEnv({schema: refSchema, root}), definitions)
|
||||
|
||||
+1
-1
@@ -234,7 +234,7 @@ function serializeRef(cxt: SerializeCxt): void {
|
||||
const {gen, self, data, definitions, schema, schemaEnv} = cxt
|
||||
const {ref} = schema
|
||||
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})
|
||||
const {root} = schemaEnv
|
||||
const sch = compileSerializer.call(self, new SchemaEnv({schema: refSchema, root}), definitions)
|
||||
|
||||
+4
-3
@@ -1,12 +1,13 @@
|
||||
import {resolveUrl, normalizeId, getFullPath} from "./resolve"
|
||||
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) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
+15
-12
@@ -1,9 +1,9 @@
|
||||
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"
|
||||
|
||||
// the hash of local references inside the schema (created by getSchemaRefs), used for inline resolution
|
||||
export type LocalRefs = {[Ref in string]?: AnySchemaObject}
|
||||
@@ -67,14 +67,15 @@ function countKeys(schema: AnySchemaObject): number {
|
||||
return count
|
||||
}
|
||||
|
||||
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] + "#"
|
||||
}
|
||||
|
||||
const TRAILING_SLASH_HASH = /#\/?$/
|
||||
@@ -82,19 +83,19 @@ export function normalizeId(id: string | undefined): string {
|
||||
return id ? id.replace(TRAILING_SLASH_HASH, "") : ""
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
const ANCHOR = /^[a-z_][-a-z0-9._]*$/i
|
||||
|
||||
export function getSchemaRefs(this: Ajv, schema: AnySchema, baseId: string): LocalRefs {
|
||||
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 = {}
|
||||
const schemaRefs: Set<string> = new Set()
|
||||
|
||||
@@ -108,7 +109,9 @@ export function getSchemaRefs(this: Ajv, schema: AnySchema, baseId: string): Loc
|
||||
baseIds[jsonPtr] = baseId
|
||||
|
||||
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)
|
||||
schemaRefs.add(ref)
|
||||
let schOrRef = this.refs[ref]
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ function checkNoDefault(it: SchemaObjCxt): void {
|
||||
|
||||
function updateContext(it: SchemaObjCxt): void {
|
||||
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)
|
||||
}
|
||||
|
||||
function checkAsyncSchema(it: SchemaObjCxt): void {
|
||||
|
||||
+8
-2
@@ -49,6 +49,7 @@ import type {
|
||||
Format,
|
||||
AddedFormat,
|
||||
RegExpEngine,
|
||||
UriResolver,
|
||||
} from "./types"
|
||||
import type {JSONSchemaType} from "./types/json-schema"
|
||||
import type {JTDSchemaType, SomeJTDSchemaType, JTDDataType} from "./types/jtd-schema"
|
||||
@@ -60,9 +61,10 @@ import {Code, ValueScope} from "./compile/codegen"
|
||||
import {normalizeId, getSchemaRefs} from "./compile/resolve"
|
||||
import {getJSONTypes} from "./compile/validate/dataType"
|
||||
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)
|
||||
defaultRegExp.code = "new RegExp"
|
||||
|
||||
@@ -136,6 +138,7 @@ export interface CurrentOptions {
|
||||
int32range?: boolean // JTD only
|
||||
messages?: boolean
|
||||
code?: CodeOptions // NEW
|
||||
uriResolver?: UriResolver
|
||||
}
|
||||
|
||||
export interface CodeOptions {
|
||||
@@ -226,7 +229,8 @@ type RequiredInstanceOptions = {
|
||||
| "validateSchema"
|
||||
| "validateFormats"
|
||||
| "int32range"
|
||||
| "unicodeRegExp"]: NonNullable<Options[K]>
|
||||
| "unicodeRegExp"
|
||||
| "uriResolver"]: NonNullable<Options[K]>
|
||||
} & {code: InstanceCodeOptions}
|
||||
|
||||
export type InstanceOptions = Options & RequiredInstanceOptions
|
||||
@@ -239,6 +243,7 @@ function requiredOptions(o: Options): RequiredInstanceOptions {
|
||||
const _optz = o.code?.optimize
|
||||
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0
|
||||
const regExp = o.code?.regExp ?? defaultRegExp
|
||||
const uriResolver = o.uriResolver ?? DefaultUriResolver
|
||||
return {
|
||||
strictSchema: o.strictSchema ?? s ?? true,
|
||||
strictNumbers: o.strictNumbers ?? s ?? true,
|
||||
@@ -257,6 +262,7 @@ function requiredOptions(o: Options): RequiredInstanceOptions {
|
||||
validateFormats: o.validateFormats ?? true,
|
||||
unicodeRegExp: o.unicodeRegExp ?? true,
|
||||
int32range: o.int32range ?? true,
|
||||
uriResolver: uriResolver,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import * as uri from "uri-js"
|
||||
|
||||
type URI = typeof uri & {code: string}
|
||||
;(uri as URI).code = 'require("ajv/dist/runtime/uri").default'
|
||||
|
||||
export default uri as URI
|
||||
+7
@@ -1,3 +1,4 @@
|
||||
import * as URI from "uri-js"
|
||||
import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen"
|
||||
import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile"
|
||||
import type {JSONType} from "../compile/rules"
|
||||
@@ -231,3 +232,9 @@ export interface RegExpEngine {
|
||||
export interface RegExpLike {
|
||||
test: (s: string) => boolean
|
||||
}
|
||||
|
||||
export interface UriResolver {
|
||||
parse(uri: string): URI.URIComponents
|
||||
resolve(base: string, path: string): string
|
||||
serialize(component: URI.URIComponents): string
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ const def: CodeKeywordDefinition = {
|
||||
const {root} = env
|
||||
if (($ref === "#" || $ref === "#/") && baseId === root.baseId) return callRootRef()
|
||||
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)
|
||||
return inlineRefSchema(schOrEnv)
|
||||
|
||||
|
||||
+3
-1
@@ -28,7 +28,9 @@ const def: CodeKeywordDefinition = {
|
||||
|
||||
function validateJtdRef(): void {
|
||||
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)
|
||||
else inlineRefSchema(refSchema)
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ajv",
|
||||
"version": "8.9.0",
|
||||
"version": "8.10.0",
|
||||
"description": "Another JSON Schema Validator",
|
||||
"main": "dist/ajv.js",
|
||||
"types": "dist/ajv.d.ts",
|
||||
@@ -83,6 +83,7 @@
|
||||
"dayjs-plugin-utc": "^0.1.2",
|
||||
"eslint": "^7.8.1",
|
||||
"eslint-config-prettier": "^7.0.0",
|
||||
"fast-uri": "^1.0.0",
|
||||
"glob": "^7.0.0",
|
||||
"husky": "^7.0.1",
|
||||
"if-node-version": "^1.0.0",
|
||||
|
||||
Reference in New Issue
Block a user