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

Rebar doesn't respect mime type setting #186

Open
serj-p opened this issue Jun 16, 2020 · 0 comments
Open

Rebar doesn't respect mime type setting #186

serj-p opened this issue Jun 16, 2020 · 0 comments

Comments

@serj-p
Copy link

serj-p commented Jun 16, 2020

I have an endpoint which returns pdf file. Thus I do something that converts into

registry.add_handler(*args, response_body_schema={200: None}, mimetype='application/pdf').
I want to say that normal reponse code is 200 and marshmallow schema is not applicable. (I used the same technique in order to return just string issue #184 )
later I get

 trace="Traceback (most recent call last):
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask_rebar/rebar.py", line 156, in wrapped
    data=data, status_code=status_code, headers=headers, mimetype=mimetype
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask_rebar/utils/request_utils.py", line 66, in response
    resp = jsonify(data) if data is not None else Response()
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask/json.py", line 263, in jsonify
    (dumps(data, indent=indent, separators=separators), '\n'),
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask/json.py", line 123, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/lib64/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib64/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/hub/core/json.py", line 16, in default
    return super(HubJSONEncoder, self).default(obj)
  File "/opt/opsta/hub-live/py/lib/python2.7/site-packages/flask/json.py", line 80, in default
    return _json.JSONEncoder.default(self, o)
  File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <Response streamed [200 OK]> is not JSON serializable
"

so rebar doesn't care that return content type is not a json, so there's no need to apply json serialization and it doesn't tell swagger that this endpoint returns pdf, but lies about json.

@serj-p serj-p changed the title Rebar doesn't respect content type setting Rebar doesn't respect mime type setting Jun 16, 2020
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

1 participant