You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SyntaxError: Parameters with the same name but different locations #305
If you have two parameters with the same name but different locations (in), the generated client has a function with repeated variable names which is a Python syntax error. The OpenAPI spec requires parameters to be unique only on (name, location), so this is a bug.
In my case, the spec was a result of using a very standard Django Rest Framework ModelViewSet (which added the path parameter) with a django_filters.FilterSet (which added the query parameter).
EDIT: Perhaps my specific case should be fixed in django-filters... Maybe those filter parameters shouldn't be added to actions other than list.
The result has this function (among others) which don't distinguish between the parameters and are thus Python syntax errors:
# in test-client/test_client/api/default/retrieve_pet.pydef_get_kwargs(
*,
client: Client,
name: str,
name: Union[Unset, str] =UNSET, # <-- a duplicate `name` variable which leads to a syntax error
) ->Dict[str, Any]:
url="{}/pets/{name}/".format(
client.base_url,name=name)
headers: Dict[str, Any] =client.get_headers()
Expected behavior
I'm not sure the best way to handle this. openapi-generator does so by suffixing duplicate parameter names with integers. E.g., the arguments to its endpoint functions are name for the path parameter and name2 for the query parameter.
Desktop (please complete the following information):
Ick... yeah that's definitely a thing we need to do something about. My initial thought is to suffix the names with the location in the event of a conflict. So in your example it would change them to name_path and name_query. Not the most elegant thing, but I can't think of a solution that is particularly elegant.
Activity
dbanty commentedon Jan 18, 2021
Ick... yeah that's definitely a thing we need to do something about. My initial thought is to suffix the names with the location in the event of a conflict. So in your example it would change them to name_path and name_query. Not the most elegant thing, but I can't think of a solution that is particularly elegant.
Thanks for reporting this issue!
fix(parser): Attempt to deduplicate endpoint parameters based on name…
fix(parser): Attempt to deduplicate endpoint parameters based on name…