-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests with patterns #44
Comments
Thanks for reporting! I must have not tested this properly: #2 Should have left it as it was. |
The first case could be solved by merging it in the same way, but by adding I am tempted however to make it unresolved, not 100% sure that will work for all possible regex expressions. Also it could get rather hard to read if many regex patterns. Thoughts? But the second case is not really related to pattern, but to I don't really think I can combine allOf from multiple contains as I do now. As it is the combination of all the keywords in one contains that decides if it matches. So if we move some subkeywords from different contains together then it might not match a single item all in one. Even though seperately they would match, like you described above. However inside each contains, there we can merge allOf as normal. This might even apply to some other keywords, will need to check. |
Regarding merging the patterns: We have built a tool that can check two (Draft6) schemas for equivalence (https://jsonschematool-370416.oa.r.appspot.com/). Nevertheless, one cannot and-merge two distinct "contains" into one "contains", because (exists x.P(x) And exists x.Q(x)) is not equivalent to (exists x. (P(x) And Q(x)). In running your unit tests through our tool, we found several cases where the input schema and merged schema are not equivalent, for instance here
The instance
is valid w.r.t. one schema but not the other. We are happy to share further details. |
Yeah you are right. This is probably an issue with oneOf/anyOf as well. I must have been a bit quick in my thinking when doing those. Although looking at it now it is pretty obvious those can not be merged as they depend on 1 or 1 or more schemas to match IN THAT allOf schema. I have myself not used those much, at least not with conflicting values, so have not discovered it. I have started the process of cleaning up this. What is most important for me is the lossless nature of the merging process. Better to leave the resulting schema a bit more verbose than it could be than to change the validation result. See #45 Still there is more to do, as your example proves, for complex resolvers like properties/patternproperties. |
If you do have readily available more test cases of instances validating differently I would appreaciate to have a look at them yes if that is possible. :) |
We are happy to share our findings, and we would also be very interested in your feedback, whether we unserstood the intention of your tests. (1)
Valid w.r.t. merged schema, but not the original schema:
(2)
Valid w.r.t. original schema, but not the merged schema:
(3)
Valid w.r.t. original schema, but not the merged schema:
(4) json-schema-merge-allof/test/specs/index.spec.js Line 1022 in ea2e48e
(This one we already discussed) (5)
Valid w.r.t. the original schema, but not the merged schema:
Vice versa for the instance (6) json-schema-merge-allof/test/specs/index.spec.js Line 1678 in ea2e48e
I assume the merged schema is this (I might be mistaken):
Valid w.r.t. merged schema, but not the original schema:
(7)
From the code, this seema seems to be considered unsatisfiable? But maybe I misunderstood the intent. (8)
Valid w.r.t. the original schema, but not the merged schema:
Vice versa for the instance |
Yet another case which looks is not valid: the source schema {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"allOf": [
{
"contains": {
"type": "object",
"properties": {
"type": {
"pattern": "1"
}
}
}
},
{
"contains": {
"type": "object",
"properties": {
"type": {
"pattern": "2"
}
}
}
}
]
} merged schema looks absolutely wrong: {
"type": "array",
"contains": {
"type": "object",
"properties": {
"type": {
"pattern": "(?=1)(?=2)"
}
}
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
} from my memory, v0.6 merged as: {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"contains": {
"type": "object",
"properties": {
"type": {
"allOf": [
{
"pattern": "1"
},
{
"pattern": "2"
}
]
}
}
}
} |
The unit tests create patterns like
(?=bar)(?=foo)
,e.g. in the test that merges contains.
Yet this resulting pattern seems to be unsatisfiable.
The following instances are valid w.r.t. the original schema but not the merged schema:
The text was updated successfully, but these errors were encountered: