You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validation will pass although id should expect a number and name should expect a string.
The solution is to add a "properties" key below items like so:
This now fails as expected. I don't know if the non-failure in the first case is a bug or expected behavior, but I am wondering why it doesn't fail, when it clearly is an incorrectly constructed schema. It doesn't appear as if tv4 is trying to validate that those items are in the array, or that the syntax is incorrect, or any other error one might expect.
The text was updated successfully, but these errors were encountered:
I had the same problem as you, but I have come to the conclusion that it is by design.
When using the items key, you "starts" a new schema so to speak. Might be the wrong terminology.
In the schema for an array, you must specify the type of items the array may contain. The type of an item is itself a schema. In other words, the value for the items key must be a schema itself.
See below.
type: "object",
properties: { ... }
versus
type: "array",
items: {
<some schema>
}
This is why validation still occurs. Your example:
Say my response is a JSON array of objects:
If I (incorrectly) build my schema like this:
Validation will pass although id should expect a number and name should expect a string.
The solution is to add a "properties" key below items like so:
This now fails as expected. I don't know if the non-failure in the first case is a bug or expected behavior, but I am wondering why it doesn't fail, when it clearly is an incorrectly constructed schema. It doesn't appear as if tv4 is trying to validate that those items are in the array, or that the syntax is incorrect, or any other error one might expect.
The text was updated successfully, but these errors were encountered: