Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.11.0
Choose a base ref
...
head repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.11.1
Choose a head ref

Commits on May 13, 2022

  1. build(deps-dev): bump glob from 7.2.0 to 8.0.2 (#1981)

    Bumps [glob](https://github.com/isaacs/node-glob) from 7.2.0 to 8.0.2.
    - [Release notes](https://github.com/isaacs/node-glob/releases)
    - [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
    - [Commits](isaacs/node-glob@v7.2.0...v8.0.2)
    
    ---
    updated-dependencies:
    - dependency-name: glob
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored May 13, 2022

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    99e884d View commit details

Commits on Sep 27, 2022

  1. Update README.md

    epoberezkin authored Sep 27, 2022

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    1657fe4 View commit details
  2. Update README.md

    epoberezkin authored Sep 27, 2022
    Copy the full SHA
    13caf47 View commit details
  3. Update README.md

    epoberezkin authored Sep 27, 2022
    Copy the full SHA
    948ffbf View commit details

Commits on Nov 13, 2022

  1. Copy the full SHA
    572c843 View commit details
  2. Remove unnecessary console.log (#2138)

    There are already console logs in the parseAndLog function itself. parseAndLog(json) and parseAndLog(invalidJson) will just print 2 undefined in plus
    vargaeric authored Nov 13, 2022
    Copy the full SHA
    58f9e7f View commit details
  3. Copy the full SHA
    d6d8d5f View commit details
  4. Doc: update the documentation of addKeyword args (#2090)

    * update the documentation of addKeyword args
    
    * add the
    
    * corrections
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    TommyDew42 and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    7516a09 View commit details
  5. docs: parsing does not support non-standard JTD keywords (#2072)

    * add Non-standard JTD keywords warn
    
    * correction
    
    * correction
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    avanelli and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    b3cbbc1 View commit details
  6. build(deps-dev): bump husky from 7.0.4 to 8.0.2 (#2153)

    Bumps [husky](https://github.com/typicode/husky) from 7.0.4 to 8.0.2.
    - [Release notes](https://github.com/typicode/husky/releases)
    - [Commits](typicode/husky@v7.0.4...v8.0.2)
    
    ---
    updated-dependencies:
    - dependency-name: husky
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    69d7897 View commit details
  7. ensure that nullable is not set for required parameters (#2079)

    nullable was enforced for optional parameters, but not forbidden for
    required parameters. This tests and enforces the latter case.
    
    fixes #2030
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    erikbrinkman and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    00b3939 View commit details
  8. fix: typo (#2010)

    hadrien-toma authored Nov 13, 2022
    Copy the full SHA
    d6f3ac9 View commit details
  9. docs: fix link for useDefaults (#1955)

    * Clarify validation errors and fix link for useDefaults.
    
    * Make it clear the value, not the property, may be missing.
    
    * remove correction
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    bradjones1 and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    5d5c803 View commit details
  10. build(deps-dev): bump @rollup/plugin-commonjs from 21.1.0 to 23.0.2 (#…

    …2142)
    
    Bumps [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/HEAD/packages/commonjs) from 21.1.0 to 23.0.2.
    - [Release notes](https://github.com/rollup/plugins/releases)
    - [Changelog](https://github.com/rollup/plugins/blob/master/packages/commonjs/CHANGELOG.md)
    - [Commits](https://github.com/rollup/plugins/commits/commonjs-v23.0.2/packages/commonjs)
    
    ---
    updated-dependencies:
    - dependency-name: "@rollup/plugin-commonjs"
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    f90a1cf View commit details
  11. build(deps-dev): bump fast-uri from 1.0.1 to 2.1.0 (#2007)

    Bumps [fast-uri](https://github.com/fastify/fast-uri) from 1.0.1 to 2.1.0.
    - [Release notes](https://github.com/fastify/fast-uri/releases)
    - [Commits](fastify/fast-uri@v1.0.1...v2.1.0)
    
    ---
    updated-dependencies:
    - dependency-name: fast-uri
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 13, 2022
    Copy the full SHA
    d0beea5 View commit details
  12. docs: fix broken links (#2006)

    Co-authored-by: Connor Smith <Connor.Smith@aexp.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    3 people authored Nov 13, 2022
    Copy the full SHA
    67e7f1c View commit details
  13. Update security.md -> ReDoS Attack Section (#1953)

    I made a mistake with one of the code snippets in the documentation. The 'regExp' attribute belongs to the code options, not the ajv options directly.
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    efebarlas and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    b2a109c View commit details
  14. Copy the full SHA
    f38d269 View commit details
  15. build(deps-dev): bump @rollup/plugin-node-resolve from 13.3.0 to 15.0…

    ….1 (#2143)
    
    Bumps [@rollup/plugin-node-resolve](https://github.com/rollup/plugins/tree/HEAD/packages/node-resolve) from 13.3.0 to 15.0.1.
    - [Release notes](https://github.com/rollup/plugins/releases)
    - [Changelog](https://github.com/rollup/plugins/blob/master/packages/node-resolve/CHANGELOG.md)
    - [Commits](https://github.com/rollup/plugins/commits/node-resolve-v15.0.1/packages/node-resolve)
    
    ---
    updated-dependencies:
    - dependency-name: "@rollup/plugin-node-resolve"
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    b8f563b View commit details
  16. build(deps-dev): bump @types/node from 17.0.45 to 18.11.9 (#2151)

    Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.45 to 18.11.9.
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)
    
    ---
    updated-dependencies:
    - dependency-name: "@types/node"
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    fa4343b View commit details
  17. build(deps-dev): bump mocha from 9.2.2 to 10.0.0 (#1972)

    Bumps [mocha](https://github.com/mochajs/mocha) from 9.2.2 to 10.0.0.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v9.2.2...v10.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: mocha
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    b3c53ed View commit details
  18. build(deps-dev): bump lint-staged from 12.5.0 to 13.0.3 (#2019)

    Bumps [lint-staged](https://github.com/okonet/lint-staged) from 12.5.0 to 13.0.3.
    - [Release notes](https://github.com/okonet/lint-staged/releases)
    - [Commits](lint-staged/lint-staged@v12.5.0...v13.0.3)
    
    ---
    updated-dependencies:
    - dependency-name: lint-staged
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dependabot[bot] and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    65220d6 View commit details
  19. export ValidationError and MissingRefError, closes #1926, closes #1840 (

    #2020)
    
    * expost Validation Error - fix to #1926
    
    * fixed prettier issues
    
    Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
    dannyb648 and epoberezkin authored Nov 13, 2022
    Copy the full SHA
    16af695 View commit details
  20. 8.11.1

    epoberezkin committed Nov 13, 2022
    Copy the full SHA
    92e5a1e View commit details
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ Your continuing support is very important - the funds will be used to develop an
Please sponsor Ajv via:

- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it)
- [Ajv Open Collective️](https://opencollective.com/ajv)
- [Ajv Open Collective](https://opencollective.com/ajv)

Thank you.

@@ -73,6 +73,19 @@ Thank you.
<a href="https://opencollective.com/ajv/organization/9/website"><img src="https://opencollective.com/ajv/organization/9/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/10/website"><img src="https://opencollective.com/ajv/organization/10/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/11/website"><img src="https://opencollective.com/ajv/organization/11/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/12/website"><img src="https://opencollective.com/ajv/organization/12/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/13/website"><img src="https://opencollective.com/ajv/organization/13/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/14/website"><img src="https://opencollective.com/ajv/organization/14/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/15/website"><img src="https://opencollective.com/ajv/organization/15/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/16/website"><img src="https://opencollective.com/ajv/organization/16/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/17/website"><img src="https://opencollective.com/ajv/organization/17/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/18/website"><img src="https://opencollective.com/ajv/organization/18/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/19/website"><img src="https://opencollective.com/ajv/organization/19/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/20/website"><img src="https://opencollective.com/ajv/organization/20/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/21/website"><img src="https://opencollective.com/ajv/organization/21/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/22/website"><img src="https://opencollective.com/ajv/organization/22/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/23/website"><img src="https://opencollective.com/ajv/organization/23/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/24/website"><img src="https://opencollective.com/ajv/organization/24/avatar.svg"></a>

## Performance

6 changes: 4 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ Every time this method is called the errors are overwritten so you need to copy

If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](./guide/async-validation.md).

<a name="add-schema"></a>
<a id="add-schema"></a>

### ajv.addSchema(schema: object | object[], key?: string): Ajv

@@ -245,7 +245,7 @@ Formats can be also added via `formats` option.

<a name="api-addkeyword"></a>

### ajv.addKeyword(definition: object): Ajv
### ajv.addKeyword(definition: string | object): Ajv

Add validation keyword to Ajv instance.

@@ -297,6 +297,8 @@ interface KeywordDefinition {
}
```

If only the property `keyword` is provided in the definition object, you can also pass the keyword name as the argument.

`compile`, `macro` and `code` are mutually exclusive, only one should be used at a time. `validate` can be used separately or in addition to `compile` or `macro` to support [\$data reference](./guide/combining-schemas.md#data-reference).

::: tip Keyword is validated only for applicable data types
2 changes: 1 addition & 1 deletion docs/guide/combining-schemas.md
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ const ajv = new Ajv()
const validate = ajv.addSchema(defsSchema).compile(schema)
```

See [Options](./api.md#options) and [addSchema](./api.md#add-schema) method.
See [Options](../options.md) and [addSchema](../api.md#add-schema) method.

::: tip Reference resolution
- `$ref` is resolved as the uri-reference using schema \$id as the base URI (see the example).
6 changes: 3 additions & 3 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
You can try Ajv without installing it in the Node.js REPL: [https://runkit.com/npm/ajv](https://runkit.com/npm/ajv)
:::

To install Ajv version 7:
To install Ajv version 8:

```bash
npm install ajv
@@ -140,8 +140,8 @@ const parse = ajv.compileParser(schema)
const json = '{"foo": 1, "bar": "abc"}'
const invalidJson = '{"unknown": "abc"}'

console.log(parseAndLog(json)) // logs {foo: 1, bar: "abc"}
console.log(parseAndLog(invalidJson)) // logs error and position
parseAndLog(json) // logs {foo: 1, bar: "abc"}
parseAndLog(invalidJson) // logs error and position

function parseAndLog(json) {
const data = parse(json)
2 changes: 1 addition & 1 deletion docs/guide/modifying-data.md
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ See [discriminator](../json-schema.md#discriminator) keyword.

## Assigning defaults

With [option `useDefaults`](./api.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
With [option `useDefaults`](./options.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.

With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.

4 changes: 4 additions & 0 deletions docs/json-type-definition.md
Original file line number Diff line number Diff line change
@@ -416,6 +416,10 @@ Any user-defined keywords that can be used in JSON Schema schemas can also be us
It is strongly recommended to only use it to simplify migration from JSON Schema to JTD and not to use non-standard keywords in the new schemas, as these keywords are not supported by any other tools.
:::

::: warning Parsing does NOT support non-standard JTD keywords
compileParser method does not support non-standard JTD keywords, you will have to use JSON.parse and then validates.
:::

## Validation errors

TODO
2 changes: 1 addition & 1 deletion docs/keywords.md
Original file line number Diff line number Diff line change
@@ -239,7 +239,7 @@ ajv.addKeyword({
})
```

Macro keywords an be recursive - i.e. return schemas containing the same keyword. See the example of defining a recursive macro keyword `deepProperties` in the [test](https://github.com/ajv-validator/ajv/blob/master/spec/keyword.spec.ts#L316).
Macro keywords can be recursive - i.e. return schemas containing the same keyword. See the example of defining a recursive macro keyword `deepProperties` in the [test](https://github.com/ajv-validator/ajv/blob/master/spec/keyword.spec.ts#L316).

## Schema compilation context

2 changes: 1 addition & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ To use a third-party regex engine in Ajv, set the ajv.opts.code.regExp property
```
const Ajv = require("ajv")
const RE2 = require("re2")
const ajv = new Ajv({regExp: RE2})
const ajv = new Ajv({code: {regExp: RE2}})
```

For details about the interface of the `regexp` option, see options.md under the docs folder.
2 changes: 2 additions & 0 deletions lib/2019.ts
Original file line number Diff line number Diff line change
@@ -76,3 +76,5 @@ export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
2 changes: 2 additions & 0 deletions lib/2020.ts
Original file line number Diff line number Diff line change
@@ -70,3 +70,5 @@ export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
2 changes: 2 additions & 0 deletions lib/ajv.ts
Original file line number Diff line number Diff line change
@@ -65,3 +65,5 @@ export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
2 changes: 2 additions & 0 deletions lib/jtd.ts
Original file line number Diff line number Diff line change
@@ -127,3 +127,5 @@ export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./com

export {JTDSchemaType, SomeJTDSchemaType, JTDDataType}
export {JTDOptions}
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
1 change: 1 addition & 0 deletions lib/types/json-schema.ts
Original file line number Diff line number Diff line change
@@ -180,6 +180,7 @@ type Nullable<T> = undefined extends T
default?: T | null
}
: {
nullable?: false
const?: T
enum?: Readonly<T[]>
default?: T
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "8.11.0",
"version": "8.11.1",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
@@ -65,13 +65,13 @@
},
"devDependencies": {
"@ajv-validator/config": "^0.3.0",
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/chai": "^4.2.12",
"@types/mocha": "^9.0.0",
"@types/node": "^17.0.0",
"@types/node": "^18.11.9",
"@types/require-from-string": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
@@ -83,18 +83,18 @@
"dayjs-plugin-utc": "^0.1.2",
"eslint": "^7.8.1",
"eslint-config-prettier": "^7.0.0",
"fast-uri": "^1.0.0",
"glob": "^7.0.0",
"husky": "^7.0.1",
"fast-uri": "^2.1.0",
"glob": "^8.0.2",
"husky": "^8.0.2",
"if-node-version": "^1.0.0",
"jimp": "^0.16.1",
"js-beautify": "^1.7.3",
"json-schema-test": "^2.0.0",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.0.0",
"karma-mocha": "^2.0.0",
"lint-staged": "^12.1.1",
"mocha": "^9.0.2",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"module-from-string": "^3.1.3",
"node-fetch": "^3.0.0",
"nyc": "^15.0.0",
@@ -104,7 +104,7 @@
"rollup-plugin-terser": "^7.0.2",
"ts-node": "^10.0.0",
"tsify": "^5.0.2",
"typescript": "^4.2.0"
"typescript": "^4.8.0"
},
"collective": {
"type": "opencollective",
17 changes: 17 additions & 0 deletions spec/types/json-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -306,6 +306,23 @@ describe("JSONSchemaType type and validation as a type guard", () => {
// eslint-disable-next-line no-void
void optionalSchema
})

it("won't accept nullable for non-null types", () => {
// @ts-expect-error can't set nullable
const nonNullSchema: JSONSchemaType<{a: number}> = {
type: "object",
properties: {
a: {
type: "number",
nullable: true,
},
},
required: [],
}

// eslint-disable-next-line no-void
void nonNullSchema
})
})

describe("schema works for primitives", () => {
4 changes: 2 additions & 2 deletions spec/types/jtd-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -130,12 +130,12 @@ describe("JTDSchemaType", () => {
// tuples don't work
// @ts-expect-error
const tupleHomo: JTDSchemaType<[number, number]> = {elements: {type: "float64"}}
// @ts-expect-error
const tupleHeteroNum: JTDSchemaType<[number, string]> = {
// @ts-expect-error
elements: {type: "float64"},
}
// @ts-expect-error
const tupleHeteroString: JTDSchemaType<[number, string]> = {
// @ts-expect-error
elements: {type: "string"},
}
const elemNull: JTDSchemaType<number[] | null> = {elements: {type: "float64"}, nullable: true}