Skip to content

Use Optional for Query Params Instead of Union[Unset, ...] #285

Closed
benchling/openapi-python-client
#40
@bowenwr

Description

@bowenwr

Is your feature request related to a problem? Please describe.

Although I'd like to keep Unset for body params, it makes a lot less sense for query params. I'd like non-required query params to return to the use of Optional.

While it would be inconsistent with the way we handle body params, I like that it encapsulates Unset (which is something of a workaround) more tightly.

Describe the solution you'd like

Given:

'/things':
    get:
      tags:
      - things
      operationId: getThings
      parameters:
      - name: size
        in: query
        schema:
          type: int

I'd like the signature to look like:

def sync_detailed(
    *,
    client: Client,
    size: Optional[int] = None,
) -> Response[Thing]:

Instead of:

def sync_detailed(
    *,
    client: Client,
    size: Union[Unset, int] = UNSET,
) -> Response[Thing]:

Describe alternatives you've considered

We have several endpoints with a large number of optional query params that default to None in the wrapping interface. Will probably just iterate the dict and assign Unset everywhere we have None now.

Additional context

I feel like I did this to myself having requested the original Unset feature. 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions