Skip to content

PathItem parameters overriding in Operation #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mtovts opened this issue Jul 22, 2021 · 1 comment
Closed

PathItem parameters overriding in Operation #457

mtovts opened this issue Jul 22, 2021 · 1 comment
Labels
🐞bug Something isn't working
Milestone

Comments

@mtovts
Copy link
Contributor

mtovts commented Jul 22, 2021

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:

  1. Run generation for example OpenAPI (see below).
  2. See warnings in cli.
  3. 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?

@dbanty
Copy link
Collaborator

dbanty commented Aug 15, 2021

Will be included in 0.10.2

@dbanty dbanty closed this as completed Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants