DuplicateParameterException when using use_kwargs with OpenAPI 3
- Dominant language
- Python
- Stars
- 652
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
Whenever I try and use OpenAPI 3 with flask-apispec, using use_kwargs gives the error:
`apispec.exceptions.DuplicateParameterError: Duplicate parameter with name body and location body`.
Here is a minimal `app.py` to reproduce:
```python
from flask import Flask
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask_apispec import FlaskApiSpec, MethodResource, use_kwargs
from marshmallow import Schema, fields
app = Flask(__name__)
app.config['APISPEC_SPEC'] = APISpec('test', 'v1.0', '3.0', plugins=[MarshmallowPlugin()])
docs = FlaskApiSpec(app)
class TestSchema(Schema):
field1 = fields.Str()
field2 = fields.Str()
class TestResource(MethodResource):
@use_kwargs(TestSchema, locations=['json'])
def get(self, field1, field2):
return {'field1': field1, 'field2': field2}
app.add_url_rule('/', endpoint='testresource', view_func=TestResource.as_view('Test'))
docs.register(TestResource)
if __name__ == '__main__':
app.run()
```
Installed pakages:
```
apispec==3.0.0
Click==7.0
Flask==1.1.1
flask-apispec==0.8.3
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
marshmallow==3.2.1
six==1.12.0
webargs==5.5.2
Werkzeug==0.16.0
```
Output of `python3 app.py`:
```
Traceback (most recent call last):
File "app.py", line 21, in
docs.register(TestResource)
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/flask_apispec/extension.py", line 121, in register
resource_class_args, resource_class_kwargs)
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/flask_apispec/extension.py", line 68, in _defer
bound()
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/flask_apispec/extension.py", line 148, in _register
self.spec.path(**path)
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/apispec/core.py", line 267, in path
self.clean_operations(operations)
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/apispec/core.py", line 350, in clean_operations
operation["parameters"] = self.clean_parameters(operation["parameters"])
File "/home/natasha/.virtualenvs/flat/lib/python3.6/site-packages/apispec/core.py", line 318, in clean_parameters
parameter["name"], parameter["in"]
apispec.exceptions.DuplicateParameterError: Duplicate parameter with name body and location body
```
Please help, as I would really like to use OpenAPI 3.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the minimal app.py reproduction and the traceback through flask_apispec/extension.py, especially register and _register. Inspect how the OpenAPI 3 path reaches apispec's clean_parameters, then add regression coverage for use_kwargs with locations=['json']; done means docs.register completes without the duplicate body-parameter error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100