Closed ext closed 2 years ago
Thanks again for raising the PR. I vaguely remember that there was a reason for it but I can't recall it now.
I need some time to review and test this out. I have been away from this project for quite some time. I was waiting for a change in the ajv
so that I can resume rewriting it using typescript
https://github.com/torifat/better-ajv-errors/tree/typescript.
In the current version of
better-ajv-errors
enumeration errors are only handled if it is the only type of errors present. This does not mesh well withanyOf
(or similar construct).Consider the following schema where
id
can either befoo
orbar
(e.g."id": "foo"
) or it can be an array of those values (e.g."id": ["bar", "foo"]
):Given the data
{ id: "baz" }
, Ajv will yield a list of three errors:The current code tests if all errors are
enum
(as far as I can tell because some other edge cases but the previous commits were a bit sparse on details) and only handlesenum
if and only if all errors areenum
.In my use-case this causes the above test to fail and thus the
enum
error is handled byDefaultValidationError
instead ofEnumValidationError
which gives a less precise error:This PR adds the
enum
case back to the else-block soenum
is once again handled byEnumValidationError
giving the intended message again:With that said I do not fully understand the previous case matching only if all errors are
enum
and thus I'm not fully sure there are no regressions with this PR but at least all other test-cases passed without any changes. Please do let me know if there are any issues with this approach.