flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

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

Open hjmallon opened this issue 1 year ago • 2 comments

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={}
    ):

hjmallon avatar Apr 15 '24 08:04 hjmallon

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

peter-doggart avatar Jul 24 '24 15:07 peter-doggart

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

hjmallon avatar Jul 24 '24 15:07 hjmallon