json-schema-library 11.5.0 → 11.5.1
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 +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/jlib.js +2 -2
- package/package.json +1 -1
- package/src/compileSchema.ts +3 -0
- package/src/keywords/unevaluatedProperties.test.ts +57 -0
- package/src/keywords/unevaluatedProperties.ts +7 -0
- package/src/settings.ts +2 -2
package/package.json
CHANGED
package/src/compileSchema.ts
CHANGED
|
@@ -67,6 +67,9 @@ export type CompileOptions = {
|
|
|
67
67
|
* Set node and its remote schemata as remote schemata for this node and schema to resolve $ref
|
|
68
68
|
*/
|
|
69
69
|
remote?: SchemaNode;
|
|
70
|
+
/**
|
|
71
|
+
* a list of remotes to add, requires a unique $id for each schema. Will be ignored if `remote` is set
|
|
72
|
+
*/
|
|
70
73
|
remotes?: JsonSchema[];
|
|
71
74
|
/**
|
|
72
75
|
* Enables `format`-keyword assertions when this is set tor `true` or sets assertion as defined by
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compileSchema } from "../compileSchema";
|
|
2
|
+
import { draft2020 } from "../draft2020";
|
|
2
3
|
import { strict as assert } from "assert";
|
|
3
4
|
|
|
4
5
|
describe("keyword : unevaluatedProperties : validation", () => {
|
|
@@ -13,4 +14,60 @@ describe("keyword : unevaluatedProperties : validation", () => {
|
|
|
13
14
|
});
|
|
14
15
|
assert.equal(errors.length, 0);
|
|
15
16
|
});
|
|
17
|
+
|
|
18
|
+
it("should not return unevaluated-property-error for a property that fails format validation", () => {
|
|
19
|
+
const node = compileSchema(
|
|
20
|
+
{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
name: { type: "string" },
|
|
24
|
+
email: { type: "string", format: "email" }
|
|
25
|
+
},
|
|
26
|
+
unevaluatedProperties: false
|
|
27
|
+
},
|
|
28
|
+
{ drafts: [draft2020] }
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const { errors } = node.validate({ name: "Alice", email: "not-an-email" });
|
|
32
|
+
|
|
33
|
+
const unevaluatedErrors = errors.filter((e) => e.code === "unevaluated-property-error");
|
|
34
|
+
assert.equal(unevaluatedErrors.length, 0, "should not flag email as unevaluated");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should not return unevaluated-property-error for a property that fails type validation", () => {
|
|
38
|
+
const node = compileSchema(
|
|
39
|
+
{
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
name: { type: "string" },
|
|
43
|
+
age: { type: "number" }
|
|
44
|
+
},
|
|
45
|
+
unevaluatedProperties: false
|
|
46
|
+
},
|
|
47
|
+
{ drafts: [draft2020] }
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const { errors } = node.validate({ name: "Alice", age: "not-a-number" });
|
|
51
|
+
|
|
52
|
+
const unevaluatedErrors = errors.filter((e) => e.code === "unevaluated-property-error");
|
|
53
|
+
assert.equal(unevaluatedErrors.length, 0, "should not flag age as unevaluated");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should still return unevaluated-property-error for truly unknown properties", () => {
|
|
57
|
+
const node = compileSchema(
|
|
58
|
+
{
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
name: { type: "string" }
|
|
62
|
+
},
|
|
63
|
+
unevaluatedProperties: false
|
|
64
|
+
},
|
|
65
|
+
{ drafts: [draft2020] }
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const { errors } = node.validate({ name: "Alice", unknown: "value" });
|
|
69
|
+
|
|
70
|
+
const unevaluatedErrors = errors.filter((e) => e.code === "unevaluated-property-error");
|
|
71
|
+
assert.equal(unevaluatedErrors.length, 1, "should flag unknown as unevaluated");
|
|
72
|
+
});
|
|
16
73
|
});
|
|
@@ -56,6 +56,13 @@ function validateUnevaluatedProperties({ node, data, pointer, path }: JsonSchema
|
|
|
56
56
|
|
|
57
57
|
const errors: ValidationReturnType = [];
|
|
58
58
|
for (const propertyName of unevaluated) {
|
|
59
|
+
// Properties defined directly on this schema object are always
|
|
60
|
+
// evaluated by the "properties" keyword, regardless of whether the
|
|
61
|
+
// value passes validation (per JSON Schema spec, annotations from
|
|
62
|
+
// adjacent keywords are always collected)
|
|
63
|
+
if (node.properties?.[propertyName]) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
59
66
|
if (isPropertyEvaluated({ node, data, key: propertyName, pointer, path })) {
|
|
60
67
|
continue;
|
|
61
68
|
}
|
package/src/settings.ts
CHANGED
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
],
|
|
20
20
|
REGEX_FLAGS: "u",
|
|
21
21
|
/** additional keywords that should not produce an unknown-keyword-warning */
|
|
22
|
-
VALID_ANNOTATION_KEYWORDS: ["title", "description", "default"],
|
|
22
|
+
VALID_ANNOTATION_KEYWORDS: ["$id", "$schema", "title", "description", "default", "oneOfProperty"],
|
|
23
23
|
/**
|
|
24
24
|
* properties to keep from a $ref-schema when resolving a $ref (recursively)
|
|
25
25
|
* this allows to overwrite specified properties locally on a $ref-definition
|
|
@@ -45,5 +45,5 @@ export default {
|
|
|
45
45
|
* type: "object"
|
|
46
46
|
* }
|
|
47
47
|
*/
|
|
48
|
-
PROPERTIES_TO_MERGE: ["title", "description", "options", "x-options", "readOnly", "writeOnly"]
|
|
48
|
+
PROPERTIES_TO_MERGE: ["title", "description", "default", "options", "x-options", "readOnly", "writeOnly"]
|
|
49
49
|
};
|