当前位置:网站首页>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这种场景有其他处理方式,欢迎评论区留言!
边栏推荐
- [NLP] text classification still stays at Bert? Duality is too strong than learning framework
- Subgraph isomorphism -subgraph isomorphism
- Global and Chinese markets for instant saliva testing devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Qtcharts notes (V) scatter diagram qscatterseries
- BBS forum recommendation
- Iclr2022: how does AI recognize "things I haven't seen"?
- Understanding of Radix
- 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
- Smart fan system based on stm32f407
- Distributed transaction -- middleware of TCC -- selection / comparison
猜你喜欢

BBS forum recommendation

MySQL is installed as a Windows Service

Smart fan system based on stm32f407

Software testers, how can you quickly improve your testing skills? Ten minutes to teach you

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
![[NLP] text classification still stays at Bert? Duality is too strong than learning framework](/img/49/1ff6025bdb0445e5638c1451e0b267.jpg)
[NLP] text classification still stays at Bert? Duality is too strong than learning framework

A dichotomy of Valentine's Day

Sorry, Tencent I also refused
![[CSDN Q & A] experience and suggestions](/img/db/dff3173dda24ca5740729b54a81153.jpg)
[CSDN Q & A] experience and suggestions

Shell script three swordsman sed
随机推荐
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Entropy and full connection layer
Unity elementary case notes of angry birds Siki college 1-6
What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
What insurance products should be bought for the elderly?
Speed up the energy Internet of things. What can low-power Internet of things technology represented by Zeta do?
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
Interview script of Software Test Engineer
Similarities and differences of text similarity between Jaccard and cosine
[CSDN Q & A] experience and suggestions
Struct in linked list
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Global and Chinese market of process beer equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for blood and liquid heating devices 2022-2028: Research Report on technology, participants, trends, market size and share
From functional testing to automated testing, how did I successfully transform my salary to 15K +?
[Mongodb] 2. Use mongodb --------- use compass
Self study software testing. To what extent can you go out and find a job?
The upload experience version of uniapp wechat applet enters the blank page for the first time, and the page data can be seen only after it is refreshed again
How to be a professional software testing engineer? Listen to the byte five year old test
Stock price forecast