feiniaojin / graceful-response

Spring Boot接口响应处理解决方案,提供统一返回值封装、全局异常处理、自定义异常错误码、参数校验增强、断言增强等功能
https://doc.feiniaojin.com
MIT License
1.09k stars 164 forks source link

[踩坑],集成knife4j,swagger时出错 #26

Closed 1060423877 closed 10 months ago

1060423877 commented 10 months ago

image 原因:swagger的接口返回值也被这个框架给封装了 解决: exclude-packages: - org.springdoc.** 希望作者可以将这个添加到默认配置,还可能会有其他第三方包的。 建议改成扫描包(include)的配置,而不是排除包(exclude)

1060423877 commented 10 months ago

@feiniaojin

feiniaojin commented 10 months ago

提供一下graceful-response的版本

1060423877 commented 10 months ago
com.feiniaojin graceful-response 3.2.0-boot2
feiniaojin commented 10 months ago

什么坑?别瞎说,哈哈哈哈。解决方案在后面。

关于“建议改成扫描包(include)的配置,而不是排除包(exclude)”改是不可能改的,有两个方面原因:第一,我们主打就是一个注解就生效,额外配东西增加学习难度;第二,改这个逻辑就会导致从前所有的项目都要变更。

你按照下面去配exclude-packages就好使了。

graceful-response:
  exclude-packages:
    - springfox.**

Controller:

@RestController
@RequestMapping("/demo")
@Api(value = "demo接口", tags = "测试")
public class DemoController {

    @ApiOperation("测试方法test0")
    @GetMapping("/test0")
    public Map<String, Object> test0() {
        return Collections.singletonMap("key", "value");
    }

    @ApiOperation("测试方法test1")
    @PostMapping("/test1")
    public ResModel test1(ReqModel reqModel) {
        ResModel model = new ResModel("graceful", "response");
        return model;
    }
}

ReqModel:


@ApiModel("请求模型")
public class ReqModel {

    @ApiModelProperty("uid")
    private String uid;

    public ReqModel() {
    }

    public ReqModel(String uid) {
        this.uid = uid;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }
}

ResModel:

@ApiModel("响应模型")
public class ResModel {

    @ApiModelProperty("key")
    private String key;

    @ApiModelProperty("value")
    private String value;

    public ResModel() {
    }

    public ResModel(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
image image
feiniaojin commented 10 months ago

knife4j

image
Lseven-zzw commented 5 months ago

boot3 也是同样的解决方式吗 image image