Skip to content

Commit

Permalink
Update openapi.py
Browse files Browse the repository at this point in the history
fix openapi handling of None return type
  • Loading branch information
modularizer authored May 7, 2024
1 parent 8247d64 commit 12fd831
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/socketwrench/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ def openapi_schema(routes_dict):
except:
pass
if return_type is not inspect._empty:
if return_type is Path or issubclass(return_type, Path) or return_type is FileResponse or issubclass(return_type, FileResponse):
if return_type is None:
route_info["responses"] = {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {"type": "object"}
}
}
}
}
elif return_type is Path or issubclass(return_type, Path) or return_type is FileResponse or issubclass(return_type, FileResponse):
content_type = getattr(return_type, "default_content_type", "application/octet-stream")
route_info["responses"] = {
"200": {
Expand Down Expand Up @@ -149,4 +160,4 @@ def openapi_schema(routes_dict):
openapi["paths"][route_name] = {}
for method in allowed_methods:
openapi["paths"][route_name][method.lower()] = route_info
return openapi
return openapi

0 comments on commit 12fd831

Please sign in to comment.