Represent empty responses as None #799
cornerman
started this conversation in
Feature request
Replies: 1 comment
-
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 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I specify no content for a response, I would expect to generate a
sync
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:
When I generate a client with this project, this endpoint will not have a
sync
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:
openapi-python-client/openapi_python_client/templates/endpoint_module.py.jinja
Line 18 in 4823d96
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:openapi-python-client/openapi_python_client/parser/openapi.py
Line 525 in 4823d96
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 acontent
field defined with an empty object for any type.Beta Was this translation helpful? Give feedback.
All reactions