Description
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 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
.
To Reproduce
Generate a client with this spec:
openapi: 3.0.2
info:
title: test
version: "0.0.0"
paths:
/pets/{name}/:
get:
operationId: retrievePet
parameters:
- name: name
required: true
in: path
schema:
type: string
- name: name
in: query
required: false
schema:
type: string
responses:
"200":
description: pet response
content:
application/json:
schema:
type: string
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.py
def _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