flask-restx
flask-restx copied to clipboard
automatic swagger documentation fails when multiple locations provided to regparser
Code
class AsyncGenerate(Resource):
parser = reqparse.RequestParser()
parser.add_argument("prompt", type=str, required=True, help="The prompt to generate from")
parser.add_argument("api_key", type=str, required=True, help="The API Key corresponding to a registered user", location=['headers', 'json'])
parser.add_argument("params", type=dict, required=False, default={}, help="Extra generate params to send to the SD server")
parser.add_argument("servers", type=str, action='append', required=False, default=[], help="If specified, only the server with this ID will be able to generate this prompt")
@api.expect(parser)
def post(self, api_version = None):
Expected Behavior
The swagger API should renger my regparser requirements correctly
Actual Behavior
If I set the location
parameter of add_argument to a list of locations, the api.expect(parser)
errors
Error Messages/Stack Trace
2022-09-22 16:44:58,743 - ERROR - api:576 - Unable to render schema
Traceback (most recent call last):
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\api.py", line 571, in __schema__
self._schema = Swagger(self).as_dict()
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\swagger.py", line 239, in as_dict
serialized = self.serialize_resource(
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\swagger.py", line 438, in serialize_resource
doc = self.extract_resource_doc(resource, url, route_doc=route_doc)
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\swagger.py", line 343, in extract_resource_doc
method_params = self.expected_params(method_doc)
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\swagger.py", line 382, in expected_params
(p["name"], p) for p in expect.__schema__ if p["in"] != "body"
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\reqparse.py", line 435, in __schema__
param = arg.__schema__
File "C:\Users\Db0\AppData\Roaming\Python\Python310\site-packages\flask_restx\reqparse.py", line 290, in __schema__
param = {"name": self.name, "in": LOCATIONS.get(self.location, "query")}
TypeError: unhashable type: 'list'
Environment
- Python version: 3.10.0
- Flask version: 2.1.3
- Flask-RESTX version: 0.5.1
- Other installed Flask extensions: flask_limiter