Swagger2 忽略某些参数使其不出现在接口文档中
解决方案
@ApiOperation("添加购物车")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", required = true, value = "header token", paramType = "header", defaultValue = "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7InVzZXJJZCI6MjAsInVzZXJuYW1lIjoiMSIsInBhc3N3b3JkIjpudWx"),
@ApiImplicitParam(name = "productId", value = "商品id", paramType = "query", dataType = "int", required = true)
})
@PostMapping
public RespBean add(@ApiIgnore ShoppingCart shoppingCart) {
ShoppingCart shop = new ShoppingCart();
shop.setProductId(shoppingCart.getProductId());
shop.setSkuId(shoppingCart.getSkuId());
shop.setUserId(shoppingCart.getUserId());
shop.setCartNum(shoppingCart.getCartNum());
shop.setProductPrice(shoppingCart.getProductPrice());
shop.setSkuProps(shoppingCart.getSkuProps());
boolean save = shoppingCartService.save(shop);
if (save) {
return new RespBean(200, "添加收藏成功", null);
} else {
return new RespBean(555, "添加收藏失败", null);
}
}
前后对比
之前
添加@ApiIgnore
之后