@hyperjump/json-schema
Advanced tools
Comparing version 1.4.4 to 1.4.5
@@ -95,3 +95,3 @@ import { v4 as uuid } from "uuid"; | ||
if (additionalProperties) { | ||
additionalProperties.collectExternalIds = ([, , additionalProperties], externalIds, ast, dynamicAnchors) => { | ||
additionalProperties.collectExternalIds = ([, additionalProperties], externalIds, ast, dynamicAnchors) => { | ||
if (typeof additionalProperties === "string") { | ||
@@ -98,0 +98,0 @@ Validation.collectExternalIds(additionalProperties, externalIds, ast, dynamicAnchors); |
@@ -1,2 +0,2 @@ | ||
import { resolveIri, toAbsoluteIri, parseIriReference } from "@hyperjump/uri"; | ||
import { resolveIri, parseIriReference } from "@hyperjump/uri"; | ||
import * as JsonPointer from "@hyperjump/json-pointer"; | ||
@@ -3,0 +3,0 @@ |
@@ -10,14 +10,29 @@ import * as Schema from "../schema.js"; | ||
const compile = async (schema, ast, parentSchema) => { | ||
const patterns = []; | ||
const propertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/properties"); | ||
const propertiesSchema = await Schema.step(propertiesKeyword, parentSchema); | ||
const propertyNames = Schema.typeOf(propertiesSchema, "object") ? Schema.keys(propertiesSchema) : []; | ||
if (Schema.typeOf(propertiesSchema, "object")) { | ||
for (const name of Schema.keys(propertiesSchema)) { | ||
patterns.push(regexEscape(name)); | ||
} | ||
} | ||
const patternPropertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/patternProperties"); | ||
const patternProperties = await Schema.step(patternPropertiesKeyword, parentSchema); | ||
const propertyNamePatterns = Schema.typeOf(patternProperties, "object") ? Schema.keys(patternProperties).map((pattern) => new RegExp(pattern)) : []; | ||
if (Schema.typeOf(patternProperties, "object")) { | ||
patterns.push(...Schema.keys(patternProperties)); | ||
} | ||
return [propertyNames, propertyNamePatterns, await Validation.compile(schema, ast)]; | ||
return [ | ||
new RegExp(patterns.length > 0 ? patterns.join("|") : "(?!)", "u"), | ||
await Validation.compile(schema, ast) | ||
]; | ||
}; | ||
const interpret = ([propertyNames, propertyNamePatterns, additionalProperties], instance, ast, dynamicAnchors, quiet) => { | ||
const regexEscape = (string) => string | ||
.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&") | ||
.replace(/-/g, "\\x2d"); | ||
const interpret = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors, quiet) => { | ||
if (!Instance.typeOf(instance, "object")) { | ||
@@ -28,7 +43,7 @@ return true; | ||
return Instance.entries(instance) | ||
.filter(([propertyName]) => !propertyNames.includes(propertyName) && !propertyNamePatterns.some((pattern) => pattern.test(propertyName))) | ||
.filter(([propertyName]) => !isDefinedProperty.test(propertyName)) | ||
.every(([, property]) => Validation.interpret(additionalProperties, property, ast, dynamicAnchors, quiet)); | ||
}; | ||
const collectEvaluatedProperties = ([propertyNames, propertyNamePatterns, additionalProperties], instance, ast, dynamicAnchors) => { | ||
const collectEvaluatedProperties = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors) => { | ||
if (!Instance.typeOf(instance, "object")) { | ||
@@ -40,3 +55,3 @@ return true; | ||
for (const [propertyName, property] of Instance.entries(instance)) { | ||
if (!propertyNames.includes(propertyName) && !propertyNamePatterns.some((pattern) => pattern.test(propertyName))) { | ||
if (!isDefinedProperty.test(propertyName)) { | ||
if (!Validation.interpret(additionalProperties, property, ast, dynamicAnchors, true)) { | ||
@@ -43,0 +58,0 @@ return false; |
{ | ||
"name": "@hyperjump/json-schema", | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10140
347235