0

Whenever I try to define an argument in reqparse object, using the flask_restx.inputs.email type and decorate the method via api.expect; Flask-Restx fails to create the Swagger doc.

Example code:

@api.route("/route")
class View(Resource):

    parser = reqparse.RequestParser()
    parser.add_argument("email", type=inputs.email)
    
    @api.expect(parser)
    def post(self):
        ...

The error on the Swagger docs page

Python's Error:

Unable to render schema
Traceback (most recent call last):
  File "\venv\lib\site-packages\flask_restx\api.py", line 571, in __schema__
    self._schema = Swagger(self).as_dict()
  File "\venv\lib\site-packages\flask_restx\swagger.py", line 239, in as_dict
    serialized = self.serialize_resource(
  File "\venv\lib\site-packages\flask_restx\swagger.py", line 438, in serialize_resource
    doc = self.extract_resource_doc(resource, url, route_doc=route_doc)
  File "\venv\lib\site-packages\flask_restx\swagger.py", line 343, in extract_resource_doc
    method_params = self.expected_params(method_doc)
  File "\venv\lib\site-packages\flask_restx\swagger.py", line 382, in expected_params
    (p["name"], p) for p in expect.__schema__ if p["in"] != "body"
  File "\venv\lib\site-packages\flask_restx\reqparse.py", line 435, in __schema__
    param = arg.__schema__
  File "\venv\lib\site-packages\flask_restx\reqparse.py", line 291, in __schema__
    _handle_arg_type(self, param)
  File "\venv\lib\site-packages\flask_restx\reqparse.py", line 451, in _handle_arg_type
    param.update(arg.type.__schema__)
TypeError: 'property' object is not iterable

I can use Python's builtin types, other types on Restx's inputs or my own custom type without any issues.

Is there anything I am doing wrong or not aware of? Thanks.

s3lcuk
  • 1

1 Answers1

0

I've found the solution:

Changing inputs.email to inputs.email() resolved the issue.

I assume it is because email is a class based validator rather than a function.

s3lcuk
  • 1