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
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):
Python version: 3.6.4
openapi-python-client version: 0.7.3
The text was updated successfully, but these errors were encountered:
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.
… and location (fixes#305) (#406)
* fix(parser): Attempt to deduplicate endpoint parameters based on name and location (fixes#305)
* refactor: Use location prefix for all duplicate params
Describe the bug
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 adjango_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 thanlist
.To Reproduce
Generate a client with this spec:
The result has this function (among others) which don't distinguish between the parameters and are thus Python syntax errors:
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 arename
for the path parameter andname2
for the query parameter.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: