Ste*_*ich 3 spring jackson swagger swagger-ui springfox
我正在使用 Spring、springfox、Jackson 开发 REST API,我的模型类包含一个ZoneIdas 属性:
@JsonProperty
private ZoneId timeZone;
Run Code Online (Sandbox Code Playgroud)
我在我的依赖项中包含了jackson-datatype-jsr310版本2.9.0.pr4,因此它可以按预期正常进行序列化和反序列化。但我的 swagger-ui 显示了很多模型对象,例如ZoneId、等,这非常令人困惑ZoneOffset,ZoneOffsetTransition因为区域 ID 被序列化为简单的字符串。生成的 API 规范中的情况相同。如何防止 swagger 公开这些(未使用的)模型对象?
您可以尝试@ApiModelProperty设置dataType为string:
@JsonProperty
@ApiModelProperty(dataType = "string")
private ZoneId timeZone;
Run Code Online (Sandbox Code Playgroud)
如果dataType被忽略,您可以使用Docket:
@Bean
public Docket configureDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.directModelSubstitute(ZoneId .class, String.class);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1014 次 |
| 最近记录: |