Case Insensitive Enums? #148
Replies: 5 comments 2 replies
-
I agree that JSON Schema needs a better solution for this. Something I've considered is adding a way to pass regex flags for a pattern. In this case, the
Of course this wouldn't work for
But, that would be a breaking change, so we would have to be really sure want to make that change. |
Beta Was this translation helpful? Give feedback.
-
There already is syntax for flags inside of regexes - they can even be nested -- but it's up to your particular language as to whether they are supported. "any-case" as a case-insensitive regex would be |
Beta Was this translation helpful? Give feedback.
-
In |
Beta Was this translation helpful? Give feedback.
-
It also needs to be noted that the opening comment assumes string-only enums. Enums may be of any JSON value, including objects and arrays. Maybe what's needed is a new keyword (vocab suggestion) such as |
Beta Was this translation helpful? Give feedback.
-
@Pluckerpluck JSON Schema now has support for extension vocabularies, so you could publish your keyword specification that way and others could implement it and use it in an interoperable way (although not with AJV which has refused to implement vocabulary support and stuck with its own non-interoperable extensions instead). |
Beta Was this translation helpful? Give feedback.
-
I have now worked on a number of existing APIs that have operated in case-insensitive ways, and the inability to create a case insensitive enum has frustrated me. So will we ever see support for case insensitive Enums?
JSON Schema already supports regex, which is platform dependent. The simple suggestion here is to "avoid using features that aren't common accross most regex engines".
So I believe a similar thought process could be defined here. The same way
toLowerCase
is defined in JavaScript to be locale insensitive, a basic implimentation in the Schema could be likewise defined. Just like JavaScript we could use the locale independent mapping provided by the Unicode Character Database (therefore this is fully standardized)Alternatively, the option to be locale specific could be included in the settings. Support for this functionality would then be engine dependent, but I know that at least JavaScript supports this under
toLocaleUpperCase
. Something else to consider would be the ICU libraries if we wanted locale sensitivity. They already handle case conversion, and wrappers exist in many languages.You can see the JavaScript implementation here, which references the Unicode Default Case Conversion algorithm.
I know best practices would not have case insensitivity in APIs. But in practice it is not uncommon. As a result I've been forced to implement my own validation on enums that works case insensitively.
I hope this is the right place to bring up this discussion. I honestly am unsure.
Beta Was this translation helpful? Give feedback.
All reactions