Order of pattern properties matter! #619
-
Hello Expert,
It was enforcing the type string on the properties that were named BAR, bar, Bar etc and for anything else (eg baz, bars, rebars), it was enforcing number type. But when the order was reversed like this:
It started enforcing type number on Bar, BAR etc also. Now I am trying to figure out a regex that matches "everything but all case variations of the bar" which I can use in place of ^.*$" so that order of pattern properties does not matter. And I am really struggling with it, specially since it will require regex negative lookahead which may not be supported universally and uniformly. Is there any other workaround to it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
That sounds like a bug in whatever implementation you are using, though I suspect you're not actually using a validator but some other kind of JSON Schema tool -- JSON objects (let alone within JSON Schema) are unordered, and indeed no matter what order you apply the constraints there, the JSON Schema specification would say that that schema would never match any instance with a property called "bar" (or the like) as indeed it would always require that property to simultaneously be a string and number. EDIT: Though I haven't answered what I assume your actual question must be -- which is how to write a schema which does one thing for |
Beta Was this translation helpful? Give feedback.
-
this will work in some of the instances in my case but of course better option will be to have properly constructed non-overlapping regex |
Beta Was this translation helpful? Give feedback.
-
Well that explains a lot. I am glad that it wasn't a flaw in my my limited understanding of json / json but a bug instead. |
Beta Was this translation helpful? Give feedback.
In your simplified example that should be pretty easy, just use
additionalProperties
instead, i.e.:If that doesn't work for your real example you'll probably need to expand your simplified one, but hopefully that helps.