Validate my array items satisfy certain criteria #988
-
|
Hi All, This is my first time posting so apologies if I'm posting in the wrong place. I'm trying to write a schema that essentially describes a database table and it's fields, the schema looks like this: I want to validate that atleast one of my fields is marked as |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Welcome! This is the perfect place to ask a question like this. You have the right idea with "allOf": [
{
"contains": { pk constraint }
},
{
"contains": { lmd constraint }
}
]If that doesn't help. Please share more of what you've tried. |
Beta Was this translation helpful? Give feedback.
-
|
thanks for the response, here's what I just tried (apologies for the massive JSON dumps): And then with data: Using AJV to validate I get the following 8 errors: So of the 8 total errors, there are three that say every field must be equal to primarykey and then three errors that say that every field must be equal to lastmodifieddate. The other two are errors that say the fields array must contain one item that satisfies the primarykey / lastmodifieddate criteria. When I set a field_one to primarykey and field_two to lastmodifieddate the errors go away i.e. the data is now valid. As I type this I'm starting to wonder if this is perhaps a question for AJV or does JSON schema have the concept describing every way that data isn't valid against a schema? |
Beta Was this translation helpful? Give feedback.
Welcome! This is the perfect place to ask a question like this.
You have the right idea with
contains. Are you saying that you got both constraints working, just not at the same time? You probably just need anallOf.If that doesn't help. Please share more of what you've tried.