feiniaojin/graceful-response

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

1060423877 opened this issue · 6 comments

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

提供一下graceful-response的版本

com.feiniaojin graceful-response 3.2.0-boot2

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

关于“建议改成扫描包(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

knife4j

image

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