Git Product home page Git Product logo

Comments (13)

yizhitangtongxue avatar yizhitangtongxue commented on August 17, 2024

同求

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

目前是支持Map解析范型的,对于Map<T, User>可以会生成KEY的字段,里面包含了User相关字段信息

from apidocx.

yizhitangtongxue avatar yizhitangtongxue commented on August 17, 2024

目前是支持Map解析范型的,对于Map<T, User>可以会生成KEY的字段,里面包含了User相关字段信息

public class Response extends HashMap<String, Object>

请问这种返回值能否支持文档展示

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

请问期望怎么展示了?目前这种情况就是一个object类型

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

目前是支持Map解析范型的,对于Map<T, User>可以会生成KEY的字段,里面包含了User相关字段信息

public class Response extends HashMap<String, Object>

请问这种返回值能否支持文档展示

是Response里定义了字段,但是解析不出来吗?

from apidocx.

gclm avatar gclm commented on August 17, 2024

我也遇到类似问题了,目前我们使用ApiResult 包装了Task对象。解析效果如下图所示,目前针对这个情况,我个人感觉是如何通过注解或者其他方案把保证把Task对象正确展示出来,因为目前springboot一般会封装统一的返回。所以针对但是目前解析出来的都是object对象,而不是具体的对象

image
image

from apidocx.

gclm avatar gclm commented on August 17, 2024

目前已经尝试过使用 @return {@link Task} 发现根本不行

ApiResult 数据结构

public class ApiResult {

    /**
     * 响应状态码
     */
    @ApiModelProperty(value = "响应状态码", required = true)
    @Schema(description = "响应状态码", required = true)
    private Integer code;

    /**
     * 响应提示
     */
    @ApiModelProperty(value = "响应提示消息", required = true)
    @Schema(description = "响应提示消息", required = true)
    private String message;

    /**
     * 响应时间戳
     */
    @ApiModelProperty(value = "响应时间戳", required = true)
    @Schema(description = "响应时间戳", required = true)
    private String timestamp = String.valueOf(DateUtils.getTime());

    /**
     * 响应数据
     */
    @ApiModelProperty(value = "响应数据")
    @Schema(description = "响应数据")
    private Object data;

    public ApiResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

目前已经尝试过使用 @return {@link Task} 发现根本不行

ApiResult 数据结构

public class ApiResult {

    /**
     * 响应状态码
     */
    @ApiModelProperty(value = "响应状态码", required = true)
    @Schema(description = "响应状态码", required = true)
    private Integer code;

    /**
     * 响应提示
     */
    @ApiModelProperty(value = "响应提示消息", required = true)
    @Schema(description = "响应提示消息", required = true)
    private String message;

    /**
     * 响应时间戳
     */
    @ApiModelProperty(value = "响应时间戳", required = true)
    @Schema(description = "响应时间戳", required = true)
    private String timestamp = String.valueOf(DateUtils.getTime());

    /**
     * 响应数据
     */
    @ApiModelProperty(value = "响应数据")
    @Schema(description = "响应数据")
    private Object data;

    public ApiResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

这里data字段应该改为泛型,然后再控制方法使用 ApiResult就可以展示出T的具体类型

from apidocx.

gclm avatar gclm commented on August 17, 2024

OK。

from apidocx.

gclm avatar gclm commented on August 17, 2024

@lkqm 我们团队内部已经沟通了,因为目前ApiResult 引用的项目太多了,如果修改成泛型,改动影响比较大。大佬你看能不能改成数据从@return {https://github.com/link Task} 获取,不过他的优先级比使用泛型的优先级低呢或者新增一个静态配置,只有设置这个配置,才会使用@return {https://github.com/link Task} 获取相应呢?

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

@gclm 改成泛型不会影响调用方的,默认不传泛型就会当作Object类型。另外你说的方案主要问题在于对于插件来说不知道ApiResult.data需要被return指定的替换,虽然可以通过配置来实现,但是这样使用从你的场景来看没有必要这样做。

from apidocx.

gclm avatar gclm commented on August 17, 2024

目前是会影响到调用方的,目前我们调用已经封装成这样了,如果穿泛型的话,目前这个函数实例化就是一个问题。我一会先看看目前插件的代码?如果你这边暂时不好改的话,我fork一份,针对这个场景做个自定义主持吧。
image

from apidocx.

lkqm avatar lkqm commented on August 17, 2024

public class ApiResult {

/**
 * 响应状态码
 */
@ApiModelProperty(value = "响应状态码", required = true)
@Schema(description = "响应状态码", required = true)
private Integer code;

/**
 * 响应提示
 */
@ApiModelProperty(value = "响应提示消息", required = true)
@Schema(description = "响应提示消息", required = true)
private String message;

/**
 * 响应时间戳
 */
@ApiModelProperty(value = "响应时间戳", required = true)
@Schema(description = "响应时间戳", required = true)
private String timestamp = String.valueOf(DateUtils.getTime());

/**
 * 响应数据
 */
@ApiModelProperty(value = "响应数据")
@Schema(description = "响应数据")
private Object data;

public ApiResult(Integer code, String message, Object data) {
    this.code = code;
    this.message = message;
    this.data = data;
}

试试下面这种该法

public class ApiResult<T> {

    /**
     * 响应状态码
     */
    private Integer code;

    /**
     * 响应提示
     */
    private String message;

    /**
     * 响应时间戳
     */
    private String timestamp;

    /**
     * 响应数据
     */
    private T data;

    public ApiResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> ok(T data) {
        return new ApiResult<T>(200, "ok", data);
    }
}

from apidocx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.