当前位置:网站首页>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】数据库的存储过程与存储函数通关教程(完整版)
- C language double pointer -- classic question type
- Unified ordering background interface product description Chinese garbled
- Online yaml to CSV tool
- 2022.02.13 - NC003. Design LRU cache structure
- 生成器参数传入参数
- 同一局域网的手机和电脑相互访问,IIS设置
- IOT -- interpreting the four tier architecture of the Internet of things
- @JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
- Leetcode skimming (5.29) hash table
猜你喜欢
软件卸载时遇到trying to use is on a network resource that is unavailable
visdom可视化实现与检查介绍
Bottom up - physical layer
tree树的精准查询
深度剖析C语言指针
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Let the bullets fly for a while
同一局域网的手机和电脑相互访问,IIS设置
Image, CV2 read the conversion and size resize change of numpy array of pictures
IOT -- interpreting the four tier architecture of the Internet of things
随机推荐
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
堆排序详解
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
角色动画(Character Animation)的现状与趋势
Double pointeur en langage C - - modèle classique
Bitwise logical operator
leetcode刷题 (5.29) 哈希表
egg. JS project deployment online server
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The mysqlbinlog command uses
logback1.3. X configuration details and Practice
Purpose of computer F1-F12
China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
sublime text中conda环境中plt.show无法弹出显示图片的问题
pytorch训练好的模型在加载和保存过程中的问题
2022.02.13 - 238. Maximum number of "balloons"
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
【MySQL】锁
Deep learning: derivation of shallow neural networks and deep neural networks