Reporting duplicate enum values when json schema is compiled?
sebastien-rosset opened this issue · 2 comments
It would be useful to report a warning or error when the compiler finds duplicate enum values. For example, having the same foo
enum value in a flat list of enums seems to be a mistake (such as a typo by the author of a JSON schema):
enum:
- foo
- foo
- bar
Technically, duplicate enum values are allowed by the spec, so I understand why the compiler cannot fail the compilation if it finds duplicate enums. The 2020-12 JSON schema states:
The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.
(https://json-schema.org/draft/2020-12/json-schema-validation.html#name-enum )
Previously (in draft 4 - https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#page-15), enum values MUST be unique.
Elements in the array MUST be unique.
schema validation is done by validating it with hyper-schema (see here. there is no explicit code for schema validation.
in hyper-schema https://json-schema.org/draft/2019-09/meta/validation
enum
has no uniqueItems
see here
in hyper-schema https://json-schema.org/draft/2020-12/meta/validation
enum
has no uniqueItems
see here
so making it error for above two drafts make it incompatible with the specification.
in earlier drafts, the hyper-schema has uniqueItems
for enum
keyword.
raising warnings is never considered in the library. the api is also not suitable for generating warnings. and more over the library never assumes to be as linter by users.
thanks. I'm closing the issue.