Springfox Java Bean验证未在Swagger输出中显示验证组

问题描述

我有一个用于实施JSR验证组的spring boot应用程序。

@Size(max=100,groups = {SomeGroup.class})
@Size(max=50,groups = {SomeOtherGroup1.class,SomeOtherGroup2.class})
private String someString;

我试图将这些组反映在我的API文档中,但是没有运气。我目前正在使用springfox 3.0。有没有办法用springfox做到这一点?如果没有,还有其他文档框架可以处理显示字段需要哪些组吗?

预先感谢, 布莱恩

解决方法

我写了一个ModelPropertyBuilderPlugin,类似于这里的内容:https://github.com/springfox/springfox/issues/2739

我的招摇页面现在显示类似以下内容:

example: someString
x-1-validation-type-Size: groups: SomeGroup | other attributes: min: 0,max: 100
x-2-validation-type-Size: groups: SomeOtherGroup1,SomeOtherGroup2 | other attributes: min: 0,max: 50

description of someString

创建springfox.documentation.service.VendorExtension的列表,然后按如下所示进行设置。

context.getSpecificationBuilder().vendorExtensions(extensions);
context.getBuilder().extensions(extensions);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...