bcherny / json-schema-to-typescript

Compile JSON Schema to TypeScript type declarations
https://bcherny.github.io/json-schema-to-typescript-browser/
MIT License
2.95k stars 392 forks source link

fix: fix bad validation of definitions #616

Open aloisklink opened 3 months ago

aloisklink commented 3 months ago

Sometimes, traverse accidentally traverses a non-schema object, e.g. instead traversing the properties object of a schema.

This then causes validation errors if one of these properties is "invalid" (e.g. you have a key called deprecated).

Using traverse instead of traverseObjectKeys seems to fix this, since then we don't traverse on objects that contain BLACKLISTED_KEYS.

For an example, see the test case I added. On the current master branch, shows the following error:

[
  'Error at key "properties" in file "deprecated": deprecated must be a boolean'
]

For a real world use-case, I was trying to use the OpenAPI 3.1 JSON Schema in my app and I got this validation error.

[^1]: Unfortunately, even after fixing this bug, it looks like OpenAPI 3.1's JSON Schema uses some new features in JSON Schema that the @apidevtools/json-schema-ref-parser library does not yet support: https://github.com/APIDevTools/json-schema-ref-parser/issues/145