Skip to content

Represent empty responses as None #770

Description

@cornerman

When I specify no content for a response, I would expect to generate a sync method and async method that returns None.

Currently, I work against an api that has a few endpoints returning no data (that could be with status code 200 or status code 204).
Example:

   "/something" : {
      "patch" : {
        ...
        "responses" : {
          "200" : {
            "description" : "something"
          }
        }
      }
    }

When I generate a client with this project, this endpoint will not have a sync or async method, but only the sync_detailed and async_detailed. This works, but it looks weird because for all other methods I use sync/async. I would be great to have them implemented to return None (like a void/unit method in python).

I think, the problem manifests here:

{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %}

The sync method is only generated if the return type is not any - which makes sense. But I think, the return type here is not actually Any - but None. The response type comes from here:

Here is a link with documentation on handling empty responses and any type: https://swagger.io/docs/specification/data-models/data-types/

According to that, the difference is having either no content field for empty responses and having a content field defined with an empty object for any type.

Activity

  1. dbanty commented on Jul 7, 2023

    @dbanty
    Collaborator

    I think the trouble here is that there would be no easy way to tell whether or not a request had failed from the non-detailed method unless you set raise_on_unexpected_status to True in the client. It seems like that would provide an easy way for API consumers to accidentally miss failures, unless I'm missing something.

  2. added and removed
    🐞bugSomething isn't working
    on Jul 7, 2023
  3. locked and limited conversation to collaborators on Aug 13, 2023
  4. converted this issue into a discussion #799 on Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions