Is it correct to define both pattern and format for type string property?
VShingala opened this issue · 3 comments
So I came across a schema that I am not sure is valid or not. From a pure syntax perspective, it is correct but it contains conflicting info.
In the below example both format and pattern keywords are defined. And there is no single data that it's valid against. If the value is of sort 2018-11-13T20:20:39+00:00 then pattern is violated and if it's 2018-11-13 20:20:39 then format is violated.
{
"type": "string",
"format": "date-time",
"pattern": "^([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])( (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]))?$"
}
Should both keywords be mentioned at the same time? If yes, which keyword should take precedence? I went through the document on string but couldn't find an answer on this.
There are many situations that can, and legitimately so, result in a schema for which it's impossible for any data to be valid against.
This is expected. There may be conflicts. One keyword doesn't take any precedence (in terms of preventing another from being used, in your example) than another.
It's also worth noting, that by default, format "does nothing", and implementations MAY choose to provide another layer of validation. You can't expect others using your schema to rely on format.
Thanks for the quick reply!
Understood, so from what I gathered it's up to corresponding implementations to understand what they should do in these cases given schema. And the schema I have mentioned is correct and valid.
Let me know if anything is wrong with what I mentioned.
That's correct. Closing issue as question has been answered.