If-Then for various forms of an Address #529
Replies: 3 comments 10 replies
-
Can you update your question with what's not working for you? Are there examples of data that should pass but don't, or data that should fail but don't? |
Beta Was this translation helpful? Give feedback.
-
You need to use |
Beta Was this translation helpful? Give feedback.
-
I have recreated the test scenario in a clone of the JsonScema.Net repo. Debugging the scenario shows me that when it tests the snippet of one of the If branches that causes a validation error (when processing a 'CA' IsoCountryCode
|
Beta Was this translation helpful? Give feedback.
-
I have been trying to work out how to write the json-schema using
If-Then
andOneOf
so that I can vary the Address property based onIsoCountryCode
example data (for a Canadian Address format
There are different Address objects for US, UK, CA etc with each having differences in their properties, Enums, regex patterns etc.
Here is an example of an attempt at it
NB. I have not attempted to add a
Default
Address in this example to keep it from becoming too complex.Behavior
Expect Valid
If I validate the above (Good) data against the schema using JsonSchema.Net, then it says that the result.IsValid is FALSE and there are no Errors. The Details node is also empty so no errors in any lower level nodes.
Expect Invalid and 1 Error
If I change the data and put invalid characters into the Address.City (e.g. <> chars) and Validate it, then I get result.IsValid is FALSE (as expected), but I also get 5 errors when i am only expecting to get the one pattern error for the Address.City.
The 5 errors are
Beta Was this translation helpful? Give feedback.
All reactions