Yelp / bravado-core

Other
109 stars 98 forks source link

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

Open explody opened 6 years ago

explody commented 6 years ago

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": ""
                    }
                }

Perhaps most importantly, IMHO:

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 commented 6 years ago

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.