Skip to content

Commit d514df2

Browse files
committed
draft: add all supported drafts (and next) to samples
1 parent e19e893 commit d514df2

File tree

185 files changed

+40053
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+40053
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ See [Error handling](./doc/Error-handling.md) for more information.
198198
## Generate Modules
199199

200200
See the [doc/samples](./doc/samples/) directory to see how `@exodus/schemasafe` compiles
201-
`draft/2019-09` and `draft/2020-12` test suites.
201+
supported test suites.
202202

203203
To compile a validator function to an IIFE, call `validate.toModule()`:
204204

doc/samples/draft-next/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Samples
2+
3+
Based on JSON Schema Test Suite for `draft-next`.
4+
5+
6+
### Disambiguation
7+
8+
* **Failed to compile** — schemas that did not compile in any mode.
9+
10+
* **Warnings** — schemas that did not compile in the `default` mode, but compiled in `lax`
11+
mode.
12+
13+
JSON Schema spec allows usage of ineffective or unknown keywords, which is considered a mistake
14+
by `@exodus/schemasafe` by default. `lax` mode lifts that coherence check.
15+
16+
* **Misclassified** — schemas that classified at least one test value incorrectly, i.e. gave
17+
`true` where testsuite expected `false` or vice versa.
18+
19+
## Results
20+
21+
| Name | Total | Failed to compile | Warnings | Misclassified |
22+
|---------------------------------------------------------------------------------|-------|-------------------|----------|---------------|
23+
| [additionalProperties](./additionalProperties.md) | 7 | - | - | - |
24+
| [allOf](./allOf.md) | 12 | - | - | - |
25+
| [anchor](./anchor.md) | 7 | - | - | - |
26+
| [anyOf](./anyOf.md) | 8 | - | 3 | - |
27+
| [boolean_schema](./boolean_schema.md) | 2 | - | - | - |
28+
| [const](./const.md) | 15 | - | - | - |
29+
| [contains](./contains.md) | 7 | - | - | 6 |
30+
| [content](./content.md) | 4 | - | 4 | - |
31+
| [default](./default.md) | 3 | - | - | - |
32+
| [defs](./defs.md) | 1 | - | - | - |
33+
| [dependentRequired](./dependentRequired.md) | 4 | - | - | - |
34+
| [dependentSchemas](./dependentSchemas.md) | 3 | - | - | - |
35+
| [dynamicRef](./dynamicRef.md) | 12 | 2 | - | - |
36+
| [enum](./enum.md) | 10 | - | - | - |
37+
| [exclusiveMaximum](./exclusiveMaximum.md) | 1 | - | - | - |
38+
| [exclusiveMinimum](./exclusiveMinimum.md) | 1 | - | - | - |
39+
| [format](./format.md) | 19 | 4 | - | - |
40+
| [id](./id.md) | 5 | - | - | - |
41+
| [if-then-else](./if-then-else.md) | 10 | - | 6 | - |
42+
| [infinite-loop-detection](./infinite-loop-detection.md) | 1 | - | - | - |
43+
| [items](./items.md) | 9 | - | - | - |
44+
| [maxContains](./maxContains.md) | 4 | - | 1 | 2 |
45+
| [maxItems](./maxItems.md) | 2 | - | - | - |
46+
| [maxLength](./maxLength.md) | 2 | - | - | - |
47+
| [maxProperties](./maxProperties.md) | 3 | - | - | - |
48+
| [maximum](./maximum.md) | 2 | - | - | - |
49+
| [minContains](./minContains.md) | 8 | - | 2 | - |
50+
| [minItems](./minItems.md) | 2 | - | - | - |
51+
| [minLength](./minLength.md) | 2 | - | - | - |
52+
| [minProperties](./minProperties.md) | 2 | - | - | - |
53+
| [minimum](./minimum.md) | 2 | - | - | - |
54+
| [multipleOf](./multipleOf.md) | 4 | - | - | - |
55+
| [not](./not.md) | 6 | - | 1 | - |
56+
| [oneOf](./oneOf.md) | 11 | - | 3 | - |
57+
| [pattern](./pattern.md) | 2 | - | - | - |
58+
| [patternProperties](./patternProperties.md) | 5 | - | - | - |
59+
| [prefixItems](./prefixItems.md) | 4 | - | - | - |
60+
| [properties](./properties.md) | 6 | - | - | - |
61+
| [propertyDependencies](./propertyDependencies.md) | 3 | - | 3 | 1 |
62+
| [propertyNames](./propertyNames.md) | 3 | - | - | - |
63+
| [ref](./ref.md) | 29 | - | - | - |
64+
| [refRemote](./refRemote.md) | 13 | - | - | - |
65+
| [required](./required.md) | 5 | - | - | - |
66+
| [type](./type.md) | 11 | - | - | - |
67+
| [unevaluatedItems](./unevaluatedItems.md) | 23 | - | 2 | - |
68+
| [unevaluatedProperties](./unevaluatedProperties.md) | 36 | - | 3 | 2 |
69+
| [uniqueItems](./uniqueItems.md) | 6 | - | - | - |
70+
| [unknownKeyword](./unknownKeyword.md) | 1 | - | 1 | - |
71+
| [vocabulary](./vocabulary.md) | 1 | 1 | - | - |
72+
| [optional/bignum](./optional-bignum.md) | 7 | - | - | - |
73+
| [optional/dependencies-compatibility](./optional-dependencies-compatibility.md) | 7 | - | - | - |
74+
| [optional/ecmascript-regex](./optional-ecmascript-regex.md) | 21 | - | - | - |
75+
| [optional/float-overflow](./optional-float-overflow.md) | 1 | - | - | - |
76+
| [optional/format-assertion](./optional-format-assertion.md) | 2 | 2 | - | - |
77+
| [optional/non-bmp-regex](./optional-non-bmp-regex.md) | 2 | - | - | - |
78+
| [optional/refOfUnknownKeyword](./optional-refOfUnknownKeyword.md) | 2 | - | 2 | - |
79+
80+
### Notes
81+
82+
`{ isJSON: true }` option is used for better clarity, and that also corresponds to the main
83+
expected usage pattern of this module. Without it, there would be additional checks for
84+
`!== undefined`, which can be fast-tracked if we know that the input came from `JSON.parse()`.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# additionalProperties
2+
3+
## additionalProperties being false does not allow other properties
4+
5+
### Schema
6+
7+
```json
8+
{
9+
"properties": { "foo": {}, "bar": {} },
10+
"patternProperties": { "^v": {} },
11+
"additionalProperties": false
12+
}
13+
```
14+
15+
### Code
16+
17+
```js
18+
'use strict'
19+
const ref0 = function validate(data) {
20+
if (typeof data === "object" && data && !Array.isArray(data)) {
21+
for (const key1 of Object.keys(data)) {
22+
if (key1 !== "foo" && key1 !== "bar" && !(key1.startsWith("v"))) return false
23+
}
24+
}
25+
return true
26+
};
27+
return ref0
28+
```
29+
30+
##### Strong mode notices
31+
32+
* `[requireValidation] empty rules node is not allowed at #/properties/foo`
33+
34+
35+
## non-ASCII pattern with additionalProperties
36+
37+
### Schema
38+
39+
```json
40+
{ "patternProperties": { "^á": {} }, "additionalProperties": false }
41+
```
42+
43+
### Code
44+
45+
```js
46+
'use strict'
47+
const ref0 = function validate(data) {
48+
if (typeof data === "object" && data && !Array.isArray(data)) {
49+
for (const key1 of Object.keys(data)) {
50+
if (!(key1.startsWith("á"))) return false
51+
}
52+
}
53+
return true
54+
};
55+
return ref0
56+
```
57+
58+
##### Strong mode notices
59+
60+
* `Should start with ^ and end with $: "^á" at #`
61+
62+
63+
## additionalProperties with schema
64+
65+
### Schema
66+
67+
```json
68+
{
69+
"properties": { "foo": {}, "bar": {} },
70+
"additionalProperties": { "type": "boolean" }
71+
}
72+
```
73+
74+
### Code
75+
76+
```js
77+
'use strict'
78+
const ref0 = function validate(data) {
79+
if (typeof data === "object" && data && !Array.isArray(data)) {
80+
for (const key0 of Object.keys(data)) {
81+
if (key0 !== "foo" && key0 !== "bar") {
82+
if (!(typeof data[key0] === "boolean")) return false
83+
}
84+
}
85+
}
86+
return true
87+
};
88+
return ref0
89+
```
90+
91+
##### Strong mode notices
92+
93+
* `[requireValidation] empty rules node is not allowed at #/properties/foo`
94+
95+
96+
## additionalProperties can exist by itself
97+
98+
### Schema
99+
100+
```json
101+
{ "additionalProperties": { "type": "boolean" } }
102+
```
103+
104+
### Code
105+
106+
```js
107+
'use strict'
108+
const ref0 = function validate(data) {
109+
if (typeof data === "object" && data && !Array.isArray(data)) {
110+
for (const key0 of Object.keys(data)) {
111+
if (!(typeof data[key0] === "boolean")) return false
112+
}
113+
}
114+
return true
115+
};
116+
return ref0
117+
```
118+
119+
##### Strong mode notices
120+
121+
* `[requireValidation] type should be specified at #`
122+
123+
124+
## additionalProperties are allowed by default
125+
126+
### Schema
127+
128+
```json
129+
{ "properties": { "foo": {}, "bar": {} } }
130+
```
131+
132+
### Code
133+
134+
```js
135+
'use strict'
136+
const ref0 = function validate(data) {
137+
return true
138+
};
139+
return ref0
140+
```
141+
142+
##### Strong mode notices
143+
144+
* `[requireValidation] empty rules node is not allowed at #/properties/foo`
145+
146+
147+
## additionalProperties does not look in applicators
148+
149+
### Schema
150+
151+
```json
152+
{
153+
"allOf": [{ "properties": { "foo": {} } }],
154+
"additionalProperties": { "type": "boolean" }
155+
}
156+
```
157+
158+
### Code
159+
160+
```js
161+
'use strict'
162+
const ref0 = function validate(data) {
163+
if (typeof data === "object" && data && !Array.isArray(data)) {
164+
for (const key0 of Object.keys(data)) {
165+
if (!(typeof data[key0] === "boolean")) return false
166+
}
167+
}
168+
return true
169+
};
170+
return ref0
171+
```
172+
173+
##### Strong mode notices
174+
175+
* `[requireValidation] empty rules node is not allowed at #/allOf/0/properties/foo`
176+
177+
178+
## additionalProperties with null valued instance properties
179+
180+
### Schema
181+
182+
```json
183+
{ "additionalProperties": { "type": "null" } }
184+
```
185+
186+
### Code
187+
188+
```js
189+
'use strict'
190+
const ref0 = function validate(data) {
191+
if (typeof data === "object" && data && !Array.isArray(data)) {
192+
for (const key0 of Object.keys(data)) {
193+
if (!(data[key0] === null)) return false
194+
}
195+
}
196+
return true
197+
};
198+
return ref0
199+
```
200+
201+
##### Strong mode notices
202+
203+
* `[requireValidation] type should be specified at #`
204+

0 commit comments

Comments
 (0)