Skip to content

Commit

Permalink
draft: add all supported drafts (and next) to samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Oct 6, 2022
1 parent e19e893 commit d514df2
Show file tree
Hide file tree
Showing 185 changed files with 40,053 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ See [Error handling](./doc/Error-handling.md) for more information.
## Generate Modules

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

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

Expand Down
84 changes: 84 additions & 0 deletions doc/samples/draft-next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Samples

Based on JSON Schema Test Suite for `draft-next`.


### Disambiguation

* **Failed to compile** — schemas that did not compile in any mode.

* **Warnings** — schemas that did not compile in the `default` mode, but compiled in `lax`
mode.

JSON Schema spec allows usage of ineffective or unknown keywords, which is considered a mistake
by `@exodus/schemasafe` by default. `lax` mode lifts that coherence check.

* **Misclassified** — schemas that classified at least one test value incorrectly, i.e. gave
`true` where testsuite expected `false` or vice versa.

## Results

| Name | Total | Failed to compile | Warnings | Misclassified |
|---------------------------------------------------------------------------------|-------|-------------------|----------|---------------|
| [additionalProperties](./additionalProperties.md) | 7 | - | - | - |
| [allOf](./allOf.md) | 12 | - | - | - |
| [anchor](./anchor.md) | 7 | - | - | - |
| [anyOf](./anyOf.md) | 8 | - | 3 | - |
| [boolean_schema](./boolean_schema.md) | 2 | - | - | - |
| [const](./const.md) | 15 | - | - | - |
| [contains](./contains.md) | 7 | - | - | 6 |
| [content](./content.md) | 4 | - | 4 | - |
| [default](./default.md) | 3 | - | - | - |
| [defs](./defs.md) | 1 | - | - | - |
| [dependentRequired](./dependentRequired.md) | 4 | - | - | - |
| [dependentSchemas](./dependentSchemas.md) | 3 | - | - | - |
| [dynamicRef](./dynamicRef.md) | 12 | 2 | - | - |
| [enum](./enum.md) | 10 | - | - | - |
| [exclusiveMaximum](./exclusiveMaximum.md) | 1 | - | - | - |
| [exclusiveMinimum](./exclusiveMinimum.md) | 1 | - | - | - |
| [format](./format.md) | 19 | 4 | - | - |
| [id](./id.md) | 5 | - | - | - |
| [if-then-else](./if-then-else.md) | 10 | - | 6 | - |
| [infinite-loop-detection](./infinite-loop-detection.md) | 1 | - | - | - |
| [items](./items.md) | 9 | - | - | - |
| [maxContains](./maxContains.md) | 4 | - | 1 | 2 |
| [maxItems](./maxItems.md) | 2 | - | - | - |
| [maxLength](./maxLength.md) | 2 | - | - | - |
| [maxProperties](./maxProperties.md) | 3 | - | - | - |
| [maximum](./maximum.md) | 2 | - | - | - |
| [minContains](./minContains.md) | 8 | - | 2 | - |
| [minItems](./minItems.md) | 2 | - | - | - |
| [minLength](./minLength.md) | 2 | - | - | - |
| [minProperties](./minProperties.md) | 2 | - | - | - |
| [minimum](./minimum.md) | 2 | - | - | - |
| [multipleOf](./multipleOf.md) | 4 | - | - | - |
| [not](./not.md) | 6 | - | 1 | - |
| [oneOf](./oneOf.md) | 11 | - | 3 | - |
| [pattern](./pattern.md) | 2 | - | - | - |
| [patternProperties](./patternProperties.md) | 5 | - | - | - |
| [prefixItems](./prefixItems.md) | 4 | - | - | - |
| [properties](./properties.md) | 6 | - | - | - |
| [propertyDependencies](./propertyDependencies.md) | 3 | - | 3 | 1 |
| [propertyNames](./propertyNames.md) | 3 | - | - | - |
| [ref](./ref.md) | 29 | - | - | - |
| [refRemote](./refRemote.md) | 13 | - | - | - |
| [required](./required.md) | 5 | - | - | - |
| [type](./type.md) | 11 | - | - | - |
| [unevaluatedItems](./unevaluatedItems.md) | 23 | - | 2 | - |
| [unevaluatedProperties](./unevaluatedProperties.md) | 36 | - | 3 | 2 |
| [uniqueItems](./uniqueItems.md) | 6 | - | - | - |
| [unknownKeyword](./unknownKeyword.md) | 1 | - | 1 | - |
| [vocabulary](./vocabulary.md) | 1 | 1 | - | - |
| [optional/bignum](./optional-bignum.md) | 7 | - | - | - |
| [optional/dependencies-compatibility](./optional-dependencies-compatibility.md) | 7 | - | - | - |
| [optional/ecmascript-regex](./optional-ecmascript-regex.md) | 21 | - | - | - |
| [optional/float-overflow](./optional-float-overflow.md) | 1 | - | - | - |
| [optional/format-assertion](./optional-format-assertion.md) | 2 | 2 | - | - |
| [optional/non-bmp-regex](./optional-non-bmp-regex.md) | 2 | - | - | - |
| [optional/refOfUnknownKeyword](./optional-refOfUnknownKeyword.md) | 2 | - | 2 | - |

