@hyperjump/json-schema 0.23.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +459 -120
- package/draft-04/additionalItems.js +29 -0
- package/{lib/keywords → draft-04}/dependencies.js +9 -5
- package/draft-04/exclusiveMaximum.js +5 -0
- package/draft-04/exclusiveMinimum.js +5 -0
- package/draft-04/id.js +1 -0
- package/draft-04/index.d.ts +43 -0
- package/draft-04/index.js +69 -0
- package/draft-04/items.js +35 -0
- package/draft-04/maximum.js +26 -0
- package/draft-04/minimum.js +25 -0
- package/draft-04/ref.js +1 -0
- package/draft-04/schema.js +149 -0
- package/draft-06/contains.js +13 -0
- package/draft-06/index.d.ts +47 -0
- package/draft-06/index.js +66 -0
- package/draft-06/schema.js +154 -0
- package/{lib/draft-07.d.ts → draft-07/index.d.ts} +21 -19
- package/draft-07/index.js +72 -0
- package/draft-07/schema.js +172 -0
- package/{lib/keywords/contains-minContains-maxContains.js → draft-2019-09/contains.js} +14 -7
- package/{lib/draft-2019-09.d.ts → draft-2019-09/index.d.ts} +24 -22
- package/draft-2019-09/index.js +117 -0
- package/draft-2019-09/meta/applicator.js +55 -0
- package/draft-2019-09/meta/content.js +17 -0
- package/draft-2019-09/meta/core.js +57 -0
- package/draft-2019-09/meta/format.js +14 -0
- package/draft-2019-09/meta/meta-data.js +37 -0
- package/draft-2019-09/meta/validation.js +98 -0
- package/draft-2019-09/recursiveAnchor.js +1 -0
- package/draft-2019-09/recursiveRef.js +19 -0
- package/draft-2019-09/schema.js +42 -0
- package/draft-2020-12/dynamicAnchor.js +1 -0
- package/draft-2020-12/dynamicRef.js +35 -0
- package/draft-2020-12/index.d.ts +66 -0
- package/draft-2020-12/index.js +124 -0
- package/draft-2020-12/meta/applicator.js +46 -0
- package/draft-2020-12/meta/content.js +14 -0
- package/draft-2020-12/meta/core.js +54 -0
- package/draft-2020-12/meta/format-annotation.js +11 -0
- package/draft-2020-12/meta/format-assertion.js +11 -0
- package/draft-2020-12/meta/meta-data.js +34 -0
- package/draft-2020-12/meta/unevaluated.js +12 -0
- package/draft-2020-12/meta/validation.js +95 -0
- package/draft-2020-12/schema.js +44 -0
- package/lib/common.d.ts +5 -1
- package/lib/common.js +80 -9
- package/lib/configuration.d.ts +9 -0
- package/lib/configuration.js +18 -0
- package/lib/core.d.ts +48 -0
- package/lib/core.js +102 -0
- package/lib/experimental.d.ts +8 -0
- package/lib/experimental.js +4 -0
- package/lib/fetch.browser.js +1 -0
- package/lib/fetch.js +19 -0
- package/lib/index.d.ts +11 -42
- package/lib/index.js +130 -23
- package/lib/instance.d.ts +75 -0
- package/lib/instance.js +58 -0
- package/lib/invalid-schema-error.d.ts +8 -0
- package/lib/invalid-schema-error.js +7 -0
- package/lib/keywords/additionalProperties.js +19 -17
- package/lib/keywords/allOf.js +10 -7
- package/lib/keywords/anchor.js +1 -0
- package/lib/keywords/anyOf.js +10 -7
- package/lib/keywords/comment.js +4 -0
- package/lib/keywords/const.js +6 -3
- package/lib/keywords/contains.js +48 -5
- package/lib/keywords/contentEncoding.js +4 -0
- package/lib/keywords/contentMediaType.js +4 -0
- package/lib/keywords/contentSchema.js +4 -0
- package/lib/keywords/default.js +4 -0
- package/lib/keywords/definitions.js +7 -4
- package/lib/keywords/dependentRequired.js +6 -3
- package/lib/keywords/dependentSchemas.js +10 -6
- package/lib/keywords/deprecated.js +4 -0
- package/lib/keywords/description.js +4 -0
- package/lib/keywords/dynamicAnchor.js +1 -0
- package/lib/keywords/dynamicRef.js +13 -17
- package/lib/keywords/else.js +16 -11
- package/lib/keywords/enum.js +6 -3
- package/lib/keywords/examples.js +4 -0
- package/lib/keywords/exclusiveMaximum.js +5 -2
- package/lib/keywords/exclusiveMinimum.js +5 -2
- package/lib/keywords/format.js +4 -0
- package/lib/keywords/id.js +1 -0
- package/lib/keywords/if.js +8 -6
- package/lib/keywords/items.js +17 -19
- package/lib/keywords/maxContains.js +4 -0
- package/lib/keywords/maxItems.js +5 -2
- package/lib/keywords/maxLength.js +5 -2
- package/lib/keywords/maxProperties.js +5 -2
- package/lib/keywords/maximum.js +5 -2
- package/lib/keywords/meta-data.js +4 -0
- package/lib/keywords/minContains.js +4 -0
- package/lib/keywords/minItems.js +5 -2
- package/lib/keywords/minLength.js +5 -2
- package/lib/keywords/minProperties.js +5 -2
- package/lib/keywords/minimum.js +5 -2
- package/lib/keywords/multipleOf.js +5 -2
- package/lib/keywords/not.js +6 -4
- package/lib/keywords/oneOf.js +9 -6
- package/lib/keywords/pattern.js +5 -2
- package/lib/keywords/patternProperties.js +9 -5
- package/lib/keywords/prefixItems.js +28 -0
- package/lib/keywords/properties.js +11 -6
- package/lib/keywords/propertyDependencies.js +49 -0
- package/lib/keywords/propertyNames.js +7 -4
- package/lib/keywords/readOnly.js +4 -0
- package/lib/keywords/ref.js +9 -6
- package/lib/keywords/requireAllExcept.js +24 -0
- package/lib/keywords/required.js +5 -2
- package/lib/keywords/then.js +16 -11
- package/lib/keywords/title.js +4 -0
- package/lib/keywords/type.js +5 -2
- package/lib/keywords/unevaluatedItems.js +9 -5
- package/lib/keywords/unevaluatedProperties.js +9 -5
- package/lib/keywords/uniqueItems.js +6 -3
- package/lib/keywords/validation.js +123 -0
- package/lib/keywords/vocabulary.js +1 -0
- package/lib/keywords/writeOnly.js +4 -0
- package/lib/keywords.d.ts +19 -0
- package/lib/keywords.js +59 -0
- package/lib/media-types.d.ts +9 -0
- package/lib/media-types.js +26 -0
- package/lib/pubsub.js +42 -0
- package/lib/reference.d.ts +11 -0
- package/lib/reference.js +11 -0
- package/lib/schema.d.ts +64 -0
- package/lib/schema.js +308 -0
- package/package.json +31 -22
- package/{lib/draft-2020-12.d.ts → stable/index.d.ts} +26 -24
- package/stable/index.js +118 -0
- package/stable/meta/applicator.js +49 -0
- package/stable/meta/content.js +12 -0
- package/stable/meta/core.js +49 -0
- package/stable/meta/format-annotation.js +10 -0
- package/stable/meta/format-assertion.js +10 -0
- package/stable/meta/meta-data.js +16 -0
- package/stable/meta/unevaluated.js +11 -0
- package/stable/meta/validation.js +67 -0
- package/stable/validation.js +24 -0
- package/dist/json-schema-amd.js +0 -6644
- package/dist/json-schema-amd.js.map +0 -1
- package/dist/json-schema-amd.min.js +0 -2
- package/dist/json-schema-amd.min.js.map +0 -1
- package/dist/json-schema-cjs.js +0 -6642
- package/dist/json-schema-cjs.js.map +0 -1
- package/dist/json-schema-cjs.min.js +0 -2
- package/dist/json-schema-cjs.min.js.map +0 -1
- package/dist/json-schema-esm.js +0 -6638
- package/dist/json-schema-esm.js.map +0 -1
- package/dist/json-schema-esm.min.js +0 -2
- package/dist/json-schema-esm.min.js.map +0 -1
- package/dist/json-schema-iife.js +0 -6647
- package/dist/json-schema-iife.js.map +0 -1
- package/dist/json-schema-iife.min.js +0 -2
- package/dist/json-schema-iife.min.js.map +0 -1
- package/dist/json-schema-system.js +0 -6645
- package/dist/json-schema-system.js.map +0 -1
- package/dist/json-schema-system.min.js +0 -2
- package/dist/json-schema-system.min.js.map +0 -1
- package/dist/json-schema-umd.js +0 -6648
- package/dist/json-schema-umd.js.map +0 -1
- package/dist/json-schema-umd.min.js +0 -2
- package/dist/json-schema-umd.min.js.map +0 -1
- package/lib/draft-04.d.ts +0 -41
- package/lib/draft-04.js +0 -46
- package/lib/draft-06.d.ts +0 -45
- package/lib/draft-06.js +0 -51
- package/lib/draft-07.js +0 -55
- package/lib/draft-2019-09.js +0 -92
- package/lib/draft-2020-12.js +0 -103
- package/lib/index.mjs +0 -19
- package/lib/keywords/additionalItems.js +0 -27
- package/lib/keywords/additionalItems6.js +0 -23
- package/lib/keywords/additionalProperties6.js +0 -28
- package/lib/keywords/index.js +0 -53
- package/lib/keywords/items202012.js +0 -23
- package/lib/keywords/maximum-exclusiveMaximum.js +0 -20
- package/lib/keywords/minimum-exclusiveMinimum.js +0 -20
- package/lib/keywords/tupleItems.js +0 -24
- package/meta/draft/2019-09/meta/applicator.js +0 -55
- package/meta/draft/2019-09/meta/content.js +0 -17
- package/meta/draft/2019-09/meta/core.js +0 -57
- package/meta/draft/2019-09/meta/format.js +0 -14
- package/meta/draft/2019-09/meta/meta-data.js +0 -37
- package/meta/draft/2019-09/meta/validation.js +0 -98
- package/meta/draft/2019-09/schema.js +0 -42
- package/meta/draft/2020-12/meta/applicator.js +0 -49
- package/meta/draft/2020-12/meta/content.js +0 -17
- package/meta/draft/2020-12/meta/core.js +0 -57
- package/meta/draft/2020-12/meta/format-annotation.js +0 -14
- package/meta/draft/2020-12/meta/format-assertion.js +0 -14
- package/meta/draft/2020-12/meta/meta-data.js +0 -37
- package/meta/draft/2020-12/meta/unevaluated.js +0 -15
- package/meta/draft/2020-12/meta/validation.js +0 -98
- package/meta/draft/2020-12/schema.js +0 -44
- package/meta/draft-04/schema.js +0 -149
- package/meta/draft-06/schema.js +0 -154
- package/meta/draft-07/schema.js +0 -172
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import * as Schema from "../lib/schema.js";
|
|
3
|
+
import Validation from "../lib/keywords/validation.js";
|
|
4
|
+
import { getKeywordName } from "../lib/keywords.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const id = "https://json-schema.org/keyword/draft-04/additionalItems";
|
|
8
|
+
|
|
9
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
10
|
+
const itemsKeywordName = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/items");
|
|
11
|
+
const items = await Schema.step(itemsKeywordName, parentSchema);
|
|
12
|
+
const numberOfItems = Schema.typeOf(items, "array") ? Schema.length(items) : Number.MAX_SAFE_INTEGER;
|
|
13
|
+
|
|
14
|
+
return [numberOfItems, await Validation.compile(schema, ast)];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const interpret = ([numberOfItems, additionalItems], instance, ast, dynamicAnchors) => {
|
|
18
|
+
if (!Instance.typeOf(instance, "array")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Instance.every((item, ndx) => ndx < numberOfItems || Validation.interpret(additionalItems, item, ast, dynamicAnchors), instance);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
26
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default { id, compile, interpret, collectEvaluatedItems };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import * as Schema from "../lib/schema.js";
|
|
3
|
+
import Validation from "../lib/keywords/validation.js";
|
|
4
|
+
import * as Pact from "@hyperjump/pact";
|
|
3
5
|
|
|
4
6
|
|
|
7
|
+
const id = "https://json-schema.org/keyword/draft-04/dependencies";
|
|
8
|
+
|
|
5
9
|
const compile = (schema, ast) => Pact.pipeline([
|
|
6
10
|
Schema.entries,
|
|
7
11
|
Pact.map(async ([key, dependency]) => {
|
|
8
|
-
return [key, Schema.typeOf(dependency, "array") ? Schema.value(dependency) : await
|
|
12
|
+
return [key, Schema.typeOf(dependency, "array") ? Schema.value(dependency) : await Validation.compile(dependency, ast)];
|
|
9
13
|
}),
|
|
10
14
|
Pact.all
|
|
11
15
|
], schema);
|
|
@@ -21,9 +25,9 @@ const interpret = (dependencies, instance, ast, dynamicAnchors) => {
|
|
|
21
25
|
if (Array.isArray(dependency)) {
|
|
22
26
|
return dependency.every((key) => key in value);
|
|
23
27
|
} else {
|
|
24
|
-
return
|
|
28
|
+
return Validation.interpret(dependency, instance, ast, dynamicAnchors);
|
|
25
29
|
}
|
|
26
30
|
});
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
export default { id, compile, interpret };
|
package/draft-04/id.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { id: "https://json-schema.org/keyword/draft-04/id" };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Json } from "@hyperjump/json-pointer";
|
|
2
|
+
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export type JsonSchemaDraft04 = {
|
|
6
|
+
$ref: string;
|
|
7
|
+
} | {
|
|
8
|
+
$schema?: "http://json-schema.org/draft-04/schema#";
|
|
9
|
+
id?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
default?: Json;
|
|
13
|
+
multipleOf?: number;
|
|
14
|
+
maximum?: number;
|
|
15
|
+
exclusiveMaximum?: boolean;
|
|
16
|
+
minimum?: number;
|
|
17
|
+
exclusiveMinimum?: boolean;
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
minLength?: number;
|
|
20
|
+
pattern?: string;
|
|
21
|
+
additionalItems?: boolean | JsonSchemaDraft04;
|
|
22
|
+
items?: JsonSchemaDraft04 | JsonSchemaDraft04[];
|
|
23
|
+
maxItems?: number;
|
|
24
|
+
minItems?: number;
|
|
25
|
+
uniqueItems?: boolean;
|
|
26
|
+
maxProperties?: number;
|
|
27
|
+
minProperties?: number;
|
|
28
|
+
required?: string[];
|
|
29
|
+
additionalProperties?: boolean | JsonSchemaDraft04;
|
|
30
|
+
definitions?: Record<string, JsonSchemaDraft04>;
|
|
31
|
+
properties?: Record<string, JsonSchemaDraft04>;
|
|
32
|
+
patternProperties?: Record<string, JsonSchemaDraft04>;
|
|
33
|
+
dependencies?: Record<string, JsonSchemaDraft04 | string[]>;
|
|
34
|
+
enum?: Json[];
|
|
35
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
36
|
+
format?: "date-time" | "email" | "hostname" | "ipv4" | "ipv6" | "uri";
|
|
37
|
+
allOf?: JsonSchemaDraft04[];
|
|
38
|
+
anyOf?: JsonSchemaDraft04[];
|
|
39
|
+
oneOf?: JsonSchemaDraft04[];
|
|
40
|
+
not?: JsonSchemaDraft04;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export * from "../lib/index.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
|
|
2
|
+
import { addSchema } from "../lib/core.js";
|
|
3
|
+
import metaSchema from "./schema.js";
|
|
4
|
+
import additionalItems from "./additionalItems.js";
|
|
5
|
+
import dependencies from "./dependencies.js";
|
|
6
|
+
import exclusiveMaximum from "./exclusiveMaximum.js";
|
|
7
|
+
import exclusiveMinimum from "./exclusiveMinimum.js";
|
|
8
|
+
import id from "./id.js";
|
|
9
|
+
import items from "./items.js";
|
|
10
|
+
import maximum from "./maximum.js";
|
|
11
|
+
import minimum from "./minimum.js";
|
|
12
|
+
import ref from "./ref.js";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
addKeyword(additionalItems);
|
|
16
|
+
addKeyword(dependencies);
|
|
17
|
+
addKeyword(exclusiveMaximum);
|
|
18
|
+
addKeyword(exclusiveMinimum);
|
|
19
|
+
addKeyword(maximum);
|
|
20
|
+
addKeyword(minimum);
|
|
21
|
+
addKeyword(id);
|
|
22
|
+
addKeyword(items);
|
|
23
|
+
addKeyword(ref);
|
|
24
|
+
|
|
25
|
+
const jsonSchemaVersion = "http://json-schema.org/draft-04/schema";
|
|
26
|
+
|
|
27
|
+
defineVocabulary(jsonSchemaVersion, {
|
|
28
|
+
"id": "https://json-schema.org/keyword/draft-04/id",
|
|
29
|
+
"$ref": "https://json-schema.org/keyword/draft-04/ref",
|
|
30
|
+
"additionalItems": "https://json-schema.org/keyword/draft-04/additionalItems",
|
|
31
|
+
"additionalProperties": "https://json-schema.org/keyword/additionalProperties",
|
|
32
|
+
"allOf": "https://json-schema.org/keyword/allOf",
|
|
33
|
+
"anyOf": "https://json-schema.org/keyword/anyOf",
|
|
34
|
+
"default": "https://json-schema.org/keyword/default",
|
|
35
|
+
"definitions": "https://json-schema.org/keyword/definitions",
|
|
36
|
+
"dependencies": "https://json-schema.org/keyword/draft-04/dependencies",
|
|
37
|
+
"description": "https://json-schema.org/keyword/description",
|
|
38
|
+
"enum": "https://json-schema.org/keyword/enum",
|
|
39
|
+
"exclusiveMaximum": "https://json-schema.org/keyword/draft-04/exclusiveMaximum",
|
|
40
|
+
"exclusiveMinimum": "https://json-schema.org/keyword/draft-04/exclusiveMinimum",
|
|
41
|
+
"format": "https://json-schema.org/keyword/format",
|
|
42
|
+
"items": "https://json-schema.org/keyword/draft-04/items",
|
|
43
|
+
"maxItems": "https://json-schema.org/keyword/maxItems",
|
|
44
|
+
"maxLength": "https://json-schema.org/keyword/maxLength",
|
|
45
|
+
"maxProperties": "https://json-schema.org/keyword/maxProperties",
|
|
46
|
+
"maximum": "https://json-schema.org/keyword/draft-04/maximum",
|
|
47
|
+
"minItems": "https://json-schema.org/keyword/minItems",
|
|
48
|
+
"minLength": "https://json-schema.org/keyword/minLength",
|
|
49
|
+
"minProperties": "https://json-schema.org/keyword/minProperties",
|
|
50
|
+
"minimum": "https://json-schema.org/keyword/draft-04/minimum",
|
|
51
|
+
"multipleOf": "https://json-schema.org/keyword/multipleOf",
|
|
52
|
+
"not": "https://json-schema.org/keyword/not",
|
|
53
|
+
"oneOf": "https://json-schema.org/keyword/oneOf",
|
|
54
|
+
"pattern": "https://json-schema.org/keyword/pattern",
|
|
55
|
+
"patternProperties": "https://json-schema.org/keyword/patternProperties",
|
|
56
|
+
"properties": "https://json-schema.org/keyword/properties",
|
|
57
|
+
"required": "https://json-schema.org/keyword/required",
|
|
58
|
+
"title": "https://json-schema.org/keyword/title",
|
|
59
|
+
"type": "https://json-schema.org/keyword/type",
|
|
60
|
+
"uniqueItems": "https://json-schema.org/keyword/uniqueItems"
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
loadDialect(jsonSchemaVersion, {
|
|
64
|
+
[jsonSchemaVersion]: true
|
|
65
|
+
}, true);
|
|
66
|
+
|
|
67
|
+
addSchema(metaSchema);
|
|
68
|
+
|
|
69
|
+
export * from "../lib/index.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import * as Schema from "../lib/schema.js";
|
|
3
|
+
import Validation from "../lib/keywords/validation.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const id = "https://json-schema.org/keyword/draft-04/items";
|
|
7
|
+
|
|
8
|
+
const compile = async (schema, ast) => {
|
|
9
|
+
if (Schema.typeOf(schema, "array")) {
|
|
10
|
+
const tupleItems = await Schema.map((itemSchema) => Validation.compile(itemSchema, ast), schema);
|
|
11
|
+
return Promise.all(tupleItems);
|
|
12
|
+
} else {
|
|
13
|
+
return Validation.compile(schema, ast);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const interpret = (items, instance, ast, dynamicAnchors) => {
|
|
18
|
+
if (!Instance.typeOf(instance, "array")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (typeof items === "string") {
|
|
23
|
+
return Instance.every((itemValue) => Validation.interpret(items, itemValue, ast, dynamicAnchors), instance);
|
|
24
|
+
} else {
|
|
25
|
+
return Instance.every((item, ndx) => !(ndx in items) || Validation.interpret(items[ndx], item, ast, dynamicAnchors), instance);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => {
|
|
30
|
+
return interpret(items, instance, ast, dynamicAnchors) && (typeof items === "string"
|
|
31
|
+
? new Set(Instance.map((item, itemIndex) => itemIndex, instance))
|
|
32
|
+
: new Set(items.map((item, itemIndex) => itemIndex)));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default { id, compile, interpret, collectEvaluatedItems };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import * as Schema from "../lib/schema.js";
|
|
3
|
+
import { getKeywordName } from "../lib/keywords.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const id = "https://json-schema.org/keyword/draft-04/maximum";
|
|
7
|
+
|
|
8
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
9
|
+
const exclusiveMaximumKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/exclusiveMaximum");
|
|
10
|
+
console.log(exclusiveMaximumKeyword);
|
|
11
|
+
const exclusiveMaximum = await Schema.step(exclusiveMaximumKeyword, parentSchema);
|
|
12
|
+
const isExclusive = Schema.value(exclusiveMaximum);
|
|
13
|
+
|
|
14
|
+
return [Schema.value(schema), isExclusive];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const interpret = ([maximum, isExclusive], instance) => {
|
|
18
|
+
if (!Instance.typeOf(instance, "number")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const value = Instance.value(instance);
|
|
23
|
+
return isExclusive ? value < maximum : value <= maximum;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default { id, compile, interpret };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import * as Schema from "../lib/schema.js";
|
|
3
|
+
import { getKeywordName } from "../lib/keywords.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const id = "https://json-schema.org/keyword/draft-04/minimum";
|
|
7
|
+
|
|
8
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
9
|
+
const exclusiveMinimumKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/exclusiveMinimum");
|
|
10
|
+
const exclusiveMinimum = await Schema.step(exclusiveMinimumKeyword, parentSchema);
|
|
11
|
+
const isExclusive = Schema.value(exclusiveMinimum);
|
|
12
|
+
|
|
13
|
+
return [Schema.value(schema), isExclusive];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const interpret = ([minimum, isExclusive], instance) => {
|
|
17
|
+
if (!Instance.typeOf(instance, "number")) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const value = Instance.value(instance);
|
|
22
|
+
return isExclusive ? value > minimum : value >= minimum;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default { id, compile, interpret };
|
package/draft-04/ref.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { id: "https://json-schema.org/keyword/draft-04/ref" };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
"id": "http://json-schema.org/draft-04/schema#",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
4
|
+
"description": "Core schema meta-schema",
|
|
5
|
+
"definitions": {
|
|
6
|
+
"schemaArray": {
|
|
7
|
+
"type": "array",
|
|
8
|
+
"minItems": 1,
|
|
9
|
+
"items": { "$ref": "#" }
|
|
10
|
+
},
|
|
11
|
+
"positiveInteger": {
|
|
12
|
+
"type": "integer",
|
|
13
|
+
"minimum": 0
|
|
14
|
+
},
|
|
15
|
+
"positiveIntegerDefault0": {
|
|
16
|
+
"allOf": [{ "$ref": "#/definitions/positiveInteger" }, { "default": 0 }]
|
|
17
|
+
},
|
|
18
|
+
"simpleTypes": {
|
|
19
|
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
|
20
|
+
},
|
|
21
|
+
"stringArray": {
|
|
22
|
+
"type": "array",
|
|
23
|
+
"items": { "type": "string" },
|
|
24
|
+
"minItems": 1,
|
|
25
|
+
"uniqueItems": true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"type": "object",
|
|
29
|
+
"properties": {
|
|
30
|
+
"id": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"$schema": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"title": {
|
|
37
|
+
"type": "string"
|
|
38
|
+
},
|
|
39
|
+
"description": {
|
|
40
|
+
"type": "string"
|
|
41
|
+
},
|
|
42
|
+
"default": {},
|
|
43
|
+
"multipleOf": {
|
|
44
|
+
"type": "number",
|
|
45
|
+
"minimum": 0,
|
|
46
|
+
"exclusiveMinimum": true
|
|
47
|
+
},
|
|
48
|
+
"maximum": {
|
|
49
|
+
"type": "number"
|
|
50
|
+
},
|
|
51
|
+
"exclusiveMaximum": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"default": false
|
|
54
|
+
},
|
|
55
|
+
"minimum": {
|
|
56
|
+
"type": "number"
|
|
57
|
+
},
|
|
58
|
+
"exclusiveMinimum": {
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"default": false
|
|
61
|
+
},
|
|
62
|
+
"maxLength": { "$ref": "#/definitions/positiveInteger" },
|
|
63
|
+
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
|
64
|
+
"pattern": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"format": "regex"
|
|
67
|
+
},
|
|
68
|
+
"additionalItems": {
|
|
69
|
+
"anyOf": [
|
|
70
|
+
{ "type": "boolean" },
|
|
71
|
+
{ "$ref": "#" }
|
|
72
|
+
],
|
|
73
|
+
"default": {}
|
|
74
|
+
},
|
|
75
|
+
"items": {
|
|
76
|
+
"anyOf": [
|
|
77
|
+
{ "$ref": "#" },
|
|
78
|
+
{ "$ref": "#/definitions/schemaArray" }
|
|
79
|
+
],
|
|
80
|
+
"default": {}
|
|
81
|
+
},
|
|
82
|
+
"maxItems": { "$ref": "#/definitions/positiveInteger" },
|
|
83
|
+
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
|
84
|
+
"uniqueItems": {
|
|
85
|
+
"type": "boolean",
|
|
86
|
+
"default": false
|
|
87
|
+
},
|
|
88
|
+
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
|
|
89
|
+
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
|
90
|
+
"required": { "$ref": "#/definitions/stringArray" },
|
|
91
|
+
"additionalProperties": {
|
|
92
|
+
"anyOf": [
|
|
93
|
+
{ "type": "boolean" },
|
|
94
|
+
{ "$ref": "#" }
|
|
95
|
+
],
|
|
96
|
+
"default": {}
|
|
97
|
+
},
|
|
98
|
+
"definitions": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"additionalProperties": { "$ref": "#" },
|
|
101
|
+
"default": {}
|
|
102
|
+
},
|
|
103
|
+
"properties": {
|
|
104
|
+
"type": "object",
|
|
105
|
+
"additionalProperties": { "$ref": "#" },
|
|
106
|
+
"default": {}
|
|
107
|
+
},
|
|
108
|
+
"patternProperties": {
|
|
109
|
+
"type": "object",
|
|
110
|
+
"additionalProperties": { "$ref": "#" },
|
|
111
|
+
"default": {}
|
|
112
|
+
},
|
|
113
|
+
"dependencies": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"additionalProperties": {
|
|
116
|
+
"anyOf": [
|
|
117
|
+
{ "$ref": "#" },
|
|
118
|
+
{ "$ref": "#/definitions/stringArray" }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"enum": {
|
|
123
|
+
"type": "array",
|
|
124
|
+
"minItems": 1,
|
|
125
|
+
"uniqueItems": true
|
|
126
|
+
},
|
|
127
|
+
"type": {
|
|
128
|
+
"anyOf": [
|
|
129
|
+
{ "$ref": "#/definitions/simpleTypes" },
|
|
130
|
+
{
|
|
131
|
+
"type": "array",
|
|
132
|
+
"items": { "$ref": "#/definitions/simpleTypes" },
|
|
133
|
+
"minItems": 1,
|
|
134
|
+
"uniqueItems": true
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"format": { "type": "string" },
|
|
139
|
+
"allOf": { "$ref": "#/definitions/schemaArray" },
|
|
140
|
+
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
|
141
|
+
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
|
142
|
+
"not": { "$ref": "#" }
|
|
143
|
+
},
|
|
144
|
+
"dependencies": {
|
|
145
|
+
"exclusiveMaximum": ["maximum"],
|
|
146
|
+
"exclusiveMinimum": ["minimum"]
|
|
147
|
+
},
|
|
148
|
+
"default": {}
|
|
149
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Instance from "../lib/instance.js";
|
|
2
|
+
import Validation from "../lib/keywords/validation.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const id = "https://json-schema.org/keyword/draft-06/contains";
|
|
6
|
+
|
|
7
|
+
const compile = (schema, ast) => Validation.compile(schema, ast);
|
|
8
|
+
|
|
9
|
+
const interpret = (contains, instance, ast, dynamicAnchors) => {
|
|
10
|
+
return !Instance.typeOf(instance, "array") || Instance.some((item) => Validation.interpret(contains, item, ast, dynamicAnchors), instance);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default { id, compile, interpret };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Json } from "@hyperjump/json-pointer";
|
|
2
|
+
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export type JsonSchemaDraft06 = boolean | {
|
|
6
|
+
$ref: string;
|
|
7
|
+
} | {
|
|
8
|
+
$schema?: "http://json-schema.org/draft-06/schema#";
|
|
9
|
+
$id?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
default?: Json;
|
|
13
|
+
examples?: Json[];
|
|
14
|
+
multipleOf?: number;
|
|
15
|
+
maximum?: number;
|
|
16
|
+
exclusiveMaximum?: number;
|
|
17
|
+
minimum?: number;
|
|
18
|
+
exclusiveMinimum?: number;
|
|
19
|
+
maxLength?: number;
|
|
20
|
+
minLength?: number;
|
|
21
|
+
pattern?: string;
|
|
22
|
+
additionalItems?: JsonSchemaDraft06;
|
|
23
|
+
items?: JsonSchemaDraft06 | JsonSchemaDraft06[];
|
|
24
|
+
maxItems?: number;
|
|
25
|
+
minItems?: number;
|
|
26
|
+
uniqueItems?: boolean;
|
|
27
|
+
contains?: JsonSchemaDraft06;
|
|
28
|
+
maxProperties?: number;
|
|
29
|
+
minProperties?: number;
|
|
30
|
+
required?: string[];
|
|
31
|
+
additionalProperties?: JsonSchemaDraft06;
|
|
32
|
+
definitions?: Record<string, JsonSchemaDraft06>;
|
|
33
|
+
properties?: Record<string, JsonSchemaDraft06>;
|
|
34
|
+
patternProperties?: Record<string, JsonSchemaDraft06>;
|
|
35
|
+
dependencies?: Record<string, JsonSchemaDraft06 | string[]>;
|
|
36
|
+
propertyNames?: JsonSchemaDraft06;
|
|
37
|
+
const?: Json;
|
|
38
|
+
enum?: Json[];
|
|
39
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
40
|
+
format?: "date-time" | "email" | "hostname" | "ipv4" | "ipv6" | "uri" | "uri-reference" | "uri-template" | "json-pointer";
|
|
41
|
+
allOf?: JsonSchemaDraft06[];
|
|
42
|
+
anyOf?: JsonSchemaDraft06[];
|
|
43
|
+
oneOf?: JsonSchemaDraft06[];
|
|
44
|
+
not?: JsonSchemaDraft06;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export * from "../lib/index.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
|
|
2
|
+
import { addSchema } from "../lib/core.js";
|
|
3
|
+
import metaSchema from "./schema.js";
|
|
4
|
+
import additionalItems from "../draft-04/additionalItems.js";
|
|
5
|
+
import contains from "./contains.js";
|
|
6
|
+
import dependencies from "../draft-04/dependencies.js";
|
|
7
|
+
import id from "../draft-04/id.js";
|
|
8
|
+
import items from "../draft-04/items.js";
|
|
9
|
+
import ref from "../draft-04/ref.js";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
addKeyword(additionalItems);
|
|
13
|
+
addKeyword(dependencies);
|
|
14
|
+
addKeyword(contains);
|
|
15
|
+
addKeyword(id);
|
|
16
|
+
addKeyword(items);
|
|
17
|
+
addKeyword(ref);
|
|
18
|
+
|
|
19
|
+
const jsonSchemaVersion = "http://json-schema.org/draft-06/schema";
|
|
20
|
+
|
|
21
|
+
defineVocabulary(jsonSchemaVersion, {
|
|
22
|
+
"$id": "https://json-schema.org/keyword/draft-04/id",
|
|
23
|
+
"$ref": "https://json-schema.org/keyword/draft-04/ref",
|
|
24
|
+
"additionalItems": "https://json-schema.org/keyword/draft-04/additionalItems",
|
|
25
|
+
"additionalProperties": "https://json-schema.org/keyword/additionalProperties",
|
|
26
|
+
"allOf": "https://json-schema.org/keyword/allOf",
|
|
27
|
+
"anyOf": "https://json-schema.org/keyword/anyOf",
|
|
28
|
+
"const": "https://json-schema.org/keyword/const",
|
|
29
|
+
"contains": "https://json-schema.org/keyword/draft-06/contains",
|
|
30
|
+
"default": "https://json-schema.org/keyword/default",
|
|
31
|
+
"definitions": "https://json-schema.org/keyword/definitions",
|
|
32
|
+
"dependencies": "https://json-schema.org/keyword/draft-04/dependencies",
|
|
33
|
+
"description": "https://json-schema.org/keyword/description",
|
|
34
|
+
"enum": "https://json-schema.org/keyword/enum",
|
|
35
|
+
"exclusiveMaximum": "https://json-schema.org/keyword/exclusiveMaximum",
|
|
36
|
+
"exclusiveMinimum": "https://json-schema.org/keyword/exclusiveMinimum",
|
|
37
|
+
"format": "https://json-schema.org/keyword/format",
|
|
38
|
+
"items": "https://json-schema.org/keyword/draft-04/items",
|
|
39
|
+
"maxItems": "https://json-schema.org/keyword/maxItems",
|
|
40
|
+
"maxLength": "https://json-schema.org/keyword/maxLength",
|
|
41
|
+
"maxProperties": "https://json-schema.org/keyword/maxProperties",
|
|
42
|
+
"maximum": "https://json-schema.org/keyword/maximum",
|
|
43
|
+
"minItems": "https://json-schema.org/keyword/minItems",
|
|
44
|
+
"minLength": "https://json-schema.org/keyword/minLength",
|
|
45
|
+
"minProperties": "https://json-schema.org/keyword/minProperties",
|
|
46
|
+
"minimum": "https://json-schema.org/keyword/minimum",
|
|
47
|
+
"multipleOf": "https://json-schema.org/keyword/multipleOf",
|
|
48
|
+
"not": "https://json-schema.org/keyword/not",
|
|
49
|
+
"oneOf": "https://json-schema.org/keyword/oneOf",
|
|
50
|
+
"pattern": "https://json-schema.org/keyword/pattern",
|
|
51
|
+
"patternProperties": "https://json-schema.org/keyword/patternProperties",
|
|
52
|
+
"properties": "https://json-schema.org/keyword/properties",
|
|
53
|
+
"propertyNames": "https://json-schema.org/keyword/propertyNames",
|
|
54
|
+
"required": "https://json-schema.org/keyword/required",
|
|
55
|
+
"title": "https://json-schema.org/keyword/title",
|
|
56
|
+
"type": "https://json-schema.org/keyword/type",
|
|
57
|
+
"uniqueItems": "https://json-schema.org/keyword/uniqueItems"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
loadDialect(jsonSchemaVersion, {
|
|
61
|
+
[jsonSchemaVersion]: true
|
|
62
|
+
}, true);
|
|
63
|
+
|
|
64
|
+
addSchema(metaSchema);
|
|
65
|
+
|
|
66
|
+
export * from "../lib/index.js";
|