1、返回数据的字段没有注释:
决绝办法:https://doc.xiaominfo.com/faq/swagger-des-not-found.html
还有你的返回体中boolean类型的属性请使用get set 命名,不要使用is
2、响应参数和响应示例不展示时,请看你是否覆盖了默认配置,respnseModel 千万不要覆盖
//添加全局响应状态码
List<ResponseMessage> responseMessageList = new ArrayList<>();
Arrays.stream(ApiCodeEnum.values()).forEach(errorEnum -> {
responseMessageList.add(
new ResponseMessageBuilder()
.code(errorEnum.getCode())
.message(errorEnum.getMessage())
.responseModel()
.build()
);
});
Docket docket=new Docket(DocumentationType.SWAGGER_2)
// 添加全局响应状态码
.globalResponseMessage(RequestMethod.GET, responseMessageList)
.globalResponseMessage(RequestMethod.POST, responseMessageList)
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
.additionalModels(new TypeResolver().resolve(UserLoginDto.class))
.apiInfo(apiInfo())
//分组名称
.groupName("默认分组")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
return docket;
3、添加自定义接口时必须指定 uniqueId
Operation panxingNormalLogin = new OperationBuilder(new CachingOperationNameGenerator())
.method(HttpMethod.POST)
.uniqueId("这个必须指定,否则多个的情况会出现接口覆盖")
.summary("用户名密码登录")
.notes("使用用户名密码登录")
.consumes(Sets.newHashSet(MediaType.APPLICATION_JSON_VALUE)) // 接收参数格式
.tags(Sets.newHashSet("会员"))
.parameters(Arrays.asList(
new ParameterBuilder()
.type(new TypeResolver().resolve(UserLoginDto.class))
.name("userLoginDto")
.parameterType("body")
.parameterAccess("access")
.required(true)
.modelRef(new ModelRef("UserLoginDto"))
.build()
)).position(1)
.responseMessages(Collections.singleton(
new ResponseMessageBuilder().code(200).message("请求成功")
.responseModel(new ModelRef(
"ResultData«MyUserDetailsVo»")
).build()))
.build();
return panxingNormalLogin;