Closed
Description
Describe the bug
I received warning when trying to generate client for example OpenAPI (see below).
ERROR parsing POST /foo/{bar} within default. Endpoint will not be generated.
Could not reconcile duplicate parameters named bar
OAS says A unique parameter is defined by a combination of a name and location.
See question in specification repo.
it's OK to have parameters with the same name as long as they have different location (i.e. path vs header).
To Reproduce
Steps to reproduce the behavior:
- Run generation for example OpenAPI (see below).
- See warnings in cli.
- See
post_foo_bar.py
module not generated.
Expected behavior
Expected two different parameters in generated client. Parameter bar
in POST method must be overridden.
# Generated `post_foo_bar.py`
...
def _get_kwargs(
*,
client: Client,
bar_path: str = "OVERRIDDEN_WITH_DEFAULT_VALUE", # from `Operation`
json_body: str,
bar_header: Union[Unset, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/foo/{bar}".format(client.base_url, bar=bar_path)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
if bar_header is not UNSET:
headers["bar"] = bar_header
...
# Generated delete_foo_bar.py
...
def _get_kwargs(
*,
client: Client,
bar_path: str, # from `PathItem`
) -> Dict[str, Any]:
...
OpenAPI Spec File
openapi: 3.0.3
info:
title: Parameters example
version: 1.0.0
servers:
- url: 'https://example.com/api/rest'
paths:
'/foo/{bar}':
post:
parameters:
- name: bar
required: true
in: path
schema:
type: string
default: OVERRIDDEN_WITH_DEFAULT_VALUE
- name: bar
in: header
schema:
type: string
requestBody:
content:
application/json:
schema:
type: string
responses:
'200':
description: Example
content:
application/json:
schema:
type: string
delete:
responses:
'200':
description: OK
parameters:
- required: true
name: bar
in: path
schema:
type: string
Desktop (please complete the following information):
- OS: [e.g. macOS 10.15.1] Windows 10
- Python Version: [e.g. 3.8.0] 3.9.2
- openapi-python-client version [e.g. 0.1.0] 0.10.1
Additional context
I wrote a fix for this issue. I want to test it and make PR soon. @dbanty what do you think about it?