@hyperjump/json-schema 1.2.4 → 1.2.6
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/draft-04/additionalItems.js +10 -1
- package/lib/fetch.js +3 -2
- package/lib/keywords/items.js +12 -3
- package/lib/keywords/unevaluatedItems.js +12 -1
- package/lib/openapi.js +4 -2
- package/openapi-3-0/index.d.ts +11 -11
- package/openapi-3-0/schema/2021-09-28.js +4 -40
- package/openapi-3-1/index.d.ts +11 -11
- package/package.json +1 -1
|
@@ -23,7 +23,16 @@ const interpret = ([numberOfItems, additionalItems], instance, ast, dynamicAncho
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
26
|
-
|
|
26
|
+
if (!interpret(keywordValue, instance, ast, dynamicAnchors)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const evaluatedIndexes = new Set();
|
|
31
|
+
for (let ndx = keywordValue[0]; ndx < Instance.length(instance); ndx++) {
|
|
32
|
+
evaluatedIndexes.add(ndx);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return evaluatedIndexes;
|
|
27
36
|
};
|
|
28
37
|
|
|
29
38
|
export default { id, compile, interpret, collectEvaluatedItems };
|
package/lib/fetch.js
CHANGED
|
@@ -9,10 +9,11 @@ export default async (url, options) => {
|
|
|
9
9
|
const filePath = Url.fileURLToPath(url);
|
|
10
10
|
const fd = await fs.open(filePath);
|
|
11
11
|
const stream = fd.createReadStream();
|
|
12
|
-
|
|
13
|
-
url: url,
|
|
12
|
+
const response = new Response(stream, {
|
|
14
13
|
headers: { "Content-Type": MediaTypes.getContentType(filePath) }
|
|
15
14
|
});
|
|
15
|
+
Object.defineProperty(response, "url", { value: url });
|
|
16
|
+
return response;
|
|
16
17
|
} else {
|
|
17
18
|
return fetch(url, options);
|
|
18
19
|
}
|
package/lib/keywords/items.js
CHANGED
|
@@ -8,8 +8,8 @@ const id = "https://json-schema.org/keyword/items";
|
|
|
8
8
|
|
|
9
9
|
const compile = async (schema, ast, parentSchema) => {
|
|
10
10
|
const prefixItemKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/prefixItems");
|
|
11
|
-
const
|
|
12
|
-
const numberOfPrefixItems = Schema.typeOf(
|
|
11
|
+
const prefixItems = await Schema.step(prefixItemKeyword, parentSchema);
|
|
12
|
+
const numberOfPrefixItems = Schema.typeOf(prefixItems, "array") ? Schema.length(prefixItems) : 0;
|
|
13
13
|
|
|
14
14
|
return [numberOfPrefixItems, await Validation.compile(schema, ast)];
|
|
15
15
|
};
|
|
@@ -23,7 +23,16 @@ const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors)
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
26
|
-
|
|
26
|
+
if (!interpret(keywordValue, instance, ast, dynamicAnchors)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const evaluatedIndexes = new Set();
|
|
31
|
+
for (let ndx = keywordValue[0]; ndx < Instance.length(instance); ndx++) {
|
|
32
|
+
evaluatedIndexes.add(ndx);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return evaluatedIndexes;
|
|
27
36
|
};
|
|
28
37
|
|
|
29
38
|
export default { id, compile, interpret, collectEvaluatedItems };
|
|
@@ -21,7 +21,18 @@ const interpret = ([schemaUrl, unevaluatedItems], instance, ast, dynamicAnchors)
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
24
|
-
|
|
24
|
+
const itemIndexes = Validation.collectEvaluatedItems(keywordValue[0], instance, ast, dynamicAnchors, true);
|
|
25
|
+
if (!itemIndexes) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const evaluatedIndexes = new Set();
|
|
30
|
+
for (let ndx = 0; ndx < Instance.length(instance); ndx++) {
|
|
31
|
+
if (!itemIndexes.has(ndx)) {
|
|
32
|
+
evaluatedIndexes.add(ndx);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return evaluatedIndexes;
|
|
25
36
|
};
|
|
26
37
|
|
|
27
38
|
export default { id, compile, interpret, collectEvaluatedItems };
|
package/lib/openapi.js
CHANGED
|
@@ -11,7 +11,9 @@ addMediaTypePlugin("application/openapi+json", {
|
|
|
11
11
|
let defaultDialect;
|
|
12
12
|
const version = doc.openapi || contentTypeParameters.version;
|
|
13
13
|
|
|
14
|
-
if (
|
|
14
|
+
if (!version) {
|
|
15
|
+
throw Error("Invalid OpenAPI document. Add the 'openapi' field and try again.");
|
|
16
|
+
} else if (is30(version)) {
|
|
15
17
|
defaultDialect = "https://spec.openapis.org/oas/3.0/schema";
|
|
16
18
|
} else if (is31(version)) {
|
|
17
19
|
if (!("jsonSchemaDialect" in doc) || doc.jsonSchemaDialect === "https://spec.openapis.org/oas/3.1/dialect/base") {
|
|
@@ -20,7 +22,7 @@ addMediaTypePlugin("application/openapi+json", {
|
|
|
20
22
|
defaultDialect = `https://spec.openapis.org/oas/3.1/schema-${encodeURIComponent(doc.jsonSchemaDialect)}`;
|
|
21
23
|
}
|
|
22
24
|
} else {
|
|
23
|
-
throw Error(
|
|
25
|
+
throw Error(`Encountered unsupported OpenAPI version '${version}' in ${response.url}`);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
return [doc, defaultDialect];
|
package/openapi-3-0/index.d.ts
CHANGED
|
@@ -33,28 +33,28 @@ export type OasSchema30 = {
|
|
|
33
33
|
anyOf?: OasSchema30[];
|
|
34
34
|
oneOf?: OasSchema30[];
|
|
35
35
|
not?: OasSchema30;
|
|
36
|
-
example
|
|
37
|
-
discriminator
|
|
38
|
-
externalDocs
|
|
39
|
-
xml
|
|
36
|
+
example?: Json;
|
|
37
|
+
discriminator?: Discriminator;
|
|
38
|
+
externalDocs?: ExternalDocs;
|
|
39
|
+
xml?: Xml;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
type Discriminator = {
|
|
43
43
|
propertyName: string;
|
|
44
|
-
mappings
|
|
44
|
+
mappings?: Record<string, string>;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
type ExternalDocs = {
|
|
48
48
|
url: string;
|
|
49
|
-
description
|
|
49
|
+
description?: string;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
type Xml = {
|
|
53
|
-
name
|
|
54
|
-
namespace
|
|
55
|
-
prefix
|
|
56
|
-
attribute
|
|
57
|
-
wrapped
|
|
53
|
+
name?: string;
|
|
54
|
+
namespace?: string;
|
|
55
|
+
prefix?: string;
|
|
56
|
+
attribute?: boolean;
|
|
57
|
+
wrapped?: boolean;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
export * from "../lib/index.js";
|
|
@@ -193,16 +193,7 @@ export default {
|
|
|
193
193
|
"schemas": {
|
|
194
194
|
"type": "object",
|
|
195
195
|
"patternProperties": {
|
|
196
|
-
"^[a-zA-Z0-9\\.\\-_]+$": {
|
|
197
|
-
"oneOf": [
|
|
198
|
-
{
|
|
199
|
-
"$ref": "#/definitions/Schema"
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
"$ref": "#/definitions/Reference"
|
|
203
|
-
}
|
|
204
|
-
]
|
|
205
|
-
}
|
|
196
|
+
"^[a-zA-Z0-9\\.\\-_]+$": { "$ref": "#/definitions/Schema" }
|
|
206
197
|
}
|
|
207
198
|
},
|
|
208
199
|
"responses": {
|
|
@@ -384,16 +375,7 @@ export default {
|
|
|
384
375
|
"MediaType": {
|
|
385
376
|
"type": "object",
|
|
386
377
|
"properties": {
|
|
387
|
-
"schema": {
|
|
388
|
-
"oneOf": [
|
|
389
|
-
{
|
|
390
|
-
"$ref": "#/definitions/Schema"
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
"$ref": "#/definitions/Reference"
|
|
394
|
-
}
|
|
395
|
-
]
|
|
396
|
-
},
|
|
378
|
+
"schema": { "$ref": "#/definitions/Schema" },
|
|
397
379
|
"example": {
|
|
398
380
|
},
|
|
399
381
|
"examples": {
|
|
@@ -481,16 +463,7 @@ export default {
|
|
|
481
463
|
"type": "boolean",
|
|
482
464
|
"default": false
|
|
483
465
|
},
|
|
484
|
-
"schema": {
|
|
485
|
-
"oneOf": [
|
|
486
|
-
{
|
|
487
|
-
"$ref": "#/definitions/Schema"
|
|
488
|
-
},
|
|
489
|
-
{
|
|
490
|
-
"$ref": "#/definitions/Reference"
|
|
491
|
-
}
|
|
492
|
-
]
|
|
493
|
-
},
|
|
466
|
+
"schema": { "$ref": "#/definitions/Schema" },
|
|
494
467
|
"content": {
|
|
495
468
|
"type": "object",
|
|
496
469
|
"additionalProperties": {
|
|
@@ -853,16 +826,7 @@ export default {
|
|
|
853
826
|
"type": "boolean",
|
|
854
827
|
"default": false
|
|
855
828
|
},
|
|
856
|
-
"schema": {
|
|
857
|
-
"oneOf": [
|
|
858
|
-
{
|
|
859
|
-
"$ref": "#/definitions/Schema"
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
"$ref": "#/definitions/Reference"
|
|
863
|
-
}
|
|
864
|
-
]
|
|
865
|
-
},
|
|
829
|
+
"schema": { "$ref": "#/definitions/Schema" },
|
|
866
830
|
"content": {
|
|
867
831
|
"type": "object",
|
|
868
832
|
"additionalProperties": {
|
package/openapi-3-1/index.d.ts
CHANGED
|
@@ -61,28 +61,28 @@ export type OasSchema31 = boolean | {
|
|
|
61
61
|
contentMediaType?: string;
|
|
62
62
|
contentEncoding?: string;
|
|
63
63
|
contentSchema?: OasSchema31;
|
|
64
|
-
example
|
|
65
|
-
discriminator
|
|
66
|
-
externalDocs
|
|
67
|
-
xml
|
|
64
|
+
example?: Json;
|
|
65
|
+
discriminator?: Discriminator;
|
|
66
|
+
externalDocs?: ExternalDocs;
|
|
67
|
+
xml?: Xml;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
type Discriminator = {
|
|
71
71
|
propertyName: string;
|
|
72
|
-
mappings
|
|
72
|
+
mappings?: Record<string, string>;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
type ExternalDocs = {
|
|
76
76
|
url: string;
|
|
77
|
-
description
|
|
77
|
+
description?: string;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
type Xml = {
|
|
81
|
-
name
|
|
82
|
-
namespace
|
|
83
|
-
prefix
|
|
84
|
-
attribute
|
|
85
|
-
wrapped
|
|
81
|
+
name?: string;
|
|
82
|
+
namespace?: string;
|
|
83
|
+
prefix?: string;
|
|
84
|
+
attribute?: boolean;
|
|
85
|
+
wrapped?: boolean;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
export * from "../lib/index.js";
|