当前位置:网站首页>swagger设置字段required必填
swagger设置字段required必填
2022-07-06 08:31:00 【renkai721】
swagger注解中需要设置请求参数的字段是必须填写的还是非必须的。我们需要添加下面的配置。只需要在对象的字段中增加下面的代码
@ApiModelProperty(value = "自建应用的corpid", required = true)显示效果如下

详细的代码如下
请求的controller代码
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 = {"自建应用服务"})
@RequestMapping("/myApp")
@Slf4j
public class MyAppController extends BaseController {
@Autowired
private MyAppService myAppService;
@ApiOperation(value = "自建应用-推送图文消息给用户",
notes = "逻辑如下:"+ 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);
}
}
请求参数对象
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 = "图文消息对象"
)
@Data
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class MyAppSendNewsReqBean implements Serializable {
@ApiModelProperty(value = "企微自建应用,接收消息的用户ID,多个接收者用‘|’分隔,最多支持1000个)。@all=全员发送", required = true)
@NotNull(message = "userId不能为空")
private String userId;
@ApiModelProperty(value = "自建应用的corpid", required = true)
@NotNull(message = "corpid不能为空")
private String corpid;
@ApiModelProperty(value = "自建应用的corpsecret", required = true)
@NotNull(message = "corpsecret不能为空")
private String corpsecret;
@ApiModelProperty(value = "自建应用的agentId", required = true)
@NotNull(message = "agentId不能为空")
private Integer agentId;
@ApiModelProperty(value = "图文消息的标题", required = true)
@NotNull(message = "title不能为空")
private String title;
@ApiModelProperty(value = "图文消息的描述")
private String description;
@ApiModelProperty(value = "点击图片跳转的网址,网址必须是备案的网址,否则会有风险提示")
private String url;
@ApiModelProperty(value = "图片地址", required = true)
@NotNull(message = "picUrl不能为空")
private String picUrl;
}启动项目,访问swagger,访问地址如下
log.info("swagger api=http://ip:port/项目名称/swagger-ui.html");
log.info("swagger api=http://ip:port/项目名称/doc.html");
边栏推荐
- Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
- FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
- egg. JS directory structure
- 角色动画(Character Animation)的现状与趋势
- 2. File operation - write
- 被破解毁掉的国产游戏之光
- Precise query of tree tree
- 根据csv文件某一列字符串中某个数字排序
- 【MySQL】数据库的存储过程与存储函数通关教程(完整版)
- egg. JS project deployment online server
猜你喜欢

【MySQL】锁

ESP series pin description diagram summary

win10系统中的截图,win+prtSc保存位置
![[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes](/img/ac/773ce8ee7f380df19edf8373250608.jpg)
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes

JVM performance tuning and practical basic theory - Part 1

FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战

查看局域网中电脑设备

JS native implementation shuttle box

tree树的精准查询

Résumé des diagrammes de description des broches de la série ESP
随机推荐
2022.02.13 - NC004. Print number of loops
Let the bullets fly for a while
Colorlog结合logging打印有颜色的日志
Upgrade tidb with tiup
logback1.3. X configuration details and Practice
Huawei cloud OBS file upload and download tool class
Beijing invitation media
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
Online yaml to CSV tool
String to leading 0
2. File operation - write
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
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
gcc动态库fPIC和fpic编译选项差异介绍
Online yaml to CSV tool
synchronized 解决共享带来的问题
C language double pointer -- classic question type
Is it safe to open an account in Zheshang futures?
Migrate data from CSV files to tidb
China dihydrolaurenol market forecast and investment strategy report (2022 Edition)