当前位置:网站首页>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这种场景有其他处理方式,欢迎评论区留言!
边栏推荐
- Development and application of fcitx functional plug-ins
- SPI based on firmware library
- Briefly understand the operation mode of developing NFT platform
- Correlation analysis summary
- Shell script three swordsman sed
- Axure resources and prototype tool Axure RP 9 download
- How to trade spot gold safely?
- 1214 print diamond
- AI Challenger 2018 text mining competition related solutions and code summary
- Eight year test old bird, some suggestions for 1-3 year programmers
猜你喜欢

How to be a professional software testing engineer? Listen to the byte five year old test

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Joint examination of six provinces 2017
![[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)](/img/44/aa4963d07d046deb2bc76eb59f8ff7.jpg)
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)

STM32 key light

Idea a method for starting multiple instances of a service

Interview script of Software Test Engineer

Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
![[C language] break and continue in switch statement](/img/ae/5967fefcf3262c9d3096e5c7d644fd.jpg)
[C language] break and continue in switch statement

A method to solve Bert long text matching
随机推荐
Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
Qtcharts notes (V) scatter diagram qscatterseries
Investment demand and income forecast report of China's building ceramics industry, 2022-2028
网上的低佣金链接安全吗?招商证券怎么开户?
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
Is the account opening of Guoyuan securities really safe and reliable
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
Axure resources and prototype tool Axure RP 9 download
Shell script three swordsman sed
Recommendation of knowledge base management system
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Introduction to thread pool
Double efficiency. Six easy-to-use pychar plug-ins are recommended
URL (data:image/png; Base64, ivborw0k... Use case
I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
AI Challenger 2018 text mining competition related solutions and code summary
Selenium library 4.5.0 keyword explanation (II)
Global and Chinese markets for coronary artery disease treatment devices 2022-2028: Research Report on technology, participants, trends, market size and share
Suggestions for improving code quality