Warm tip: This article is reproduced from stackoverflow.com, please click
javascript json jsonschema json-schema-validator

how to make the json schema flexible enough to handle case sensitive input for enum?

发布于 2020-03-28 23:14:06

Please refer to this question for the introduction Two way binding dependences based on enum value in json schema.

Now the case is that if I pass userType = CUSTOMER then it doesn't accept the request and in also the case of userType = customer.

Can anyone suggest me JSON schema solution for this?

Questioner
Bhagyesh Radiya
Viewed
108
Jason Desrosiers 2020-02-02 08:23

There isn't a way to do this that isn't awful, but the least awful thing I can think of is to use pattern with a regex that includes both cases.

{
  "type": "string",
  "anyOf": [
    { "title": "Customer", "pattern": "[Cc][Uu][Ss][Tt][Oo][Mm][Ee][Rr]" },
    { "title": "Admin", "pattern": "[Aa][Dd][Mm][Ii][Nn]" },
  ]
}

(The title isn't necessary, it's just a nicety for the poor dev who has to read this schema)