Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Represent empty responses as None#799

cornerman started this conversation inFeature request
Jun 4, 2023· 1 comments· 1 reply
Discussion options

When I specify no content for a response, I would expect to generate async method andasync method that returnsNone.

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 async orasync method, but only thesync_detailed andasync_detailed. This works, but it looks weird because for all other methods I usesync/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:

{%setparsed_responses = (endpoint.responses |length > 0)andreturn_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 actuallyAny - 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 nocontent field for empty responses and having acontent field defined with an empty object for any type.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

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 setraise_on_unexpected_status toTrue in the client. It seems like that would provide an easy way for API consumers to accidentally miss failures, unless I'm missing something.

You must be logged in to vote
1 reply
@estyrke
Comment options

It seems that somehow this got implemented along the way. It is indeed a bit scary that "success" and "unexpected status" return the same thing. Although thesync method of a "204" endpoint is typed asAny | HTTPValidationError | None, the "any" that is returned from _parse_response iscast("Any", None). I would very much have preferred if something else was returned, such as aNoContent sentinel object or something.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
✨ enhancementNew feature or improvement
3 participants
@cornerman@estyrke@dbanty
Converted from issue

This discussion was converted from issue #770 on August 13, 2023 00:22.


[8]ページ先頭

©2009-2025 Movatter.jp