python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

@api.marshal_with is meant to support headers but gets unexpected keyword argument #601

Open hjmallon opened 4 months ago

hjmallon commented 4 months ago
class World(Resource):
    @api.marshal_with(bay_model, headers={"x-my-header": "description"})
    def get(self, id):
        reuturn {"hello": "world"}

Repro Steps (if applicable)

  1. Use a response specific header with marshal_with
  2. Get an unexpected keyword argument error

Expected Behavior

Make a response specific header doc

Actual Behavior

Raises error

Error Messages/Stack Trace

    return marshal_with(fields, ordered=self.ordered, **kwargs)(func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: marshal_with.__init__() got an unexpected keyword argument 'headers'

Possible fix?

I think it can be fixed by adding headers={} to __init__ in marshal_with.

def __init__(
        self, fields, envelope=None, skip_none=False, mask=None, ordered=False, headers={}
    ):
peter-doggart commented 1 month ago

Hi @hjmallon When you say meant to support headers, can you point to where this is documented? Having trouble finding it!

hjmallon commented 1 month ago

I dont think it is documented, but it is mostly implemented. See:

https://github.com/python-restx/flask-restx/blob/29dd1fa9ecbda442345c43c982ee80f8ee484ad8/flask_restx/swagger.py#L613

As I say it is just that tiny change away from working as far as I can tell