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

Support for polymorphic return display. #614

Open
jackmiking opened this issue Sep 22, 2023 · 9 comments
Open

Support for polymorphic return display. #614

jackmiking opened this issue Sep 22, 2023 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@jackmiking
Copy link

jackmiking commented Sep 22, 2023

A parent class may have multiple subclasses as a return type, and based on the value of a field, different subclasses will be returned.
一个父类返回可能会有多种子类,根据一个字段值,对应不同的子类

@jackmiking jackmiking added the enhancement New feature or request label Sep 22, 2023
@abing22333
Copy link
Contributor

abing22333 commented Sep 22, 2023

Smart-Doc scans static code and does not have the ability to dynamically obtain field values.
smart-doc扫描的是静态代码,没有动态获取字段值的能力。

@jackmiking
Copy link
Author

jackmiking commented Sep 22, 2023 via email

@shalousun
Copy link
Collaborator

shalousun commented Sep 22, 2023

Smart-Doc scans static code and does not have the ability to dynamically obtain field values.
smart-doc扫描的是静态代码,没有动态获取字段值的能力。

Swagger should also not be able to support it.
swagger应该也不能支持

@jackmiking
Copy link
Author

jackmiking commented Sep 22, 2023

Swagger has the logic of oneOf, and the subclasses themselves are static.
swagger是有oneOf的逻辑得, 子类本身是静态的,

@jackmiking
Copy link
Author

image
类似这样

@jackmiking
Copy link
Author

jackmiking commented Sep 22, 2023

Jackson also has the @JsonSubTypes annotation that can be declared on a parent class. The logic is almost the same; it checks if the current class has the @JsonSubTypes annotation, reads the list of @JsonSubTypes.Type from it, and converts the list into a structure similar to oneOf?
jackson也会有注解声明 @JsonSubTypes 在这个父类上面。逻辑差不多是判断当前类注解上有@JsonSubTypes 读取@JsonSubTypes上的@JsonSubTypes.Type列表,得到列表转换成oneOf类似的结构?

@shalousun
Copy link
Collaborator

shalousun commented Sep 24, 2023

Jackson also has the @JsonSubTypes annotation that can be declared on a parent class. The logic is almost the same; it checks if the current class has the @JsonSubTypes annotation, reads the list of @JsonSubTypes.Type from it, and converts the list into a structure similar to oneOf?
jackson也会有注解声明 @JsonSubTypes 在这个父类上面。逻辑差不多是判断当前类注解上有@JsonSubTypes 读取@JsonSubTypes上的@JsonSubTypes.Type列表,得到列表转换成oneOf类似的结构?

We'll take a look later, but it might be difficult to support this in the short term. The implementation should not be difficult, but the existing data structure needs optimization to support this feature.
后面我们看下,不过这个短期可能支持有困难,实现应该不难,主要现有数据结构支持这个问题

@shalousun shalousun changed the title 支持多态的返回展示 Support for polymorphic return display. Mar 10, 2024
@shaunhurryup
Copy link

Is it possible to define multiple return values in a Controller? In many business cases, such as when an ID doesn't exist in the database, the server should respond with HTTP Status 200 and an error code like 10001

Success

HTTP Status 200

{
  "code": 0,
  "data": {
    "type": "electronics",
    "id": "65669ce3c684f6144ce5cf5f",
    "name": "iPhone 15 Pro Max"
  },
  "msg": "success",
  "msg_cn": ""
}

Fail

HTTP Status 200

{
    "msg": "Record Not Found",
    "code": 10001,
    "msg_cn": "未找到记录"
}

@jackmiking
Copy link
Author

jackmiking commented May 30, 2024 via email

@linwumingshi linwumingshi added this to the 3.0.8 milestone Aug 16, 2024
@linwumingshi linwumingshi modified the milestones: 3.0.8, 3.0.9 Sep 16, 2024
@linwumingshi linwumingshi modified the milestones: 3.0.9, 3.1.0 Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants