Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1138 - Add support for generic types such as List[Object] #1139

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions robyn/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ def get_schema_object(self, parameter: str, param_type: Any) -> dict:
properties["type"] = type_mapping[type_name]
return properties

# Check if it's a generic type (like List[Object])
if hasattr(param_type, "__origin__"):
if param_type.__origin__ is list or param_type.__origin__ is List:
properties["type"] = "array"
# Handle the element type in the list
if hasattr(param_type, "__args__") and param_type.__args__:
item_type = param_type.__args__[0]
properties["items"] = self.get_schema_object(f"{parameter}_item", item_type)
return properties

# check for Optional type
if param_type.__module__ == "typing":
properties["anyOf"] = [{"type": self.get_openapi_type(param_type.__args__[0])}, {"type": "null"}]
Expand Down
Loading