json-schema-library 10.5.4 → 11.0.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.
Files changed (39) hide show
  1. package/README.md +128 -14
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.cts +42 -19
  4. package/dist/index.d.mts +42 -19
  5. package/dist/index.mjs +1 -1
  6. package/dist/jlib.js +2 -2
  7. package/index.ts +8 -4
  8. package/package.json +6 -6
  9. package/src/Keyword.ts +8 -3
  10. package/src/SchemaNode.ts +46 -10
  11. package/src/compileSchema.validate.test.ts +89 -54
  12. package/src/draft04.ts +10 -8
  13. package/src/draft06.ts +10 -8
  14. package/src/draft07.ts +10 -8
  15. package/src/draft2019-09/keywords/additionalItems.ts +2 -2
  16. package/src/draft2019-09/keywords/items.ts +2 -2
  17. package/src/draft2019-09/keywords/unevaluatedItems.ts +12 -6
  18. package/src/draft2019.ts +10 -8
  19. package/src/draft2020.ts +8 -6
  20. package/src/errors/errors.ts +3 -1
  21. package/src/formats/formats.ts +2 -6
  22. package/src/keywords/additionalProperties.ts +2 -2
  23. package/src/keywords/allOf.ts +2 -2
  24. package/src/keywords/dependencies.ts +5 -6
  25. package/src/keywords/dependentRequired.ts +2 -2
  26. package/src/keywords/dependentSchemas.ts +4 -3
  27. package/src/keywords/deprecated.ts +18 -0
  28. package/src/keywords/items.ts +2 -2
  29. package/src/keywords/oneOf.test.ts +150 -15
  30. package/src/keywords/oneOf.ts +64 -4
  31. package/src/keywords/patternProperties.ts +2 -2
  32. package/src/keywords/prefixItems.ts +2 -11
  33. package/src/keywords/properties.ts +2 -2
  34. package/src/keywords/unevaluatedItems.ts +2 -2
  35. package/src/keywords/unevaluatedProperties.ts +2 -2
  36. package/src/methods/getData.test.ts +1779 -1781
  37. package/src/types.ts +32 -18
  38. package/src/utils/sanitizeErrors.ts +9 -8
  39. package/src/validateNode.ts +2 -2
@@ -6,7 +6,7 @@ import {
6
6
  JsonSchemaReducerParams,
7
7
  JsonSchemaResolverParams,
8
8
  JsonSchemaValidatorParams,
9
- ValidationResult
9
+ ValidationReturnType
10
10
  } from "../Keyword";
11
11
  import { getValue } from "../utils/getValue";
12
12
  import { validateNode } from "../validateNode";
@@ -96,7 +96,7 @@ function validatePatternProperties({ node, data, pointer, path }: JsonSchemaVali
96
96
  const { schema, patternProperties } = node;
97
97
  const properties = schema.properties || {};
98
98
  const patterns = Object.keys(schema.patternProperties).join(",");
99
- const errors: ValidationResult[] = [];
99
+ const errors: ValidationReturnType = [];
100
100
  const keys = Object.keys(data);
101
101
 
102
102
  keys.forEach((key) => {
@@ -1,5 +1,5 @@
1
1
  import { SchemaNode } from "../types";
2
- import { Keyword, JsonSchemaResolverParams, JsonSchemaValidatorParams, ValidationResult } from "../Keyword";
2
+ import { Keyword, JsonSchemaResolverParams, JsonSchemaValidatorParams, ValidationReturnType } from "../Keyword";
3
3
  import { validateNode } from "../validateNode";
4
4
 
5
5
  export const prefixItemsKeyword: Keyword = {
@@ -32,20 +32,11 @@ export function parseItems(node: SchemaNode) {
32
32
  }
33
33
 
34
34
  function validatePrefixItems({ node, data, pointer = "#", path }: JsonSchemaValidatorParams) {
35
- // const { schema } = node;
36
35
  if (!Array.isArray(data) || data.length === 0) {
37
36
  return;
38
37
  }
39
38
 
40
- // @draft >= 7 bool schema
41
- // if (schema.items === false) {
42
- // if (Array.isArray(data) && data.length === 0) {
43
- // return undefined;
44
- // }
45
- // return node.createError("InvalidDataError", { pointer, value: data, schema });
46
- // }
47
-
48
- const errors: ValidationResult[] = [];
39
+ const errors: ValidationReturnType = [];
49
40
  if (node.prefixItems) {
50
41
  // note: schema is valid when data does not have enough elements as defined by array-list
51
42
  for (let i = 0; i < Math.min(node.prefixItems.length, data.length); i += 1) {
@@ -1,6 +1,6 @@
1
1
  import { getValue } from "../utils/getValue";
2
2
  import { SchemaNode } from "../types";
3
- import { Keyword, JsonSchemaResolverParams, JsonSchemaValidatorParams, ValidationResult } from "../Keyword";
3
+ import { Keyword, JsonSchemaResolverParams, JsonSchemaValidatorParams, ValidationReturnType } from "../Keyword";
4
4
  import { isObject } from "../utils/isObject";
5
5
  import { validateNode } from "../validateNode";
6
6
 
@@ -39,7 +39,7 @@ function validateProperties({ node, data, pointer, path }: JsonSchemaValidatorPa
39
39
  return;
40
40
  }
41
41
  // move validation through properties
42
- const errors: ValidationResult[] = [];
42
+ const errors: ValidationReturnType = [];
43
43
  const properties = node.properties ?? {};
44
44
  Object.keys(data).forEach((propertyName) => {
45
45
  const value = getValue(data, propertyName);
@@ -1,6 +1,6 @@
1
1
  import { isObject } from "../utils/isObject";
2
2
  import { SchemaNode } from "../types";
3
- import { Keyword, JsonSchemaValidatorParams, ValidationResult } from "../Keyword";
3
+ import { Keyword, JsonSchemaValidatorParams, ValidationReturnType } from "../Keyword";
4
4
  import { validateNode } from "../validateNode";
5
5
  import { isItemEvaluated } from "../isItemEvaluated";
6
6
 
@@ -40,7 +40,7 @@ function validateUnevaluatedItems({ node, data, pointer, path }: JsonSchemaValid
40
40
  return undefined;
41
41
  }
42
42
 
43
- const errors: ValidationResult[] = [];
43
+ const errors: ValidationReturnType = [];
44
44
  // "unevaluatedItems with nested items"
45
45
  for (let i = 0; i < data.length; i += 1) {
46
46
  if (isItemEvaluated({ node, data, pointer, key: i, path })) {
@@ -1,6 +1,6 @@
1
1
  import { isObject } from "../utils/isObject";
2
2
  import { SchemaNode } from "../types";
3
- import { Keyword, JsonSchemaValidatorParams, ValidationResult } from "../Keyword";
3
+ import { Keyword, JsonSchemaValidatorParams, ValidationReturnType } from "../Keyword";
4
4
  import { validateNode } from "../validateNode";
5
5
  import { isPropertyEvaluated } from "../isPropertyEvaluated";
6
6
 
@@ -37,7 +37,7 @@ function validateUnevaluatedProperties({ node, data, pointer, path }: JsonSchema
37
37
  return undefined;
38
38
  }
39
39
 
40
- const errors: ValidationResult[] = [];
40
+ const errors: ValidationReturnType = [];
41
41
  for (const propertyName of unevaluated) {
42
42
  if (isPropertyEvaluated({ node, data, key: propertyName, pointer, path })) {
43
43
  continue;