-
Notifications
You must be signed in to change notification settings - Fork 0
anyOf #19
base: merging
Are you sure you want to change the base?
anyOf #19
Conversation
Codecov Report
@@ Coverage Diff @@
## merging #19 +/- ##
==========================================
Coverage ? 97.64%
==========================================
Files ? 2
Lines ? 85
Branches ? 0
==========================================
Hits ? 83
Misses ? 2
Partials ? 0 Continue to review full report at Codecov.
|
This is a simplified treatment. The documentation is not super clear in this area, but I'm pretty sure that you can actually have |
I added another test for a nested anyOf, and it doesn't seem to work: def test_anyof_nested():
"""Test generating an object from an anyOf schema."""
schema = {
"properties": {
"a": {
"anyOf": [
{
"type": "string",
},
{
"type": "integer",
},
],
}
},
}
output = generate_json(schema)
assert isinstance(output["a"], (str, int)) Is this a use case we need to support? It seems like it should be, but I'm not sure how we would go about implementing this. |
It looks like that fails because the top-level schema ought to have |
After digging a bit more, I think I understand. This: {
"type": "object",
"properties": {
"a": {},
"b": {}
},
"anyOf": [
{"required": ["a"]},
{"required": ["b"]}
]
} is equivalent to: {
"anyOf": [
{
"type": "object",
"properties": {
"a": {},
"b": {}
},
"required": ["a"]
},
{
"type": "object",
"properties": {
"a": {},
"b": {}
},
"required": ["b"]
}
]
} So I think we ought to do basically that transformation, followed by the simple anyOf procedure I've implemented here. @alongreyber has already taken a swing at schema merging in #20, so perhaps we should finish that up first. |
It gets difficult to figure out whether json_schema_fuzz itself is a local module or a third-party module
…or recursive call
This isn't exactly how you were planning to do this, but I think it is equivalent. The idea is to sample the list of anyOf schemas provided to pick a sublist (because anyOf can be one or more of the provided schemas). We merge those subschemas together and check if those subschemas were merged without error. If they were merged without error, we merge the combined schemas back into the base. If not, we pick a new sample. There will always be a valid sample because picking a single subschema is always valid. Let me know if you have questions about this process. |
No description provided.