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

response.unmarshal_response should not return None if a validate_responses is False #229

Open
explody opened this issue Nov 29, 2017 · 1 comment

Comments

@explody
Copy link

explody commented Nov 29, 2017

After a bit of digging, I found that a "None" response I was getting from an API was a result of this snippet in bravado_core/response.py:

    response_spec = get_response_spec(response.status_code, op)

    def has_content(response_spec):
        return 'schema' in response_spec

    if not has_content(response_spec):
        return None

The swagger json from this particular API declares return codes, but does not fully define the response spec:

                "responses": {
                    "200": {
                        "description": ""
                    }
                }
  • The response definition without defining content is not technically invalid - the swagger spec validates at swagger.io and w/ 3rd party tools. (that being said, I understand that an empty response schema basically says it response should be empty, but that leads to the next point)
  • As a user of 3rd party APIs over which I have no control, it would be really great to have more control over how my client lib handles responses, so as to work around situations like these, which are painfully common.
  • At least one common swagger framework which is plaguing me just doesn't support response schemas at all (yet): Schema generation doesn't support response schemas encode/django-rest-framework#4502

Perhaps most importantly, IMHO:

  • If combined with validate_reponses: False, enforcing a schema for the response serves no purpose since we don't need a schema if we're not validating the response content, ergo why would a defined schema be required?

My suggested change would be simple - if validate_responses is False, simply ignore the response schema, whether it's there or not, and return the response as is currently done for non-JSON replies.

Thoughts?

@macisamuele
Copy link
Collaborator

unmarshal_response takes care of converting the received response into a python object.
The method returns None because the specs does not specify any content of the response, so from a spec prospective the response body "does not exists".

So a possible workaroud could be to manually extract the response body in case unmarshal_response is None.

I immagine that you're ending up in that call due to bravado, if so bravado has a request option that allows you to receive the marshaled response and the raw response, here is the doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants