Skip to content

Commit

Permalink
More detailed allOf fail message
Browse files Browse the repository at this point in the history
  • Loading branch information
Stas Lipovenko authored and hh-h committed Mar 24, 2021
1 parent d601163 commit 10e9520
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

0.5.4 (dd-mm-yyyy)
------------------

- detailed error info for allOf

0.5.3 (14-01-2021)
------------------

Expand Down
5 changes: 1 addition & 4 deletions aiohttp_swagger3/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ def validate(self, raw_value: Any, raw: bool) -> Any:

value: Dict = {}
for validator in self.validators:
try:
value.update(validator.validate(raw_value, raw))
except ValidatorError:
raise ValidatorError("fail to validate allOf")
value.update(validator.validate(raw_value, raw))
return value


Expand Down
12 changes: 6 additions & 6 deletions tests/test_docs_request_bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,37 +786,37 @@ async def handler(request, body: Dict):
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"name": "required property"}}}

body = {"object": {"name": "string"}}
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"id": "required property"}}}

body = {"object": {"test": "value"}}
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"id": "required property"}}}

body = {"object": {"id": 10, "name": "string", "age": 10.1}}
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"age": "value should be type of int"}}}

body = {"object": {"rank": "321"}}
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"id": "required property"}}}

body = {"object": {"age": 15}}
resp = await client.post("/r", json=body)
assert resp.status == 400
error = error_to_json(await resp.text())
assert error == {"body": {"object": "fail to validate allOf"}}
assert error == {"body": {"object": {"id": "required property"}}}


async def test_array_in_object(swagger_docs, aiohttp_client):
Expand Down

2 comments on commit 10e9520

@eLvErDe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interresting ! Any hope such improvement could be added to oneOf ? ;-)

@hh-h
Copy link
Owner

@hh-h hh-h commented on 10e9520 Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, not. oneOf is a different thing.

Please sign in to comment.