Skip to content

Commit

Permalink
Remove "experimental" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Jan 2, 2024
1 parent 2a0ef5b commit 224e411
Show file tree
Hide file tree
Showing 18 changed files with 11 additions and 81 deletions.
8 changes: 1 addition & 7 deletions bundle/generate-snapshots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFile, mkdir, rm } from "node:fs/promises";
import { isCompatible, md5, loadSchemas, testSuite, unloadSchemas } from "./test-utils.js";
import { validate } from "../lib/index.js";
import { VERBOSE, setExperimentalKeywordEnabled } from "../lib/experimental.js";
import { VERBOSE } from "../lib/experimental.js";
import "../stable/index.js";
import "../draft-2020-12/index.js";
import "../draft-2019-09/index.js";
Expand All @@ -10,12 +10,6 @@ import "../draft-06/index.js";
import "../draft-04/index.js";


setExperimentalKeywordEnabled("https://json-schema.org/keyword/dynamicRef", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/propertyDependencies", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/requireAllExcept", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/itemPattern", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/conditional", true);

const suite = testSuite("./bundle/tests");

const snapshotGenerator = async (version, dialect) => {
Expand Down
2 changes: 1 addition & 1 deletion bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const loadKeywordSupport = () => {
contains19.collectExternalIds = Validation.collectExternalIds;
}

// Experimental
// Extensions

const propertyDependencies = getKeyword("https://json-schema.org/keyword/propertyDependencies");
if (propertyDependencies) {
Expand Down
8 changes: 1 addition & 7 deletions bundle/test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { isCompatible, md5, loadSchemas, unloadSchemas, testSuite } from "./test-utils.js";
import { registerSchema, unregisterSchema, validate } from "../lib/index.js";
import { VERBOSE, getKeywordName, setExperimentalKeywordEnabled } from "../lib/experimental.js";
import { VERBOSE, getKeywordName } from "../lib/experimental.js";
import "../stable/index.js";
import "../draft-2020-12/index.js";
import "../draft-2019-09/index.js";
Expand All @@ -15,12 +15,6 @@ import type { BundleOptions } from "./index.js";
import type { OutputUnit } from "../lib/index.js";


setExperimentalKeywordEnabled("https://json-schema.org/keyword/dynamicRef", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/propertyDependencies", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/requireAllExcept", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/itemPattern", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/conditional", true);

const suite = testSuite("./bundle/tests");

const config: BundleOptions[] = [
Expand Down
6 changes: 0 additions & 6 deletions lib/configuration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let metaSchemaOutputFormat;
let shouldValidateSchema = true;
const enabledExperimentalKeywords = {};

export const getMetaSchemaOutputFormat = () => metaSchemaOutputFormat;
export const setMetaSchemaOutputFormat = (format) => {
Expand All @@ -11,8 +10,3 @@ export const getShouldValidateSchema = () => shouldValidateSchema;
export const setShouldValidateSchema = (isEnabled) => {
shouldValidateSchema = isEnabled;
};

export const isExperimentalKeywordEnabled = (keywordId) => enabledExperimentalKeywords[keywordId];
export const setExperimentalKeywordEnabled = (keywordId, isEnabled) => {
enabledExperimentalKeywords[keywordId] = isEnabled;
};
15 changes: 0 additions & 15 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { subscribe, unsubscribe } from "./pubsub.js";
import {
setMetaSchemaOutputFormat,
getShouldValidateSchema,
isExperimentalKeywordEnabled,
setExperimentalKeywordEnabled,
getMetaSchemaOutputFormat
} from "./configuration.js";
import * as Instance from "./instance.js";
Expand Down Expand Up @@ -87,22 +85,9 @@ subscribe("validate.metaValidate", async (_message, schema) => {

// Compile
if (!(schema.document.dialectId in metaValidators)) {
// Dynamic references are experimental, but are necessary for meta-validation
const dyanmicRefKeywordId = "https://json-schema.org/keyword/dynamicRef";
const isDynamicRefEnabled = isExperimentalKeywordEnabled(dyanmicRefKeywordId);
setExperimentalKeywordEnabled(dyanmicRefKeywordId, true);

// itemPattern is experimental, but is necessary for meta-validation
const itemPatternKeywordId = "https://json-schema.org/keyword/itemPattern";
const isItemPatternEnabled = isExperimentalKeywordEnabled(itemPatternKeywordId);
setExperimentalKeywordEnabled(itemPatternKeywordId, true);

const metaSchema = await getSchema(schema.document.dialectId);
const compiledSchema = await compile(metaSchema);
metaValidators[schema.document.dialectId] = interpret(compiledSchema);

setExperimentalKeywordEnabled(itemPatternKeywordId, isItemPatternEnabled);
setExperimentalKeywordEnabled(dyanmicRefKeywordId, isDynamicRefEnabled);
}

// Interpret
Expand Down
5 changes: 0 additions & 5 deletions lib/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export const BASIC: "BASIC";
export const DETAILED: "DETAILED";
export const VERBOSE: "VERBOSE";

// Configuration
export const setExperimentalKeywordEnabled: (keywordId: string, isEnabled: boolean) => void;
export const isExperimentalKeywordEnabled: (keywordId: string) => boolean;

// Schema
export const getSchema: (uri: string, browser?: Browser) => Promise<Browser<SchemaDocument>>;
export const buildSchemaDocument: (schema: SchemaObject | boolean, retrievalUri?: string, contextDialectId?: string) => SchemaDocument;
Expand Down Expand Up @@ -71,7 +67,6 @@ export const hasDialect: (dialectId: string) => boolean;

export type Keyword<A> = {
id: string;
experimental?: boolean;
compile: (schema: Browser<SchemaDocument>, ast: AST, parentSchema: Browser<SchemaDocument>) => Promise<A>;
interpret: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors) => boolean;
collectEvaluatedProperties?: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors, isTop?: boolean) => Set<string> | false;
Expand Down
1 change: 0 additions & 1 deletion lib/experimental.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { compile, interpret, BASIC, DETAILED, VERBOSE } from "./core.js";
export { isExperimentalKeywordEnabled, setExperimentalKeywordEnabled } from "./configuration.js";
export { getKeyword, getKeywordByName, addKeyword, defineVocabulary, getKeywordName, getKeywordId, loadDialect, hasDialect } from "./keywords.js";
export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js";
export { default as Validation } from "./keywords/validation.js";
4 changes: 0 additions & 4 deletions lib/keywords.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { toAbsoluteUri } from "./common.js";
import { isExperimentalKeywordEnabled } from "./configuration.js";


const _keywords = {};
Expand All @@ -15,9 +14,6 @@ export const getKeywordByName = (keyword, dialectId) => {
if (!keywordHandler) {
throw Error(`Encountered unsupported keyword ${keyword}. You can provide an implementation for the '${keywordId}' keyword using the 'addKeyword' function.`);
}
if (keywordHandler.experimental && !isExperimentalKeywordEnabled(keywordId)) {
throw Error(`Encountered experimental keyword ${keyword}. You can enable this keyword with: setExperimentalKeywordEnabled('${keywordId}', true)`);
}

return keywordHandler;
};
Expand Down
3 changes: 1 addition & 2 deletions lib/keywords/conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Validation } from "../experimental.js";


const id = "https://json-schema.org/keyword/conditional";
const experimental = true;

const compile = (schema, ast) => pipe(
Browser.iter(schema),
Expand Down Expand Up @@ -62,4 +61,4 @@ const schemaFlatten = async function* (iter, depth = 1) {
}
};

export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
3 changes: 1 addition & 2 deletions lib/keywords/dynamicRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Validation } from "../experimental.js";


const id = "https://json-schema.org/keyword/dynamicRef";
const experimental = true;

const compile = async (schema, ast) => {
const reference = Browser.value(schema);
Expand All @@ -24,4 +23,4 @@ const interpret = evaluate(Validation.interpret);
const collectEvaluatedProperties = evaluate(Validation.collectEvaluatedProperties);
const collectEvaluatedItems = evaluate(Validation.collectEvaluatedItems);

export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
3 changes: 1 addition & 2 deletions lib/keywords/itemPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fromEpsilon, fromSchema, closure, zeroOrOne, oneOrMore, concat, union }


const id = "https://json-schema.org/keyword/itemPattern";
const experimental = true;

const compile = async (schema, ast) => {
const groups = [[]];
Expand Down Expand Up @@ -89,4 +88,4 @@ const interpret = evaluate(Validation.interpret);
const collectEvalatedProperties = evaluate(Validation.collectEvaluatedProperties);
const collectEvalatedItems = evaluate(Validation.collectEvaluatedItems);

export default { id, experimental, compile, interpret, collectEvalatedProperties, collectEvalatedItems };
export default { id, compile, interpret, collectEvalatedProperties, collectEvalatedItems };
3 changes: 1 addition & 2 deletions lib/keywords/propertyDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Validation } from "../experimental.js";


const id = "https://json-schema.org/keyword/propertyDependencies";
const experimental = true;

const compile = (schema, ast) => {
return pipe(
Expand Down Expand Up @@ -44,4 +43,4 @@ const collectEvaluatedProperties = (propertyDependencies, instance, ast, dynamic
}, []);
};

export default { id, experimental, compile, interpret, collectEvaluatedProperties };
export default { id, compile, interpret, collectEvaluatedProperties };
3 changes: 1 addition & 2 deletions lib/keywords/requireAllExcept.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getKeywordName } from "../experimental.js";


const id = "https://json-schema.org/keyword/requireAllExcept";
const experimental = true;

const compile = async (schema, _ast, parentSchema) => {
const requireAllExcept = await Browser.value(schema);
Expand All @@ -21,4 +20,4 @@ const interpret = (required, instance) => {
return Instance.typeOf(instance) !== "object" || required.every((propertyName) => Object.hasOwn(Instance.value(instance), propertyName));
};

export default { id, experimental, compile, interpret };
export default { id, compile, interpret };
3 changes: 1 addition & 2 deletions lib/keywords/unevaluatedProperties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { pipe, filter, every } from "@hyperjump/pact";
import { canonicalUri } from "../schema.js";
import * as Instance from "../instance.js";
import { Validation } from "../experimental.js";
import { Validation, canonicalUri } from "../experimental.js";


const id = "https://json-schema.org/keyword/unevaluatedProperties";
Expand Down
5 changes: 2 additions & 3 deletions lib/keywords/validation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { value, entries } from "@hyperjump/browser";
import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
import { append as pointerAppend } from "@hyperjump/json-pointer";
import { publishAsync, publish } from "../pubsub.js";
import * as Instance from "../instance.js";
import { getKeyword, getKeywordByName } from "../keywords.js";
import { toAbsoluteUri } from "../common.js";
import { canonicalUri } from "../schema.js";
import { value, entries } from "@hyperjump/browser";
import { canonicalUri, getKeyword, getKeywordByName } from "../experimental.js";


const id = "https://json-schema.org/evaluation/validate";
Expand Down
8 changes: 0 additions & 8 deletions stable/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import fs from "node:fs";
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { registerSchema, unregisterSchema, validate } from "./index.js";
import { setExperimentalKeywordEnabled } from "../lib/experimental.js";

import type { JsonSchema, Validator } from "./index.js";


type Suite = {
description: string;
stability?: string;
schema: JsonSchema;
tests: Test[];
};
Expand Down Expand Up @@ -56,12 +54,6 @@ const addRemotes = (filePath = `${testSuitePath}/remotes`, url = "") => {
});
};

setExperimentalKeywordEnabled("https://json-schema.org/keyword/dynamicRef", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/propertyDependencies", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/requireAllExcept", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/itemPattern", true);
setExperimentalKeywordEnabled("https://json-schema.org/keyword/conditional", true);

const runTestSuite = () => {
describe(`JSON Schema Test Suite: ${dialectId}`, () => {
fs.readdirSync(`${testSuitePath}/tests`, { withFileTypes: true })
Expand Down
9 changes: 0 additions & 9 deletions stable/json-schema-test-suite/tests/dynamicRef.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root",
Expand Down Expand Up @@ -29,7 +28,6 @@
},
{
"description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
Expand Down Expand Up @@ -61,7 +59,6 @@
},
{
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root",
Expand Down Expand Up @@ -97,7 +94,6 @@
},
{
"description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root",
Expand Down Expand Up @@ -129,7 +125,6 @@
},
{
"description": "multiple dynamic paths to the $dynamicRef keyword",
"stability": "stage-2",
"schema": {
"$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main",
"propertyDependencies": {
Expand Down Expand Up @@ -206,7 +201,6 @@
},
{
"description": "strict-tree schema, guards against misspelled properties",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "http://localhost:1234/strict-tree.json",
Expand Down Expand Up @@ -238,7 +232,6 @@
},
{
"description": "tests for implementation dynamic anchor and reference link",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "http://localhost:1234/strict-extendible.json",
Expand Down Expand Up @@ -284,7 +277,6 @@
},
{
"description": "$ref and $dynamicAnchor are independent of order - $defs first",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "http://localhost:1234/strict-extendible-allof-defs-first.json",
Expand Down Expand Up @@ -336,7 +328,6 @@
},
{
"description": "$ref and $dynamicAnchor are independent of order - $ref first",
"stability": "stage-2",
"schema": {
"$schema": "https://json-schema.org/validation",
"$id": "http://localhost:1234/strict-extendible-allof-ref-first.json",
Expand Down
3 changes: 0 additions & 3 deletions stable/json-schema-test-suite/tests/propertyDependencies.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"description": "propertyDependencies doesn't act on non-objects",
"stability": "stage-1",
"schema": {
"propertyDependencies": {
"foo": {"bar": false}
Expand Down Expand Up @@ -42,7 +41,6 @@
},
{
"description": "propertyDependencies doesn't act on non-string property values",
"stability": "stage-1",
"schema": {
"propertyDependencies": {
"foo": {"bar": false}
Expand Down Expand Up @@ -93,7 +91,6 @@
},
{
"description": "multiple options selects the right one",
"stability": "stage-1",
"schema": {
"propertyDependencies": {
"foo": {
Expand Down

0 comments on commit 224e411

Please sign in to comment.