Skip to content

Parameters always required when created by reference #730

Closed
@deceitfulsteve

Description

@deceitfulsteve

Describe the bug
All parameters defined via reference (introduced in #653) are marked as required.

In the current version of openapi.json, we have this definition:

...
    "/parameter-references/{path_param}": {
...
        "parameters": [
          {
            "$ref": "#/components/parameters/string-param"
          },
...
  "components": {
...
    "parameters": {
...
      "string-param": {
        "name": "string param",
        "in": "query",
        "required": false,
        "style": "form",
        "explode": true,
        "schema": {
          "type": "string"
        }
      },
...

which generates this code in get_parameter_references_path_param.py:

...
def _get_kwargs(
    path_param: str,
    *,
    client: Client,
    string_param: str,
...

but it should instead look like:

...
def _get_kwargs(
    path_param: str,
    *,
    client: Client,
    string_param: Union[Unset, None, str] = UNSET,
...

To Reproduce

Steps to reproduce the behavior:

  1. Define a parameter as a reference (e.g. as under /parameter-references/{path_param})
  2. In the components section, indicate that our parameter is not required (e.g. the one referenced by "#/components/parameters/string-param")
  3. Generate the API
  4. Notice that the parameter is nevertheless required.

Expected behavior
In general, parameters defined through a reference should be required if and only if their definition in the components section indicates that they're required.

OpenAPI Spec File
https://github.com/openapi-generators/openapi-python-client/blob/f741d8165d713eeb629e839fadc8920209ccfec3/end_to_end_tests/openapi.json

Desktop (please complete the following information):

  • OS: macOS 12.6.2
  • Python Version: 3.10.2
  • openapi-python-client version: 0.13.1

Additional context
I have a small fix which seems to address this.

However, that change calls into question a couple of the arguments to the function parameter_from_data and some associated tests. Given what we know about the guarantees around arguments passed to that function, I also have another branch with a few deletions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions