【发布时间】:2018-07-28 18:06:58
【问题描述】:
我按照本教程https://springframework.guru/spring-boot-restful-api-documentation-with-swagger-2/ 生成了一个招摇的文档。 它正在工作,但是当我尝试在我的 bean 中添加一些验证时,我在文档中找不到信息:
@ApiOperation(value = "Creates a product",
notes="Populates a product instance bla bla")
@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
public ResponseEntity saveProduct( @Valid @RequestBody Product product){
productService.saveProduct(product);
return new ResponseEntity("Product saved successfully", HttpStatus.OK);
}
我的带有验证注释的实体:
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
// @ApiModelProperty(notes = "The database generated product ID")
private Integer id;
@Version
// @ApiModelProperty(notes = "The auto-generated version of the product")
@NotNull
private Integer version;
// @ApiModelProperty(notes = "The application-specific product ID" )
private String productId;
// @ApiModelProperty(notes = "The product description")
@NotBlank
@Size(max = 50)
private String description;
// @ApiModelProperty(notes = "The image URL of the product")
private String imageUrl;
// @ApiModelProperty(notes = "The price of the product", required = true)
@NotNull
private BigDecimal price;
但是当我检查文档时,我没有这些验证信息:
这里https://github.com/springfox/springfox/issues/987 他们说我们需要更新我们的依赖项,这就是我所做的:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
我是否遗漏了配置中的某些内容?有什么想法可以帮助我吗?
【问题讨论】: