@hyperjump/json-schema
Advanced tools
Comparing version 1.6.6 to 1.6.7
@@ -226,4 +226,4 @@ import { v4 as uuid } from "uuid"; | ||
if (dependencies) { | ||
dependencies.collectExternalIds = (dependentSchemas, externalIds, ast, dynamicAnchors) => { | ||
Object.values(dependentSchemas).forEach(([, dependency]) => { | ||
dependencies.collectExternalIds = (dependencies, externalIds, ast, dynamicAnchors) => { | ||
Object.values(dependencies).forEach(([, dependency]) => { | ||
if (typeof dependency === "string") { | ||
@@ -269,2 +269,50 @@ Validation.collectExternalIds(dependency, externalIds, ast, dynamicAnchors); | ||
} | ||
// Experimental | ||
const propertyDependencies = getKeyword("https://json-schema.org/keyword/propertyDependencies"); | ||
if (propertyDependencies) { | ||
propertyDependencies.collectExternalIds = (propertyDependencies, externalIds, ast, dynamicAnchors) => { | ||
for (const key in propertyDependencies) { | ||
for (const value in propertyDependencies[key]) { | ||
Validation.collectExternalIds(propertyDependencies[key][value], externalIds, ast, dynamicAnchors); | ||
} | ||
} | ||
}; | ||
} | ||
const conditional = getKeyword("https://json-schema.org/keyword/conditional"); | ||
if (conditional) { | ||
conditional.collectExternalIds = (conditional, externalIds, ast, dynamicAnchors) => { | ||
for (const schema of conditional) { | ||
Validation.collectExternalIds(schema, externalIds, ast, dynamicAnchors); | ||
} | ||
}; | ||
} | ||
const itemPattern = getKeyword("https://json-schema.org/keyword/itemPattern"); | ||
if (itemPattern) { | ||
itemPattern.collectExternalIds = (nfa, externalIds, ast, dynamicAnchors) => { | ||
for (const itemSchema of collectNfaSchemas(nfa.start)) { | ||
Validation.collectExternalIds(itemSchema, externalIds, ast, dynamicAnchors); | ||
} | ||
}; | ||
} | ||
const collectNfaSchemas = function* (node, visited = new Set()) { | ||
if (visited.has(node)) { | ||
return; | ||
} | ||
visited.add(node); | ||
for (const schema in node.transition) { | ||
yield schema; | ||
yield* collectNfaSchemas(node.transition[schema], visited); | ||
} | ||
for (const epsilon of node.epsilonTransitions) { | ||
yield* collectNfaSchemas(epsilon, visited); | ||
} | ||
}; | ||
}; |
@@ -18,5 +18,18 @@ import { toAbsoluteUri } from "./common.js"; | ||
const _allowUnknownKeywords = {}; | ||
export const getKeywordId = (dialectId, keyword) => _dialects[dialectId]?.[keyword] | ||
|| (_allowUnknownKeywords[dialectId] || keyword[0] === "@") && `https://json-schema.org/keyword/unknown#${keyword}`; | ||
export const getKeywordId = (dialectId, keyword) => { | ||
if (!hasDialect(dialectId)) { | ||
throw Error(`Encountered unknown dialect '${dialectId}'`); | ||
} | ||
return _dialects[dialectId]?.[keyword] | ||
|| (_allowUnknownKeywords[dialectId] || keyword.startsWith("x-")) | ||
&& `https://json-schema.org/keyword/unknown#${keyword}`; | ||
}; | ||
export const getKeywordName = (dialectId, keywordId) => { | ||
if (!hasDialect(dialectId)) { | ||
throw Error(`Encountered unknown dialect '${dialectId}'`); | ||
} | ||
for (const keyword in _dialects[dialectId]) { | ||
@@ -23,0 +36,0 @@ if (_dialects[dialectId][keyword] === keywordId) { |
@@ -25,10 +25,6 @@ import { nil as nilPointer, append as pointerAppend, get as pointerGet } from "@hyperjump/json-pointer"; | ||
if (!hasDialect(dialectId)) { | ||
throw Error(`Encountered unknown dialect '${dialectId}'`); | ||
} | ||
// Identifiers | ||
const idToken = getKeywordName(dialectId, "https://json-schema.org/keyword/id") | ||
|| getKeywordName(dialectId, "https://json-schema.org/keyword/draft-04/id"); | ||
if (retrievalUri === undefined && !(idToken in schema)) { | ||
if (!retrievalUri && typeof schema?.[idToken] !== "string") { | ||
throw Error(`Unable to determine an identifier for the schema. Use the '${idToken}' keyword or pass a retrievalUri when loading the schema.`); | ||
@@ -81,5 +77,2 @@ } | ||
const embeddedDialectId = typeof subject.$schema === "string" ? toAbsoluteIri(subject.$schema) : dialectId; | ||
if (!hasDialect(embeddedDialectId)) { | ||
throw Error(`Encountered unknown dialect '${embeddedDialectId}'`); | ||
} | ||
@@ -86,0 +79,0 @@ const idToken = getKeywordName(embeddedDialectId, "https://json-schema.org/keyword/id"); |
import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js"; | ||
import { addSchema } from "../lib/core.js"; | ||
import { addSchema } from "../lib/index.js"; | ||
import "../lib/openapi.js"; | ||
@@ -4,0 +4,0 @@ |
@@ -247,3 +247,3 @@ import type { Json } from "@hyperjump/json-pointer"; | ||
deprecated?: boolean; | ||
schema?: OpenApi31; | ||
schema?: OasSchema31; | ||
style?: "simple"; | ||
@@ -250,0 +250,0 @@ explode?: boolean; |
{ | ||
"name": "@hyperjump/json-schema", | ||
"version": "1.6.6", | ||
"version": "1.6.7", | ||
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects", | ||
@@ -30,3 +30,3 @@ "type": "module", | ||
"lint": "eslint lib stable draft-* openapi-* bundle annotations", | ||
"test": "mocha 'lib/**/*.spec.ts' 'stable/**/*.spec.ts' 'draft-*/**/*.spec.ts' 'openapi-*/**/*.spec.ts' 'bundle/**/*.spec.ts' 'annotations/**/*.spec.ts'" | ||
"test": "vitest --watch=false" | ||
}, | ||
@@ -55,9 +55,8 @@ "repository": "github:hyperjump-io/json-schema", | ||
"devDependencies": { | ||
"@types/chai": "*", | ||
"@types/mocha": "*", | ||
"@types/node": "*", | ||
"@typescript-eslint/eslint-plugin": "*", | ||
"@typescript-eslint/parser": "*", | ||
"chai": "*", | ||
"@vitest/coverage-v8": "^1.0.4", | ||
"eslint": "*", | ||
"eslint-import-resolver-exports": "*", | ||
"eslint-import-resolver-node": "*", | ||
@@ -67,5 +66,4 @@ "eslint-import-resolver-typescript": "*", | ||
"json-schema-test-suite": "github:json-schema-org/JSON-Schema-Test-Suite", | ||
"mocha": "*", | ||
"ts-node": "*", | ||
"typescript": "*", | ||
"vitest": "*", | ||
"yaml": "*" | ||
@@ -72,0 +70,0 @@ }, |
13
332439
174
8877