Open NotJustPizza opened 6 years ago
Looks like a bug to me. PRs welcome!
This can be solved by replacing
schemas = utils.merge_recursive(annotation.options)
schema = schemas.get(status_code, schemas.get('default'))
if schema and annotation.apply is not False:
schema = utils.resolve_schema(schema['schema'], request=flask.request)
dumped = schema.dump(unpacked[0])
output = dumped.data if MARSHMALLOW_VERSION_INFO[0] < 3 else dumped
else:
output = unpacked[0]
return format_output((format_response(output),) + unpacked[1:])
from wrapper.py
, with
options = utils.merge_recursive(annotation.options)
option = options.get(status_code, options.get('default'))
if option:
schema = utils.resolve_schema(option['schema'], request=flask.request)
else:
schema = None
if schema and annotation.apply is not False:
dumped = schema.dump(unpacked[0])
output = dumped.data if MARSHMALLOW_VERSION_INFO[0] < 3 else dumped
else:
output = unpacked[0]
return format_output((format_response(output), ) + unpacked[1:])
The problem is that the code only checks whether there is a response defined for the current request, and not whether this definition actually contains a valid schema.
I'd submit a PR, but I'm having trouble adding a test for this code as Webtest complains about having a 204 response without a content-length header.
Let me know what you think.
It seems like #101 fixes this, but it hasn't been merged.
In docs (https://flask-apispec.readthedocs.io/en/latest/usage.html) we can find this example:
I tried same, but using function-based views, examples:
It works with "@marshal_with(MyShema, code=204)", but never with None as first parameter.
//Edit
Workaround is to define empty schema:
and use: