json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

fix: fix bad validation of definitions

Open aloisklink opened this issue 1 year ago • 0 comments

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

aloisklink avatar Aug 12 '24 14:08 aloisklink