json-schema-library 7.4.4 → 7.4.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.
@@ -21,52 +21,64 @@ import validate from "../validate";
21
21
  import { Draft } from "../draft";
22
22
  const draft07Config = {
23
23
  typeKeywords: {
24
- array: ["enum", "contains", "items", "minItems", "maxItems", "uniqueItems", "not", "if"],
25
- boolean: ["enum", "not"],
24
+ array: [
25
+ "allOf",
26
+ "anyOf",
27
+ "contains",
28
+ "enum",
29
+ "if",
30
+ "items",
31
+ "maxItems",
32
+ "minItems",
33
+ "not",
34
+ "oneOf",
35
+ "uniqueItems"
36
+ ],
37
+ boolean: ["allOf", "anyOf", "enum", "not", "oneOf"],
26
38
  object: [
27
39
  "additionalProperties",
40
+ "allOf",
41
+ "anyOf",
28
42
  "dependencies",
29
43
  "enum",
30
44
  "format",
31
- "minProperties",
45
+ "if",
32
46
  "maxProperties",
47
+ "minProperties",
48
+ "not",
49
+ "oneOf",
33
50
  "patternProperties",
34
51
  "properties",
35
52
  "propertyNames",
36
- "required",
37
- "not",
38
- "oneOf",
39
- "allOf",
40
- "anyOf",
41
- "if"
53
+ "required"
42
54
  ],
43
55
  string: [
56
+ "allOf",
57
+ "anyOf",
44
58
  "enum",
45
59
  "format",
60
+ "if",
46
61
  "maxLength",
47
62
  "minLength",
48
- "pattern",
49
63
  "not",
50
64
  "oneOf",
51
- "allOf",
52
- "anyOf",
53
- "if"
65
+ "pattern"
54
66
  ],
55
67
  number: [
68
+ "allOf",
69
+ "anyOf",
56
70
  "enum",
57
71
  "exclusiveMaximum",
58
72
  "exclusiveMinimum",
59
73
  "format",
74
+ "if",
60
75
  "maximum",
61
76
  "minimum",
62
77
  "multipleOf",
63
78
  "not",
64
- "oneOf",
65
- "allOf",
66
- "anyOf",
67
- "if"
79
+ "oneOf"
68
80
  ],
69
- null: ["enum", "format", "not", "oneOf", "allOf", "anyOf"]
81
+ null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"]
70
82
  },
71
83
  validateKeyword: KEYWORDS,
72
84
  validateType: TYPES,
@@ -154,7 +154,8 @@ function getTemplate(core, data, _schema, pointer, opts) {
154
154
  ? selectType(schema.type, data, schema.default)
155
155
  : schema.type;
156
156
  // reset invalid type
157
- if (data != null && getTypeOf(data) !== type) {
157
+ const dataType = getTypeOf(data);
158
+ if (data != null && dataType !== type && !(dataType === "number" && type === "integer")) {
158
159
  data = convertValue(type, data);
159
160
  }
160
161
  if (TYPE[type] == null) {
@@ -23,7 +23,7 @@ function getJsonSchemaType(value, expectedType) {
23
23
  */
24
24
  export default function validate(core, value, schema = core.rootSchema, pointer = "#") {
25
25
  schema = core.resolveRef(schema);
26
- // this is a high level v7 schema validation
26
+ // @draft >= 07
27
27
  if (getTypeOf(schema) === "boolean") {
28
28
  if (schema) {
29
29
  return [];
@@ -23,8 +23,18 @@ import { JSONSchema } from "../types";
23
23
 
24
24
  const draft04Config: DraftConfig = {
25
25
  typeKeywords: {
26
- array: ["enum", "items", "minItems", "maxItems", "uniqueItems", "not"],
27
- boolean: ["enum", "not"],
26
+ array: [
27
+ "allOf",
28
+ "anyOf",
29
+ "enum",
30
+ "items",
31
+ "maxItems",
32
+ "minItems",
33
+ "not",
34
+ "oneOf",
35
+ "uniqueItems"
36
+ ],
37
+ boolean: ["enum", "not", "allOf", "anyOf", "oneOf"],
28
38
  object: [
29
39
  "additionalProperties",
30
40
  "dependencies",
@@ -41,28 +51,28 @@ const draft04Config: DraftConfig = {
41
51
  "anyOf"
42
52
  ],
43
53
  string: [
54
+ "allOf",
55
+ "anyOf",
44
56
  "enum",
45
57
  "format",
46
58
  "maxLength",
47
59
  "minLength",
48
- "pattern",
49
60
  "not",
50
61
  "oneOf",
51
- "allOf",
52
- "anyOf"
62
+ "pattern"
53
63
  ],
54
64
  number: [
65
+ "allOf",
66
+ "anyOf",
55
67
  "enum",
56
68
  "format",
57
69
  "maximum",
58
70
  "minimum",
59
71
  "multipleOf",
60
72
  "not",
61
- "oneOf",
62
- "allOf",
63
- "anyOf"
73
+ "oneOf"
64
74
  ],
65
- null: ["enum", "format", "not", "oneOf", "allOf", "anyOf"]
75
+ null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"]
66
76
  },
67
77
  validateKeyword: KEYWORDS,
68
78
  validateType: TYPES,
@@ -23,36 +23,48 @@ import { JSONSchema } from "../types";
23
23
 
24
24
  const draft06Config: DraftConfig = {
25
25
  typeKeywords: {
26
- array: ["enum", "contains", "items", "minItems", "maxItems", "uniqueItems", "not", "if"],
27
- boolean: ["enum", "not"],
26
+ array: [
27
+ "allOf",
28
+ "anyOf",
29
+ "contains",
30
+ "enum",
31
+ "if",
32
+ "items",
33
+ "maxItems",
34
+ "minItems",
35
+ "not",
36
+ "oneOf",
37
+ "uniqueItems"
38
+ ],
39
+ boolean: ["allOf", "anyOf", "enum", "not", "oneOf"],
28
40
  object: [
29
41
  "additionalProperties",
42
+ "allOf",
43
+ "anyOf",
30
44
  "dependencies",
31
45
  "enum",
32
46
  "format",
33
- "minProperties",
47
+ "if",
34
48
  "maxProperties",
49
+ "minProperties",
50
+ "not",
51
+ "oneOf",
35
52
  "patternProperties",
36
53
  "properties",
37
54
  "propertyNames",
38
- "required",
39
- "not",
40
- "oneOf",
41
- "allOf",
42
- "anyOf",
43
- "if"
55
+ "required"
44
56
  ],
45
57
  string: [
58
+ "allOf",
59
+ "anyOf",
46
60
  "enum",
47
61
  "format",
62
+ "if",
48
63
  "maxLength",
49
64
  "minLength",
50
- "pattern",
51
65
  "not",
52
66
  "oneOf",
53
- "allOf",
54
- "anyOf",
55
- "if"
67
+ "pattern"
56
68
  ],
57
69
  number: [
58
70
  "enum",
@@ -68,7 +80,7 @@ const draft06Config: DraftConfig = {
68
80
  "anyOf",
69
81
  "if"
70
82
  ],
71
- null: ["enum", "format", "not", "oneOf", "allOf", "anyOf"]
83
+ null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"]
72
84
  },
73
85
  validateKeyword: KEYWORDS,
74
86
  validateType: TYPES,
@@ -23,52 +23,64 @@ import { JSONSchema } from "../types";
23
23
 
24
24
  const draft07Config: DraftConfig = {
25
25
  typeKeywords: {
26
- array: ["enum", "contains", "items", "minItems", "maxItems", "uniqueItems", "not", "if"],
27
- boolean: ["enum", "not"],
26
+ array: [
27
+ "allOf",
28
+ "anyOf",
29
+ "contains",
30
+ "enum",
31
+ "if",
32
+ "items",
33
+ "maxItems",
34
+ "minItems",
35
+ "not",
36
+ "oneOf",
37
+ "uniqueItems"
38
+ ],
39
+ boolean: ["allOf", "anyOf", "enum", "not", "oneOf"],
28
40
  object: [
29
41
  "additionalProperties",
42
+ "allOf",
43
+ "anyOf",
30
44
  "dependencies",
31
45
  "enum",
32
46
  "format",
33
- "minProperties",
47
+ "if",
34
48
  "maxProperties",
49
+ "minProperties",
50
+ "not",
51
+ "oneOf",
35
52
  "patternProperties",
36
53
  "properties",
37
54
  "propertyNames",
38
- "required",
39
- "not",
40
- "oneOf",
41
- "allOf",
42
- "anyOf",
43
- "if"
55
+ "required"
44
56
  ],
45
57
  string: [
58
+ "allOf",
59
+ "anyOf",
46
60
  "enum",
47
61
  "format",
62
+ "if",
48
63
  "maxLength",
49
64
  "minLength",
50
- "pattern",
51
65
  "not",
52
66
  "oneOf",
53
- "allOf",
54
- "anyOf",
55
- "if"
67
+ "pattern"
56
68
  ],
57
69
  number: [
70
+ "allOf",
71
+ "anyOf",
58
72
  "enum",
59
73
  "exclusiveMaximum",
60
74
  "exclusiveMinimum",
61
75
  "format",
76
+ "if",
62
77
  "maximum",
63
78
  "minimum",
64
79
  "multipleOf",
65
80
  "not",
66
- "oneOf",
67
- "allOf",
68
- "anyOf",
69
- "if"
81
+ "oneOf"
70
82
  ],
71
- null: ["enum", "format", "not", "oneOf", "allOf", "anyOf"]
83
+ null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"]
72
84
  },
73
85
  validateKeyword: KEYWORDS,
74
86
  validateType: TYPES,
@@ -195,7 +195,8 @@ function getTemplate(
195
195
  : schema.type;
196
196
 
197
197
  // reset invalid type
198
- if (data != null && getTypeOf(data) !== type) {
198
+ const dataType = getTypeOf(data);
199
+ if (data != null && dataType !== type && !(dataType === "number" && type === "integer")) {
199
200
  data = convertValue(type, data);
200
201
  }
201
202
 
package/lib/validate.ts CHANGED
@@ -34,7 +34,7 @@ export default function validate(
34
34
  ): Array<JSONError> {
35
35
  schema = core.resolveRef(schema);
36
36
 
37
- // this is a high level v7 schema validation
37
+ // @draft >= 07
38
38
  if (getTypeOf(schema) === "boolean") {
39
39
  if (schema) {
40
40
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-schema-library",
3
- "version": "7.4.4",
3
+ "version": "7.4.6",
4
4
  "description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation",
5
5
  "module": "dist/module/index.js",
6
6
  "types": "dist/index.d.ts",