-
-
Notifications
You must be signed in to change notification settings - Fork 32
Add reproducer for #20 #55
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -21,10 +21,13 @@ class TestOAS30ValidatorValidate: | |
"integer", | ||
"number", | ||
"string", | ||
"object", | ||
], | ||
) | ||
def test_null(self, schema_type): | ||
schema = {"type": schema_type} | ||
if schema_type == "object": | ||
schema["properties"] = {"some_prop": {"type": "string"}} | ||
validator = OAS30Validator(schema) | ||
value = None | ||
|
||
|
@@ -39,10 +42,13 @@ def test_null(self, schema_type): | |
"integer", | ||
"number", | ||
"string", | ||
"object", | ||
], | ||
) | ||
def test_nullable(self, schema_type): | ||
schema = {"type": schema_type, "nullable": True} | ||
if schema_type == "object": | ||
schema["properties"] = {"some_prop": {"type": "string"}} | ||
validator = OAS30Validator(schema) | ||
value = None | ||
|
||
|
@@ -195,6 +201,54 @@ def test_string_uuid(self, value): | |
|
||
assert result is None | ||
|
||
def test_ref(self): | ||
schema = { | ||
"$ref": "#/$defs/Pet", | ||
"$defs": { | ||
"Pet": { | ||
"required": ["id", "name"], | ||
"properties": { | ||
"id": {"type": "integer", "format": "int64"}, | ||
"name": {"type": "string"}, | ||
"tag": {"type": "string"}, | ||
}, | ||
} | ||
}, | ||
} | ||
validator = OAS30Validator(schema, format_checker=oas30_format_checker) | ||
|
||
result = validator.validate({"id": 1, "name": "John"}) | ||
assert result is None | ||
|
||
with pytest.raises(ValidationError) as excinfo: | ||
validator.validate({"name": "John"}) | ||
|
||
error = "'id' is a required property" | ||
assert error in str(excinfo.value) | ||
|
||
@pytest.mark.xfail(reason="Issue #20") | ||
def test_ref_nullable(self): | ||
schema = { | ||
"nullable": True, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/Pet", | ||
}, | ||
], | ||
"$defs": { | ||
"Pet": { | ||
"required": ["id", "name"], | ||
"properties": { | ||
"id": {"type": "integer", "format": "int64"}, | ||
"name": {"type": "string"}, | ||
"tag": {"type": "string"}, | ||
}, | ||
} | ||
}, | ||
} | ||
validator = OAS30Validator(schema, format_checker=oas30_format_checker) | ||
validator.validate(None) | ||
|
||
def test_allof_required(self): | ||
schema = { | ||
"allOf": [ | ||
|
@@ -211,6 +265,20 @@ def test_allof_required(self): | |
): | ||
validator.validate({"another_prop": "bla"}) | ||
|
||
@pytest.mark.xfail(reason="Issue #20") | ||
def test_allof_nullable(self): | ||
schema = { | ||
"allOf": [ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This subschema is invalid (not nullable). That means the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. |
||
"type": "object", | ||
"properties": {"some_prop": {"type": "string"}}, | ||
}, | ||
{"type": "object", "nullable": True}, | ||
] | ||
} | ||
validator = OAS30Validator(schema, format_checker=oas30_format_checker) | ||
validator.validate(None) | ||
|
||
def test_required(self): | ||
schema = { | ||
"type": "object", | ||
|
@@ -439,7 +507,7 @@ def test_oneof_discriminator(self, schema_type): | |
ValidationError, | ||
match="reference '#/components/schemas/other' could not be resolved", | ||
): | ||
result = validator.validate({"discipline": "other"}) | ||
validator.validate({"discipline": "other"}) | ||
assert False | ||
|
||
|
||
|
@@ -452,10 +520,13 @@ class TestOAS31ValidatorValidate: | |
"integer", | ||
"number", | ||
"string", | ||
"object", | ||
], | ||
) | ||
def test_null(self, schema_type): | ||
schema = {"type": schema_type} | ||
if schema_type == "object": | ||
schema["properties"] = {"some_prop": {"type": "string"}} | ||
validator = OAS31Validator(schema) | ||
value = None | ||
|
||
|
@@ -470,10 +541,13 @@ def test_null(self, schema_type): | |
"integer", | ||
"number", | ||
"string", | ||
"object", | ||
], | ||
) | ||
def test_nullable(self, schema_type): | ||
schema = {"type": [schema_type, "null"]} | ||
if schema_type == "object": | ||
schema["properties"] = {"some_prop": {"type": "string"}} | ||
validator = OAS31Validator(schema) | ||
value = None | ||
|
||
|
@@ -653,7 +727,7 @@ def test_schema_validation(self): | |
error = "'-12' is not a 'date'" | ||
assert error in str(excinfo.value) | ||
|
||
def test_schema_ref(self): | ||
def test_ref(self): | ||
schema = { | ||
"$ref": "#/$defs/Pet", | ||
"$defs": { | ||
|
@@ -681,6 +755,28 @@ def test_schema_ref(self): | |
error = "'id' is a required property" | ||
assert error in str(excinfo.value) | ||
|
||
def test_ref_nullable(self): | ||
# specifying an array for type only works with primitive types | ||
schema = { | ||
"oneOf": [ | ||
{"type": "null"}, | ||
{"$ref": "#/$defs/Pet"}, | ||
], | ||
"$defs": { | ||
"Pet": { | ||
"type": "object", | ||
"required": ["id", "name"], | ||
"properties": { | ||
"id": {"type": "integer", "format": "int64"}, | ||
"name": {"type": "string"}, | ||
"tag": {"type": "string"}, | ||
}, | ||
} | ||
}, | ||
} | ||
validator = OAS31Validator(schema, format_checker=oas30_format_checker) | ||
validator.validate(None) | ||
|
||
@pytest.mark.parametrize( | ||
"value", | ||
[ | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[tox] | ||
minversion = 3.18.0 | ||
requires = tox-poetry | ||
|
||
[testenv] | ||
extras = | ||
rfc3339-validator | ||
strict-rfc3339 | ||
isodate | ||
commands = | ||
pytest {posargs:tests/} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subschema is invalid (not nullable). That means the whole allof should be invalid isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it? I'd have expected the reference this to flatten to:
which would in-turn flatten to:
Is my understanding incorrect? It might well be! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, wait, I see your top-level comment now.
So this being the case, I wonder if the schemas should be outright rejected as invalid?