ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.47k stars 864 forks source link

JTD schema parser errors on empty properties field #2399

Closed brian-statsig closed 2 months ago

brian-statsig commented 2 months ago

What version of Ajv are you using? Does the issue happen if you use the latest version? latest version

Ajv options object no options

JSON Schema

{ "properties": {} }

Validation result, data AFTER validation, error messages

TypeError: Reduce of empty array with no initial value

Code

  const ajv = new Ajv();
ajv.compileParser({ properties: {} });

What results did you expect? A compiled schema that passes nothing or everything. I think more graceful handling would be nice

jasoniangreen commented 2 months ago

If you want to validate JSON Type Definition schemas you need to invoke Ajv differently (see top of page).

import Ajv from "ajv/dist/jtd"
const ajv = new Ajv()