@apidevtools/json-schema-ref-parser
Advanced tools
Comparing version
import type { ParserOptions } from "./options.js"; | ||
import $Ref from "./ref.js"; | ||
import type { JSONSchema } from "./types"; | ||
export declare const nullSymbol: unique symbol; | ||
/** | ||
@@ -5,0 +6,0 @@ * This class represents a single JSON pointer and its resolved value. |
@@ -39,5 +39,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nullSymbol = void 0; | ||
const ref_js_1 = __importDefault(require("./ref.js")); | ||
const url = __importStar(require("./util/url.js")); | ||
const errors_js_1 = require("./util/errors.js"); | ||
exports.nullSymbol = Symbol('null'); | ||
const slashes = /\//g; | ||
@@ -114,2 +116,11 @@ const tildes = /~/g; | ||
} | ||
// If the token we're looking for ended up not containing any slashes but is | ||
// actually instead pointing to an existing `null` value then we should use that | ||
// `null` value. | ||
if (token in this.value && this.value[token] === null) { | ||
// We use a `null` symbol for internal tracking to differntiate between a general `null` | ||
// value and our expected `null` value. | ||
this.value = exports.nullSymbol; | ||
continue; | ||
} | ||
this.value = null; | ||
@@ -116,0 +127,0 @@ const path = this.$ref.path || ""; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const pointer_js_1 = __importDefault(require("./pointer.js")); | ||
const pointer_js_1 = __importStar(require("./pointer.js")); | ||
const errors_js_1 = require("./util/errors.js"); | ||
@@ -81,3 +111,7 @@ const url_js_1 = require("./util/url.js"); | ||
try { | ||
return pointer.resolve(this.value, options, pathFromRoot); | ||
const resolved = pointer.resolve(this.value, options, pathFromRoot); | ||
if (resolved.value === pointer_js_1.nullSymbol) { | ||
resolved.value = null; | ||
} | ||
return resolved; | ||
} | ||
@@ -108,2 +142,5 @@ catch (err) { | ||
this.value = pointer.set(this.value, value); | ||
if (this.value === pointer_js_1.nullSymbol) { | ||
this.value = null; | ||
} | ||
} | ||
@@ -110,0 +147,0 @@ /** |
@@ -8,2 +8,4 @@ import type { ParserOptions } from "./options.js"; | ||
export const nullSymbol = Symbol('null'); | ||
const slashes = /\//g; | ||
@@ -125,2 +127,12 @@ const tildes = /~/g; | ||
// If the token we're looking for ended up not containing any slashes but is | ||
// actually instead pointing to an existing `null` value then we should use that | ||
// `null` value. | ||
if (token in this.value && this.value[token] === null) { | ||
// We use a `null` symbol for internal tracking to differntiate between a general `null` | ||
// value and our expected `null` value. | ||
this.value = nullSymbol; | ||
continue; | ||
} | ||
this.value = null; | ||
@@ -127,0 +139,0 @@ |
@@ -1,2 +0,2 @@ | ||
import Pointer from "./pointer.js"; | ||
import Pointer, { nullSymbol } from "./pointer.js"; | ||
import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js"; | ||
@@ -122,3 +122,8 @@ import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js"; | ||
try { | ||
return pointer.resolve(this.value, options, pathFromRoot); | ||
const resolved = pointer.resolve(this.value, options, pathFromRoot); | ||
if (resolved.value === nullSymbol) { | ||
resolved.value = null; | ||
} | ||
return resolved; | ||
} catch (err: any) { | ||
@@ -152,2 +157,5 @@ if (!options || !options.continueOnError || !isHandledError(err)) { | ||
this.value = pointer.set(this.value, value); | ||
if (this.value === nullSymbol) { | ||
this.value = null; | ||
} | ||
} | ||
@@ -154,0 +162,0 @@ |
{ | ||
"name": "@apidevtools/json-schema-ref-parser", | ||
"version": "11.9.2", | ||
"version": "11.9.3", | ||
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", | ||
@@ -5,0 +5,0 @@ "scripts": { |
335398
0.86%7957
0.84%