Skip to content

OpenAPI 文档生成器无法正确处理泛型类型(如 List[Object]) #1138

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

Open
yzutyc opened this issue Mar 6, 2025 · 0 comments · May be fixed by #1139
Open

OpenAPI 文档生成器无法正确处理泛型类型(如 List[Object]) #1138

yzutyc opened this issue Mar 6, 2025 · 0 comments · May be fixed by #1139
Labels
bug Something isn't working

Comments

@yzutyc
Copy link

yzutyc commented Mar 6, 2025

Bug Description

在 Robyn 框架的 OpenAPI 文档生成功能中,发现了一个与泛型类型处理相关的 bug。当 API 端点返回或接收包含泛型类型(如 List[Object] )的参数时,OpenAPI 规范生成不正确,导致 Swagger UI 无法正确显示这些类型。

Steps to Reproduce

  • 创建一个返回 List[Object] 类型的 API 端点
  • 访问 /docs 查看生成的 Swagger 文档
  • 观察返回类型的描述,会发现泛型类型未被正确处理

Your operating system

Windows

Your Python version (python --version)

3.11

Your Robyn version

latest

Additional Info

问题出现在 openapi.py 文件的 get_schema_object 方法中,大约在第 397行。需要添加对泛型类型的处理逻辑。

检查是否为泛型类型(如List[Object])

if hasattr(param_type, "__origin__"):
    if param_type.__origin__ is list or param_type.__origin__ is List:
        properties["type"] = "array"
        # 处理列表中的元素类型
        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

@yzutyc yzutyc added the bug Something isn't working label Mar 6, 2025
@yzutyc yzutyc marked this as a duplicate of #1137 Mar 6, 2025
@sansyrox sansyrox linked a pull request Mar 17, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant