当前位置:网站首页>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这种场景有其他处理方式,欢迎评论区留言!
边栏推荐
- Global and Chinese markets for instant saliva testing devices 2022-2028: Research Report on technology, participants, trends, market size and share
- CSP window
- No qualifying bean of type ‘com. netflix. discovery. AbstractDiscoveryClientOptionalArgs<?>‘ available
- [2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
- [NLP] text classification still stays at Bert? Duality is too strong than learning framework
- Celebrate the new year | Suihua fire rescue detachment has wonderful cultural activities during the Spring Festival
- Qtcharts notes (V) scatter diagram qscatterseries
- URL (data:image/png; Base64, ivborw0k... Use case
- Smart fan system based on stm32f407
- Data storage - interview questions
猜你喜欢

Smart fan system based on stm32f407

Pytorch learning notes 5: model creation

From functional testing to automated testing, how did I successfully transform my salary to 15K +?

Introducing Software Testing

Iclr2022: how does AI recognize "things I haven't seen"?

功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。

What does redis do? Redis often practices grammar every day

Sorry, Tencent I also refused
![[GNN] hard core! This paper combs the classical graph network model](/img/a7/2140744ebad9f1dc0a609254cc618e.jpg)
[GNN] hard core! This paper combs the classical graph network model

Zipper table in data warehouse (compressed storage)
随机推荐
Development and application of fcitx functional plug-ins
NLP Chinese corpus project: large scale Chinese natural language processing corpus
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
UTS | causal reasoning random intervention based on Reinforcement Learning
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
Idea set class header comments
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
Interview script of Software Test Engineer
Idea a method for starting multiple instances of a service
不得不会的Oracle数据库知识点(三)
Version rollback revert don't reset better reset must be forced
How to trade spot gold safely?
Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
[CSDN Q & A] experience and suggestions
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
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
Pair
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