@hyperjump/json-schema 1.16.5 → 1.17.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/README.md +100 -11
- package/annotations/annotated-instance.js +1 -1
- package/draft-04/format.js +31 -0
- package/draft-04/index.js +3 -1
- package/draft-06/format.js +34 -0
- package/draft-06/index.js +3 -1
- package/draft-07/format.js +42 -0
- package/draft-07/index.js +3 -1
- package/draft-2019-09/format-assertion.js +44 -0
- package/draft-2019-09/format.js +44 -0
- package/draft-2019-09/index.js +5 -1
- package/draft-2020-12/format-assertion.js +43 -0
- package/draft-2020-12/index.js +6 -2
- package/formats/handlers/date-time.js +7 -0
- package/formats/handlers/date.js +7 -0
- package/formats/handlers/draft-04/hostname.js +7 -0
- package/formats/handlers/duration.js +7 -0
- package/formats/handlers/email.js +7 -0
- package/formats/handlers/hostname.js +7 -0
- package/formats/handlers/idn-email.js +7 -0
- package/formats/handlers/idn-hostname.js +7 -0
- package/formats/handlers/ipv4.js +7 -0
- package/formats/handlers/ipv6.js +7 -0
- package/formats/handlers/iri-reference.js +7 -0
- package/formats/handlers/iri.js +7 -0
- package/formats/handlers/json-pointer.js +7 -0
- package/formats/handlers/regex.js +7 -0
- package/formats/handlers/relative-json-pointer.js +7 -0
- package/formats/handlers/time.js +7 -0
- package/formats/handlers/uri-reference.js +7 -0
- package/formats/handlers/uri-template.js +7 -0
- package/formats/handlers/uri.js +7 -0
- package/formats/handlers/uuid.js +7 -0
- package/formats/index.js +12 -0
- package/formats/lite.js +43 -0
- package/lib/configuration.js +7 -2
- package/lib/experimental.d.ts +8 -0
- package/lib/experimental.js +1 -0
- package/lib/keywords/dynamicRef.js +1 -1
- package/lib/keywords/format.js +35 -2
- package/lib/keywords.js +25 -3
- package/openapi-3-0/index.js +1 -1
- package/package.json +8 -5
- package/v1/extension-tests/conditional.json +289 -0
- package/v1/extension-tests/itemPattern.json +462 -0
- package/{stable → v1}/index.d.ts +2 -2
- package/{stable → v1}/index.js +25 -30
- package/{stable → v1}/meta/applicator.js +1 -3
- package/{stable → v1}/meta/content.js +1 -3
- package/{stable → v1}/meta/core.js +5 -4
- package/v1/meta/format.js +8 -0
- package/{stable → v1}/meta/meta-data.js +1 -3
- package/{stable → v1}/meta/unevaluated.js +1 -3
- package/{stable → v1}/meta/validation.js +1 -3
- package/v1/schema.js +24 -0
- package/stable/meta/format-annotation.js +0 -10
- package/stable/meta/format-assertion.js +0 -10
- package/stable/validation.js +0 -24
package/formats/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { addFormat } from "../lib/keywords.js";
|
|
2
|
+
|
|
3
|
+
import idnEmail from "./handlers/idn-email.js";
|
|
4
|
+
import hostname from "./handlers/hostname.js";
|
|
5
|
+
import idnHostname from "./handlers/idn-hostname.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
addFormat(idnEmail);
|
|
9
|
+
addFormat(hostname);
|
|
10
|
+
addFormat(idnHostname);
|
|
11
|
+
|
|
12
|
+
export * from "./lite.js";
|
package/formats/lite.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { addFormat } from "../lib/keywords.js";
|
|
2
|
+
|
|
3
|
+
import draft04Hostname from "./handlers/draft-04/hostname.js";
|
|
4
|
+
import dateTime from "./handlers/date-time.js";
|
|
5
|
+
import date from "./handlers/date.js";
|
|
6
|
+
import time from "./handlers/time.js";
|
|
7
|
+
import duration from "./handlers/duration.js";
|
|
8
|
+
import email from "./handlers/email.js";
|
|
9
|
+
import ipv4 from "./handlers/ipv4.js";
|
|
10
|
+
import ipv6 from "./handlers/ipv6.js";
|
|
11
|
+
import uri from "./handlers/uri.js";
|
|
12
|
+
import uriReference from "./handlers/uri-reference.js";
|
|
13
|
+
import iri from "./handlers/iri.js";
|
|
14
|
+
import iriReference from "./handlers/iri-reference.js";
|
|
15
|
+
import uuid from "./handlers/uuid.js";
|
|
16
|
+
import uriTemplate from "./handlers/uri-template.js";
|
|
17
|
+
import jsonPointer from "./handlers/json-pointer.js";
|
|
18
|
+
import relativeJsonPointer from "./handlers/relative-json-pointer.js";
|
|
19
|
+
import regex from "./handlers/regex.js";
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
addFormat(draft04Hostname);
|
|
23
|
+
addFormat(dateTime);
|
|
24
|
+
addFormat(date);
|
|
25
|
+
addFormat(time);
|
|
26
|
+
addFormat(duration);
|
|
27
|
+
addFormat(email);
|
|
28
|
+
addFormat(ipv4);
|
|
29
|
+
addFormat(ipv6);
|
|
30
|
+
addFormat(uri);
|
|
31
|
+
addFormat(uriReference);
|
|
32
|
+
addFormat(iri);
|
|
33
|
+
addFormat(iriReference);
|
|
34
|
+
addFormat(uuid);
|
|
35
|
+
addFormat(uriTemplate);
|
|
36
|
+
addFormat(jsonPointer);
|
|
37
|
+
addFormat(relativeJsonPointer);
|
|
38
|
+
addFormat(regex);
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
getShouldValidateFormat,
|
|
42
|
+
setShouldValidateFormat
|
|
43
|
+
} from "../lib/configuration.js";
|
package/lib/configuration.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
let metaSchemaOutputFormat;
|
|
2
|
-
let shouldValidateSchema = true;
|
|
3
|
-
|
|
4
2
|
export const getMetaSchemaOutputFormat = () => metaSchemaOutputFormat;
|
|
5
3
|
export const setMetaSchemaOutputFormat = (format) => {
|
|
6
4
|
metaSchemaOutputFormat = format;
|
|
7
5
|
};
|
|
8
6
|
|
|
7
|
+
let shouldValidateSchema = true;
|
|
9
8
|
export const getShouldValidateSchema = () => shouldValidateSchema;
|
|
10
9
|
export const setShouldValidateSchema = (isEnabled) => {
|
|
11
10
|
shouldValidateSchema = isEnabled;
|
|
12
11
|
};
|
|
12
|
+
|
|
13
|
+
let shouldValidateFormat;
|
|
14
|
+
export const getShouldValidateFormat = () => shouldValidateFormat;
|
|
15
|
+
export const setShouldValidateFormat = (isEnabled) => {
|
|
16
|
+
shouldValidateFormat = isEnabled;
|
|
17
|
+
};
|
package/lib/experimental.d.ts
CHANGED
|
@@ -61,11 +61,19 @@ export const getKeywordName: (dialectId: string, keywordId: string) => string;
|
|
|
61
61
|
export const getKeyword: <A>(id: string) => Keyword<A>;
|
|
62
62
|
export const getKeywordByName: <A>(keywordName: string, dialectId: string) => Keyword<A>;
|
|
63
63
|
export const getKeywordId: (keywordName: string, dialectId: string) => string;
|
|
64
|
+
export const addFormat: (format: Format) => void;
|
|
65
|
+
export const setFormatHandler: (keywordUri: string, formatName: string, formatUri: string) => void;
|
|
66
|
+
export const removeFormatHandler: (keywordUri: string, formatName: string) => void;
|
|
64
67
|
export const defineVocabulary: (id: string, keywords: Record<string, string>) => void;
|
|
65
68
|
export const loadDialect: (dialectId: string, dialect: Record<string, boolean>, allowUnknownKeywords?: boolean) => void;
|
|
66
69
|
export const unloadDialect: (dialectId: string) => void;
|
|
67
70
|
export const hasDialect: (dialectId: string) => boolean;
|
|
68
71
|
|
|
72
|
+
export type Format = {
|
|
73
|
+
id: string;
|
|
74
|
+
handler: (value: Json) => boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
69
77
|
export type Keyword<A, Context extends ValidationContext = ValidationContext> = {
|
|
70
78
|
id: string;
|
|
71
79
|
compile: (schema: Browser<SchemaDocument>, ast: AST, parentSchema: Browser<SchemaDocument>) => Promise<A>;
|
package/lib/experimental.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { compile, interpret, BASIC, DETAILED } from "./core.js";
|
|
2
2
|
export {
|
|
3
3
|
addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId,
|
|
4
|
+
addFormat, setFormatHandler, removeFormatHandler,
|
|
4
5
|
defineVocabulary,
|
|
5
6
|
loadDialect, unloadDialect, hasDialect
|
|
6
7
|
} from "./keywords.js";
|
|
@@ -10,7 +10,7 @@ const compile = async (schema, ast) => {
|
|
|
10
10
|
const self = await Browser.get(schema.document.baseUri, schema);
|
|
11
11
|
await Validation.compile(self, ast);
|
|
12
12
|
|
|
13
|
-
return reference;
|
|
13
|
+
return reference.startsWith("#") ? reference.slice(1) : reference;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const interpret = (fragment, instance, context) => {
|
package/lib/keywords/format.js
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
import * as Browser from "@hyperjump/browser";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
3
|
+
import { getFormatHandler } from "../keywords.js";
|
|
2
4
|
|
|
3
5
|
|
|
4
6
|
const id = "https://json-schema.org/keyword/format";
|
|
5
7
|
|
|
6
8
|
const compile = (schema) => Browser.value(schema);
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
const interpret = (format, instance) => {
|
|
11
|
+
const handler = getFormatHandler(formats[format]);
|
|
12
|
+
if (!handler) {
|
|
13
|
+
throw Error(`The '${format}' format is not supported.`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return handler(Instance.value(instance));
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
const annotation = (format) => format;
|
|
9
20
|
|
|
10
|
-
|
|
21
|
+
const formats = {
|
|
22
|
+
"date-time": "https://json-schema.org/format/date-time",
|
|
23
|
+
"date": "https://json-schema.org/format/date",
|
|
24
|
+
"time": "https://json-schema.org/format/time",
|
|
25
|
+
"duration": "https://json-schema.org/format/duration",
|
|
26
|
+
"email": "https://json-schema.org/format/email",
|
|
27
|
+
"idn-email": "https://json-schema.org/format/idn-email",
|
|
28
|
+
"hostname": "https://json-schema.org/format/hostname",
|
|
29
|
+
"idn-hostname": "https://json-schema.org/format/idn-hostname",
|
|
30
|
+
"ipv4": "https://json-schema.org/format/ipv4",
|
|
31
|
+
"ipv6": "https://json-schema.org/format/ipv6",
|
|
32
|
+
"uri": "https://json-schema.org/format/uri",
|
|
33
|
+
"uri-reference": "https://json-schema.org/format/uri-reference",
|
|
34
|
+
"iri": "https://json-schema.org/format/iri",
|
|
35
|
+
"iri-reference": "https://json-schema.org/format/iri-reference",
|
|
36
|
+
"uuid": "https://json-schema.org/format/uuid",
|
|
37
|
+
"uri-template": "https://json-schema.org/format/uri-template",
|
|
38
|
+
"json-pointer": "https://json-schema.org/format/json-pointer",
|
|
39
|
+
"relative-json-pointer": "https://json-schema.org/format/relative-json-pointer",
|
|
40
|
+
"regex": "https://json-schema.org/format/regex"
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default { id, compile, interpret, annotation, formats };
|
package/lib/keywords.js
CHANGED
|
@@ -34,6 +34,23 @@ export const defineVocabulary = (id, keywords) => {
|
|
|
34
34
|
_vocabularies[id] = keywords;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
const _formats = {};
|
|
38
|
+
export const addFormat = (format) => {
|
|
39
|
+
_formats[format.id] = format.handler;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const getFormatHandler = (formatUri) => {
|
|
43
|
+
return _formats[formatUri];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const setFormatHandler = (keywordUri, formatName, formatUri) => {
|
|
47
|
+
_keywords[keywordUri].formats[formatName] = formatUri;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const removeFormatHandler = (keywordUri, formatName) => {
|
|
51
|
+
delete _keywords[keywordUri].formats[formatName];
|
|
52
|
+
};
|
|
53
|
+
|
|
37
54
|
const _dialects = {};
|
|
38
55
|
|
|
39
56
|
export const getKeywordId = (keyword, dialectId) => {
|
|
@@ -74,9 +91,14 @@ export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false, is
|
|
|
74
91
|
if (vocabularyId in _vocabularies) {
|
|
75
92
|
for (const keyword in _vocabularies[vocabularyId]) {
|
|
76
93
|
let keywordId = _vocabularies[vocabularyId][keyword];
|
|
77
|
-
if (!
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
if (!dialect[vocabularyId]) {
|
|
95
|
+
if (vocabularyId === "https://json-schema.org/draft/2019-09/vocab/format") {
|
|
96
|
+
// Handle inconsistent 2019-09 behavior
|
|
97
|
+
keywordId = "https://json-schema.org/keyword/draft-2019-09/format";
|
|
98
|
+
} else if (!(keywordId in _keywords)) {
|
|
99
|
+
// Allow keyword to be ignored
|
|
100
|
+
keywordId = `https://json-schema.org/keyword/unknown#${keyword}`;
|
|
101
|
+
}
|
|
80
102
|
}
|
|
81
103
|
_dialects[dialectId].keywords[keyword] = keywordId;
|
|
82
104
|
}
|
package/openapi-3-0/index.js
CHANGED
|
@@ -38,7 +38,7 @@ defineVocabulary(jsonSchemaVersion, {
|
|
|
38
38
|
"exclusiveMaximum": "https://json-schema.org/keyword/draft-04/exclusiveMaximum",
|
|
39
39
|
"exclusiveMinimum": "https://json-schema.org/keyword/draft-04/exclusiveMinimum",
|
|
40
40
|
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
|
|
41
|
-
"format": "https://json-schema.org/keyword/format",
|
|
41
|
+
"format": "https://json-schema.org/keyword/draft-04/format",
|
|
42
42
|
"items": "https://json-schema.org/keyword/draft-04/items",
|
|
43
43
|
"maxItems": "https://json-schema.org/keyword/maxItems",
|
|
44
44
|
"maxLength": "https://json-schema.org/keyword/maxLength",
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperjump/json-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
6
|
+
"main": "./v1/index.js",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
8
|
+
".": "./v1/index.js",
|
|
9
9
|
"./draft-04": "./draft-04/index.js",
|
|
10
10
|
"./draft-06": "./draft-06/index.js",
|
|
11
11
|
"./draft-07": "./draft-07/index.js",
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
"./instance/experimental": "./lib/instance.js",
|
|
19
19
|
"./annotations/experimental": "./annotations/index.js",
|
|
20
20
|
"./annotated-instance/experimental": "./annotations/annotated-instance.js",
|
|
21
|
-
"./bundle": "./bundle/index.js"
|
|
21
|
+
"./bundle": "./bundle/index.js",
|
|
22
|
+
"./formats": "./formats/index.js",
|
|
23
|
+
"./formats-lite": "./formats/lite.js"
|
|
22
24
|
},
|
|
23
25
|
"scripts": {
|
|
24
26
|
"clean": "xargs -a .gitignore rm -rf",
|
|
25
|
-
"lint": "eslint lib
|
|
27
|
+
"lint": "eslint lib v1 draft-* openapi-* bundle annotations",
|
|
26
28
|
"test": "vitest --watch=false",
|
|
27
29
|
"check-types": "tsc --noEmit"
|
|
28
30
|
},
|
|
@@ -67,6 +69,7 @@
|
|
|
67
69
|
},
|
|
68
70
|
"dependencies": {
|
|
69
71
|
"@hyperjump/json-pointer": "^1.1.0",
|
|
72
|
+
"@hyperjump/json-schema-formats": "^1.0.0",
|
|
70
73
|
"@hyperjump/pact": "^1.2.0",
|
|
71
74
|
"@hyperjump/uri": "^1.2.0",
|
|
72
75
|
"content-type": "^1.0.4",
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"description": "if - then",
|
|
4
|
+
"schema": {
|
|
5
|
+
"conditional": [
|
|
6
|
+
{ "type": "string" },
|
|
7
|
+
{ "maxLength": 5 }
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"tests": [
|
|
11
|
+
{
|
|
12
|
+
"description": "if passes, then passes",
|
|
13
|
+
"data": "foo",
|
|
14
|
+
"valid": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"description": "if passes, then fails",
|
|
18
|
+
"data": "foobar",
|
|
19
|
+
"valid": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"description": "if fails",
|
|
23
|
+
"data": 42,
|
|
24
|
+
"valid": true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"description": "if - then - else",
|
|
30
|
+
"schema": {
|
|
31
|
+
"conditional": [
|
|
32
|
+
{ "type": "string" },
|
|
33
|
+
{ "maxLength": 5 },
|
|
34
|
+
{ "type": "number" }
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"tests": [
|
|
38
|
+
{
|
|
39
|
+
"description": "if passes, then passes",
|
|
40
|
+
"data": "foo",
|
|
41
|
+
"valid": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"description": "if passes, then fails",
|
|
45
|
+
"data": "foobar",
|
|
46
|
+
"valid": false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"description": "if fails, else passes",
|
|
50
|
+
"data": 42,
|
|
51
|
+
"valid": true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"description": "if fails, else fails",
|
|
55
|
+
"data": true,
|
|
56
|
+
"valid": false
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"description": "if - then - elseif - then",
|
|
62
|
+
"schema": {
|
|
63
|
+
"conditional": [
|
|
64
|
+
{ "type": "string" },
|
|
65
|
+
{ "maxLength": 5 },
|
|
66
|
+
{ "type": "number" },
|
|
67
|
+
{ "maximum": 50 }
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"tests": [
|
|
71
|
+
{
|
|
72
|
+
"description": "if passes, then passes",
|
|
73
|
+
"data": "foo",
|
|
74
|
+
"valid": true
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"description": "if passes, then fails",
|
|
78
|
+
"data": "foobar",
|
|
79
|
+
"valid": false
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"description": "if fails, elseif passes, then passes",
|
|
83
|
+
"data": 42,
|
|
84
|
+
"valid": true
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"description": "if fails, elseif passes, then fails",
|
|
88
|
+
"data": 100,
|
|
89
|
+
"valid": false
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"description": "if fails, elseif fails",
|
|
93
|
+
"data": true,
|
|
94
|
+
"valid": true
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"description": "if - then - elseif - then - else",
|
|
100
|
+
"schema": {
|
|
101
|
+
"conditional": [
|
|
102
|
+
{ "type": "string" },
|
|
103
|
+
{ "maxLength": 5 },
|
|
104
|
+
{ "type": "number" },
|
|
105
|
+
{ "maximum": 50 },
|
|
106
|
+
{ "const": true }
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
"tests": [
|
|
110
|
+
{
|
|
111
|
+
"description": "if passes, then passes",
|
|
112
|
+
"data": "foo",
|
|
113
|
+
"valid": true
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"description": "if passes, then fails",
|
|
117
|
+
"data": "foobar",
|
|
118
|
+
"valid": false
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"description": "if fails, elseif passes, then passes",
|
|
122
|
+
"data": 42,
|
|
123
|
+
"valid": true
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"description": "if fails, elseif passes, then fails",
|
|
127
|
+
"data": 100,
|
|
128
|
+
"valid": false
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"description": "if fails, elseif fails, else passes",
|
|
132
|
+
"data": true,
|
|
133
|
+
"valid": true
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"description": "if fails, elseif fails, else fails",
|
|
137
|
+
"data": false,
|
|
138
|
+
"valid": false
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"description": "nested if - then - elseif - then - else",
|
|
144
|
+
"schema": {
|
|
145
|
+
"conditional": [
|
|
146
|
+
[
|
|
147
|
+
{ "type": "string" },
|
|
148
|
+
{ "maxLength": 5 }
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
{ "type": "number" },
|
|
152
|
+
{ "maximum": 50 }
|
|
153
|
+
],
|
|
154
|
+
{ "const": true }
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
"tests": [
|
|
158
|
+
{
|
|
159
|
+
"description": "if passes, then passes",
|
|
160
|
+
"data": "foo",
|
|
161
|
+
"valid": true
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"description": "if passes, then fails",
|
|
165
|
+
"data": "foobar",
|
|
166
|
+
"valid": false
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"description": "if fails, elseif passes, then passes",
|
|
170
|
+
"data": 42,
|
|
171
|
+
"valid": true
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"description": "if fails, elseif passes, then fails",
|
|
175
|
+
"data": 100,
|
|
176
|
+
"valid": false
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"description": "if fails, elseif fails, else passes",
|
|
180
|
+
"data": true,
|
|
181
|
+
"valid": true
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"description": "if fails, elseif fails, else fails",
|
|
185
|
+
"data": false,
|
|
186
|
+
"valid": false
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"description": "if - then - else with unevaluatedProperties",
|
|
192
|
+
"schema": {
|
|
193
|
+
"allOf": [
|
|
194
|
+
{
|
|
195
|
+
"properties": {
|
|
196
|
+
"foo": {}
|
|
197
|
+
},
|
|
198
|
+
"conditional": [
|
|
199
|
+
{ "required": ["foo"] },
|
|
200
|
+
{
|
|
201
|
+
"properties": {
|
|
202
|
+
"bar": {}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"properties": {
|
|
207
|
+
"baz": {}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"unevaluatedProperties": false
|
|
214
|
+
},
|
|
215
|
+
"tests": [
|
|
216
|
+
{
|
|
217
|
+
"description": "if foo, then bar is allowed",
|
|
218
|
+
"data": { "foo": 42, "bar": true },
|
|
219
|
+
"valid": true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"description": "if foo, then baz is not allowed",
|
|
223
|
+
"data": { "foo": 42, "baz": true },
|
|
224
|
+
"valid": false
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"description": "if not foo, then baz is allowed",
|
|
228
|
+
"data": { "baz": true },
|
|
229
|
+
"valid": true
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"description": "if not foo, then bar is not allowed",
|
|
233
|
+
"data": { "bar": true },
|
|
234
|
+
"valid": false
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"description": "if - then - else with unevaluatedItems",
|
|
240
|
+
"schema": {
|
|
241
|
+
"allOf": [
|
|
242
|
+
{
|
|
243
|
+
"conditional": [
|
|
244
|
+
{ "prefixItems": [{ "const": "foo" }] },
|
|
245
|
+
{
|
|
246
|
+
"prefixItems": [{}, { "const": "bar" }]
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"prefixItems": [{}, { "const": "baz" }]
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"unevaluatedItems": false
|
|
255
|
+
},
|
|
256
|
+
"tests": [
|
|
257
|
+
{
|
|
258
|
+
"description": "foo, bar",
|
|
259
|
+
"data": ["foo", "bar"],
|
|
260
|
+
"valid": true
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"description": "foo, baz",
|
|
264
|
+
"data": ["foo", "baz"],
|
|
265
|
+
"valid": false
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"description": "foo, bar, additional",
|
|
269
|
+
"data": ["foo", "bar", ""],
|
|
270
|
+
"valid": false
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"description": "not-foo, baz",
|
|
274
|
+
"data": ["not-foo", "baz"],
|
|
275
|
+
"valid": true
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"description": "not-foo, bar",
|
|
279
|
+
"data": ["not-foo", "bar"],
|
|
280
|
+
"valid": false
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"description": "not-foo, baz, additional",
|
|
284
|
+
"data": ["not-foo", "baz", ""],
|
|
285
|
+
"valid": false
|
|
286
|
+
}
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
]
|