Skip to content
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

Return raw response #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bravado_core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def has_content(response_spec):
content_value = umsgpack.loads(response.raw_bytes)
if op.swagger_spec.config['validate_responses']:
validate_schema_object(op.swagger_spec, content_spec, content_value)
if op.swagger_spec.config['return_raw_response']:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This config seems more related to "HTTP" handling and not swagger. I would suggest adding this into bravado implementation as request option so you could enable this behavior on per request base.

return content_value

return unmarshal_schema_object(
op.swagger_spec, content_spec, content_value)
Expand Down
3 changes: 3 additions & 0 deletions bravado_core/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
# Completely dereference $refs to maximize marshaling and unmarshaling performances.
# NOTE: this depends on validate_swagger_spec
'internally_dereference_refs': False,

# Skip call to unmarshal_schema_object and return raw decoded response.
'return_raw_response': False,
}


Expand Down
5 changes: 5 additions & 0 deletions docs/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ Config key Type Default Description
| to ``object`` and be validated as such.
| When set to ``False``, missing types will not be
| validated at all.
----------------------------- --------------- --------- ----------------------------------------------------
*return_raw_response* boolean False | When set to ``True``, the raw decoded response
| will be returned.
| When set to ``False``, the response will be
| unmarshalled according to the schema.
============================= =============== ========= ====================================================
18 changes: 18 additions & 0 deletions tests/response/unmarshal_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ def test_text_content(empty_swagger_spec, response_spec):
assert 'Monday' == unmarshal_response(response, op)


def test_raw_response(empty_swagger_spec, response_spec):
empty_swagger_spec.config['validate_responses'] = False
empty_swagger_spec.config['return_raw_response'] = True
return_value = object()
response = Mock(
spec=IncomingResponse,
status_code=200,
headers={'content-type': APP_JSON},
json=Mock(return_value=return_value))

with patch('bravado_core.response.unmarshal_schema_object') as unmarshal_schem:
with patch('bravado_core.response.get_response_spec') as m:
m.return_value = response_spec
op = Mock(swagger_spec=empty_swagger_spec)
assert return_value == unmarshal_response(response, op)
assert unmarshal_schem.call_count == 0


def test_skips_validation(empty_swagger_spec, response_spec):
empty_swagger_spec.config['validate_responses'] = False
response = Mock(
Expand Down