@ApiParam忽略某些属性更新
我有一个Spring Boot项目,我有以下控制器:springfox-swagger2
2.7.0
@Api(tags = { "Some" }, description = "CRUD for Some Stuff")
@RestController
@RequestMapping(path = "/some")
public class SomeController {
@ApiOperation(value = "Get some")
@GetMapping(value = "{someId}", produces = MediaType.APPLICATION_JSON_VALUE)
public Response getSomeById(@PathVariable("someId") Id someId) {
return ...;
}
...
}
我想通过注释类来控制文档中显示的内容,这仅适用于注释的某些部分,但不适用于全部。该类(具有从 到 的已注册转换器):Id
Id
String
Id
public class Id {
@ApiParam(value = "This is the description", defaultValue = "1f1f1f",required = true, name = "someId", type = "string")
private final Long id;
public Id(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
}
现在返回的如下所示:Swagger JSON
"parameters":[{
"name":"id",
"in":"query",
"description":"This is the description",
"required":true,
"type":"integer",
"default":"1f1f1f",
"format":"int64"
}]
我的问题是(或者可能是错误报告):为什么使用注释的某些部分(如 和 ),而其他部分则没有,如 和 ?为什么看起来我无法更改 或 这里?对于我的特定用例,后者是我想更改为的。@ApiParam
value
defaultValue
required
name
type
name
type
string
更新
我决定在skadya的帮助下添加以下组件。
@Component
public class OverrideSwaggerApiParamBuilder implements
ExpandedParameterBuilderPlugin {
@Override
public boolean supports(DocumentationType type) {
return DocumentationType.SWAGGER_2 == type;
}
@Override
public void apply(ParameterExpansionContext context) {
Optional<ApiParam> apiParamOptional = findApiParamAnnotation(context.getField().getRawMember());
if (apiParamOptional.isPresent()) {
ApiParam param = apiParamOptional.get();
context.getParameterBuilder()
.name(param.name())
.modelRef(new ModelRef(param.type()))
.build();
}
}
}
Springfox的作者认为这可能是一个错误:https://github.com/springfox/springfox/issues/2107