### Notes

`{ isJSON: true }` option is used for better clarity, and that also corresponds to the main
expected usage pattern of this module. Without it, there would be additional checks for
`!== undefined`, which can be fast-tracked if we know that the input came from `JSON.parse()`.
204 changes: 204 additions & 0 deletions doc/samples/draft-next/additionalProperties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# additionalProperties

## additionalProperties being false does not allow other properties

### Schema

```json
{
"properties": { "foo": {}, "bar": {} },
"patternProperties": { "^v": {} },
"additionalProperties": false
}
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key1 of Object.keys(data)) {
if (key1 !== "foo" && key1 !== "bar" && !(key1.startsWith("v"))) return false
}
}
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] empty rules node is not allowed at #/properties/foo`


## non-ASCII pattern with additionalProperties

### Schema

```json
{ "patternProperties": { "^á": {} }, "additionalProperties": false }
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key1 of Object.keys(data)) {
if (!(key1.startsWith("á"))) return false
}
}
return true
};
return ref0
```

##### Strong mode notices

* `Should start with ^ and end with $: "^á" at #`


## additionalProperties with schema

### Schema

```json
{
"properties": { "foo": {}, "bar": {} },
"additionalProperties": { "type": "boolean" }
}
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key0 of Object.keys(data)) {
if (key0 !== "foo" && key0 !== "bar") {
if (!(typeof data[key0] === "boolean")) return false
}
}
}
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] empty rules node is not allowed at #/properties/foo`


## additionalProperties can exist by itself

### Schema

```json
{ "additionalProperties": { "type": "boolean" } }
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key0 of Object.keys(data)) {
if (!(typeof data[key0] === "boolean")) return false
}
}
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] type should be specified at #`


## additionalProperties are allowed by default

### Schema

```json
{ "properties": { "foo": {}, "bar": {} } }
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] empty rules node is not allowed at #/properties/foo`


## additionalProperties does not look in applicators

### Schema

```json
{
"allOf": [{ "properties": { "foo": {} } }],
"additionalProperties": { "type": "boolean" }
}
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key0 of Object.keys(data)) {
if (!(typeof data[key0] === "boolean")) return false
}
}
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] empty rules node is not allowed at #/allOf/0/properties/foo`


## additionalProperties with null valued instance properties

### Schema

```json
{ "additionalProperties": { "type": "null" } }
```

### Code

```js
'use strict'
const ref0 = function validate(data) {
if (typeof data === "object" && data && !Array.isArray(data)) {
for (const key0 of Object.keys(data)) {
if (!(data[key0] === null)) return false
}
}
return true
};
return ref0
```

##### Strong mode notices

* `[requireValidation] type should be specified at #`

Loading

0 comments on commit d514df2

Please sign in to comment.