我们正在使用SwaggerSpringMvcPlugin生成swagger文档,如下所示。
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) {
log.debug("Starting Swagger");
StopWatch watch = new StopWatch();
watch.start();
SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(springSwaggerConfig)
.apiInfo(apiInfo())
.genericModelSubstitutes(ResponseEntity.class)
.includePatterns(DEFAULT_INCLUDE_PATTERN);
swaggerSpringMvcPlugin.build();
watch.stop();
log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
return swaggerSpringMvcPlugin;
}
我需要排除一些模型属性,如下所示。我尝试使用@ApiModelProperty(access =“hidden”,hidden = true),但不排除它们。请注意,将显示MyModel的所有属性,包括状态字段。任何帮助表示赞赏。
public class MyModel implements Serializable {
....
@ApiModelProperty(access="hidden", hidden=true)
@Column(name = "status")
private String status;
...
}
答案 0 :(得分:0)
假设您不想显示此属性或允许通过序列化进行编辑,我只想添加
@JsonIgnore
关于bean属性的Jackson2注释将告诉模型生成将属性排除在外。
另外,请记住,注释需要放在getter或字段上的bean上,具体取决于ObjectMapper序列化/反序列化的配置方式。
如果您只想隐藏swagger ui中的字段并允许修改/序列化该字段,那么它目前无法实现。但是在next version of the library中,我们计划实现此目标
答案 1 :(得分:0)
您可以简单地使用
public class MyModel implements Serializable {
@ApiModelProperty(hidden=true)
private String status;
}