在定义webapi请求体和响应体时,在类上加上了如下注解:
@Data @Accessors(fluent= true) @ApiModel(value = "查询可用积分响应体") public class QueryUseableBonusPointsResDto { @ApiModelProperty("可用积分总数") private Long useableBonusPoints; }
一、坑的表现形式
1、在swagger 文档中,看不到如上类字段的文档描述
2、直接使用postman调用接口,接口也没有输出响应体
二、如何解决
去掉fluent= true 后,一切正常。
--------------------------------------------补充------------------------------
前言:
因为使用了Accessors 注解的 fluent= true 字段,导致swagger中无法展示字段及说明信息。后来想,是不是只有swagger才有这种问题,程序内部使用应该没问题。没想到,还是再次掉进坑里了。
在用FeignClient 调用外部接口时,请求体使用功能了Accessors( fluent= true) ,导致调用接口发生异常:Could not write request: no suitable HttpMessageConverter found for request type
去掉fluent= true 后恢复正常。
结论:这个Accessors 注解有坑,得谨慎使用。