当前位置:网站首页>swagger中响应参数为Boolean或是integer如何设置响应描述信息
swagger中响应参数为Boolean或是integer如何设置响应描述信息
2022-07-04 00:34:00 【卖柴火的小伙子】
问题描述
项目使用swagger进行文档信息展示,现在有一个招聘者企业用户信息校验接口,响应参数只会返回true或是false,如何在接口文档中响应参数栏目中添加对返回字段的描述信息(true:校验成功;false:校验失败)?
swagger中响应参数的描述信息都是通过实体类中@ApiModelProperty
添加,但是如果返回的是一个Boolean或是其他非对象类型,是没有地方添加这个注解的.这里说一下自己总结的处理方案.
解决方案
1.直接从方法描述注解 @ApiOperation
中添加响应结果描述信息,只要能让前端明白返回的字段的含义即可.
@ApiOperation("招聘者企业用户信息校验(返回参数说明:true:校验成功;false:校验失败)")
@GetMapping("/checkRecruitBusinessInfo")
public ResultVo<Boolean> checkRecruitBusinessInfo(@Validated BusinessInfoDto businessInfoDto) throws Exception {
Boolean businessInfoRight = newStoreService.checkRecruitBusinessInfo(businessInfoDto);
return ResultVoUtil.success(businessInfoRight);
}
接口文档显示如下:
2.自定义返回参数对象,标注返回字段信息.
自定义添加返回参数描述对象:
@ApiModel("招聘者企业用户信息校验返回参数信息")
@Data
public class ReturnInfo {
@ApiModelProperty(value = "招聘者企业用户信息校验:true:校验成功;false:校验失败",dataType = "Boolean",example = "false")
private Boolean businessInfoRight;
}
修改controller中返回对象信息:
@ApiOperation("招聘者企业用户信息校验")
@GetMapping("/checkRecruitBusinessInfo")
public ResultVo<ReturnInfo> checkRecruitBusinessInfo(@Validated BusinessInfoDto businessInfoDto) throws Exception {
Boolean businessInfoRight = newStoreService.checkRecruitBusinessInfo(businessInfoDto);
ReturnInfo returnInfo = new ReturnInfo();
returnInfo.setBusinessInfoRight(businessInfoRight);
return ResultVoUtil.success(returnInfo);
}
修改之后的接口文档,标注出的地方已经显示字段的描述信息:
实际开发中只要是前后端能清楚参数传递含义使用第一种方式就可以;但是对于像我这样的强迫症选手来说,不从响应参数中显示字段含义就感觉有问题,不过第二种方式确实有点多余,只是为了显示问题去创建对象确实不是很明智的方法.如果大家平常对于swagger这种场景有其他处理方式,欢迎评论区留言!
边栏推荐
- 不得不会的Oracle数据库知识点(四)
- 老姜的特点
- Axure resources and prototype tool Axure RP 9 download
- Pair
- Recommendation of knowledge base management system
- UTS | causal reasoning random intervention based on Reinforcement Learning
- Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
- (Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
- Att & CK actual combat series - red team actual combat - V
猜你喜欢
Correlation analysis summary
Beijing invites reporters and media
Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
Joint examination of six provinces 2017
Is user authentication really simple
Generic
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
The super fully automated test learning materials sorted out after a long talk with a Tencent eight year old test all night! (full of dry goods
SPI based on firmware library
随机推荐
2022 system integration project management engineer examination knowledge points: software development model
From functools import reduce -- see the use of reduce function from typical examples
No qualifying bean of type ‘com. netflix. discovery. AbstractDiscoveryClientOptionalArgs<?>‘ available
Axure resources and prototype tool Axure RP 9 download
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Wechat official account and synchronization assistant
What is the future of software testing industry? Listen to the test veterans' answers
Self study software testing. To what extent can you go out and find a job?
Development and application of fcitx functional plug-ins
Att & CK actual combat series - red team actual combat - V
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
网上的低佣金链接安全吗?招商证券怎么开户?
Advanced C language - pointer 2 - knowledge points sorting
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
8. Go implementation of string conversion integer (ATOI) and leetcode
Double efficiency. Six easy-to-use pychar plug-ins are recommended
NLP Chinese corpus project: large scale Chinese natural language processing corpus
Vscode regular match replace console log(.*)
The super fully automated test learning materials sorted out after a long talk with a Tencent eight year old test all night! (full of dry goods
system. Exit (0) and system exit(1)