Code Monkey home page Code Monkey logo

Comments (13)

xiaoymin avatar xiaoymin commented on May 24, 2024

虽然你提了问题,但是我不知道提了什么问题。作者如何复现?

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

假设我定义一个接口返回类型,字段 data是泛型

public class ApiBaseDTO<T> implements Serializable {

    private int code;

    private String msg;

    private String extra;

    private boolean success;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime time = LocalDateTime.now();

    private T data;
}

然后,在控制器定义返回类型:

接口A:

    @Operation(summary = "获取详情")
    @GetMapping("/getOneDetailById")
    ApiBaseDTO<Entity1> getOneDetailById(@RequestParam(required = false) Integer id) {
        return entity1Service.getOneDetailById(id);
    }

接口B:

    @Operation(summary = "获取详情")
    @GetMapping("/getOneDetailById")
    ApiBaseDTO<Entity2> getOneDetailById(@RequestParam(required = false) Integer id) {
        return entity2Service.getOneDetailById(id);
    }

在渲染的文档中,所有接口的data字段的Schema都是同一个,且随机。
原来的Spring Boot 2.7 + knife4j-spring-boot-starter 3.0.3则是正常的。

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

微信图片_20240315110402

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024

demo无法复现

https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/tree/ac55f7d3583596b22bcf8c2876acd03fd5e094f2/knife4j-springdoc-openapi-demo

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024
image image image

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024
image image

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

我出现问题是 Spring Boot3版本,我的Spring Boot 2.7.18也是正常的。

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

我把项目中多余内容删除,可以复现问题:

https://gitee.com/jiankian/knife4j-v4-spring-boot-v3-demo/blob/master/src/main/java/com/binfei/yjs/server/controller/HelloController.java

所有接口的data字段的schema都是同一个,本该是不同的schema

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

降级到 Spring Boot 2.7.18也会有问题,带 jakarta的依赖的版本就有此问题

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024

https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/tree/ac55f7d3583596b22bcf8c2876acd03fd5e094f2/knife4j-springdoc-openapi-demo

上面的例子就是2.7.18版本,正常的

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024

Spring Boot 3.2.3

Knife4j 4.5.0

基于你给的代码也没测出来

https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/blob/bb3d4d39b4967876cf1a774b28a5cc156a25f981/knife4j-spring-boot3-demo/src/main/java/com/github/xiaoymin/boot3/web/Simple1Controller.java

from knife4j.

xiaoymin avatar xiaoymin commented on May 24, 2024

@Schema注解的作用是重命名,条件是必须全局唯一,这种场景下,在泛型类上面用这个注解是不合适的,需要去掉

@Slf4j
@Data
public class ApiBaseDTO<T> implements Serializable {
  //....
}

from knife4j.

jiankian avatar jiankian commented on May 24, 2024

好的,已解决,谢谢

from knife4j.

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.