-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from rmspeers/51-nested-oneOf
#51 handle nested anyof, ensure that data gets passed down via object creators
- Loading branch information
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,56 @@ def test_simple_array_anyOf(): | |
assert y.ExampleAnyOf == "[email protected]" | ||
|
||
|
||
def test_nested_anyOf(): | ||
basicSchemaDefn = { | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Test", | ||
"properties": {"ExampleAnyOf": {"$ref": "#/definitions/externalItem"}}, | ||
"required": ["ExampleAnyOf"], | ||
"type": "object", | ||
"definitions": { | ||
"externalItem": { | ||
"type": "object", | ||
"properties": { | ||
"something": {"type": "string"}, | ||
"exampleAnyOf": { | ||
"anyOf": [ | ||
{"type": "string", "format": "email"}, | ||
{"type": "string", "maxlength": 0}, | ||
] | ||
}, | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
builder = pjo.ObjectBuilder(basicSchemaDefn) | ||
|
||
ns = builder.build_classes(any_of="use-first") | ||
ns.Test().from_json( | ||
'{"ExampleAnyOf" : {"something": "someone", "exampleAnyOf": "[email protected]"} }' | ||
) | ||
|
||
with pytest.raises(pjo.ValidationError): | ||
# Because this does not match the email format: | ||
ns.Test().from_json( | ||
'{"ExampleAnyOf" : {"something": "someone", "exampleAnyOf": "not-a-email-com"} }' | ||
) | ||
|
||
# Does it also work when not deserializing? | ||
x = ns.Test(ExampleAnyOf={"something": "somestring"}) | ||
with pytest.raises(pjo.ValidationError): | ||
x.ExampleAnyOf.exampleAnyOf = "" | ||
|
||
with pytest.raises(pjo.ValidationError): | ||
x.ExampleAnyOf.exampleAnyOf = "not-an-email" | ||
|
||
x.ExampleAnyOf.exampleAnyOf = "[email protected]" | ||
out = x.serialize() | ||
y = ns.Test.from_json(out) | ||
assert y.ExampleAnyOf.exampleAnyOf == "[email protected]" | ||
|
||
|
||
def test_simple_array_anyOf_withoutConfig(): | ||
basicSchemaDefn = { | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
|