jmcarp / jmcarp/flask-apispec

Error when I register multiple functions

Open
#155 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
652
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Hi,

I can't register multiple functions.
`apispec.exceptions.DuplicateParameterError: Duplicate parameter with name body and location body` error occurred.

```

docs.register(foo, blueprint=base_bp.name)
docs.register(bar, blueprint=base_bp.name)

```

These are my endpoints.
```

from flask import Blueprint
from flask_apispec import doc, use_kwargs
from flask_restful import fields, marshal_with
import marshmallow as m

base_bp = Blueprint(
"base",
__name__,
url_prefix="/base"
)

request_fields = {
'name': m.fields.Str(required=True),
'address': m.fields.Str()
}

response_fields = {
'name': fields.String,
'address': fields.String,
'id': fields.Integer
}

def db_get_info(id):
return dict(name="hello", address="world", id=id)

def db_get_info2(name, address=None, id=3):
return dict(name=name, address=address, id=id)

@base_bp.route("/", methods=["GET"])
@doc(params={'id': {'description': 'test id'}})
@marshal_with(response_fields, envelope='resource')
def foo(id):
return db_get_info(id)

@base_bp.route("/params", methods=["GET"])
@doc(params={'name': {'aa': 'name'}, 'address': {'bb': 'address'}})
@use_kwargs(request_fields)
@marshal_with(response_fields, envelope='resource')
def bar(**kwargs):
return db_get_info2(**kwargs)

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue using the shown Blueprint, foo and bar endpoints, and the two docs.register calls. Start by tracing registration and parameter generation in the library; done means both functions register successfully without a DuplicateParameterError.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.