当前位置:网站首页>Swagger setting field required is mandatory
Swagger setting field required is mandatory
2022-07-06 08:38:00 【renkai721】
swagger Is the field in the annotation that needs to set the request parameters mandatory or non mandatory . We need to add the following configuration . Just add the following code in the field of the object
@ApiModelProperty(value = " Self built application corpid", required = true)The display effect is as follows

The detailed code is as follows
Requested controller Code
package my.controller;
import my.bean.*;
import my.common.BaseController;
import my.configuration.MyRedissonConfig;
import my.service.*;
import my.util.MsgUtil;
import my.util.MyConstants;
import my.util.WxUtil;
import my.wechataes.WXBizMsgCrypt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
@EnableAsync
@RestController
@Api(value = "MyAppController",tags = {" Self built application service "})
@RequestMapping("/myApp")
@Slf4j
public class MyAppController extends BaseController {
@Autowired
private MyAppService myAppService;
@ApiOperation(value = " Self built application - Push graphic messages to users ",
notes = " The logic is as follows :"+ MyConstants.SWAGGER2_FOX_BR_TAG +
MyConstants.SWAGGER2_FOX_BR_TAG)
@RequestMapping(value = "/sendNews", method = RequestMethod.POST)
@ResponseBody
public String sendNews(@Validated @RequestBody MyAppSendNewsReqBean vo) {
String code = MyConstants.SUCCESS;
try {
log.info("myApp sendNews vo={}",vo);
myAppService.sendNews(vo);
} catch (Exception e) {
code = MyConstants.FAILURE;
e.printStackTrace();
}
return MsgUtil.outJson(code);
}
}
Request parameter object
package my.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel(
description = " Message object "
)
@Data
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class MyAppSendNewsReqBean implements Serializable {
@ApiModelProperty(value = " Enterprise and micro self built applications , Users receiving messages ID, For multiple receivers ‘|’ Separate , Most support 1000 individual )[email protected]= Send all ", required = true)
@NotNull(message = "userId Can't be empty ")
private String userId;
@ApiModelProperty(value = " Self built application corpid", required = true)
@NotNull(message = "corpid Can't be empty ")
private String corpid;
@ApiModelProperty(value = " Self built application corpsecret", required = true)
@NotNull(message = "corpsecret Can't be empty ")
private String corpsecret;
@ApiModelProperty(value = " Self built application agentId", required = true)
@NotNull(message = "agentId Can't be empty ")
private Integer agentId;
@ApiModelProperty(value = " Title of graphic message ", required = true)
@NotNull(message = "title Can't be empty ")
private String title;
@ApiModelProperty(value = " Description of graphic message ")
private String description;
@ApiModelProperty(value = " Click the image to jump to the website , The website must be the website for the record , Otherwise, there will be a risk prompt ")
private String url;
@ApiModelProperty(value = " Picture address ", required = true)
@NotNull(message = "picUrl Can't be empty ")
private String picUrl;
}Start project , visit swagger, The address is as follows
log.info("swagger api=http://ip:port/ Project name /swagger-ui.html");
log.info("swagger api=http://ip:port/ Project name /doc.html");
边栏推荐
- 【MySQL】鎖
- Golang force buckle leetcode 1020 Number of enclaves
- LDAP应用篇(4)Jenkins接入
- Research and investment forecast report of citronellol industry in China (2022 Edition)
- Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
- 被破解毁掉的国产游戏之光
- 如何进行接口测试测?有哪些注意事项?保姆级解读
- win10系统中的截图,win+prtSc保存位置
- 2022.02.13 - 238. Maximum number of "balloons"
- Colorlog结合logging打印有颜色的日志
猜你喜欢

Hungry for 4 years + Ali for 2 years: some conclusions and Thoughts on the road of research and development

visdom可视化实现与检查介绍

Image, CV2 read the conversion and size resize change of numpy array of pictures

游戏解包的危害及资源加密的重要性

Computer cleaning, deleted system files

Deep learning: derivation of shallow neural networks and deep neural networks

JVM performance tuning and practical basic theory - Part 1

JVM 快速入门

个人电脑好用必备软件(使用过)

查看局域网中电脑设备
随机推荐
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
Crash problem of Chrome browser
Roguelike游戏成破解重灾区,如何破局?
Computer cleaning, deleted system files
C语言深度解剖——C语言关键字
Shift Operators
企微服务商平台收费接口对接教程
Colorlog结合logging打印有颜色的日志
[MySQL] lock
[2022 Guangdong saim] Lagrange interpolation (multivariate function extreme value divide and conquer NTT)
Chrome浏览器的crash问题
[MySQL] log
LDAP應用篇(4)Jenkins接入
JVM performance tuning and practical basic theory - Part 1
On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced
Leetcode question brushing (5.31) string
How to conduct interface test? What are the precautions? Nanny level interpretation
【ROS】usb_cam相机标定
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
Deep analysis of C language pointer