项目配置swagger+ApiFox

1.添加依赖

<!--	swagger	-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

2.properties添加以下配置

swagger.enable=true

3.新增spring configuration配置API生成策略

/**
 * swagger接口生成策略
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
            .select()
            // 只有ApiOperation注解的接口才生成文档
            .apis(handler -> RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class).test(handler))
            .paths(PathSelectors.any())
            .build();
    }

}

4.调整需要生成接口的代码   

  • 在需要生成文档的Resource方法添加以下注解
  • class YourResourceImpl {
        @Override
        @ApiOperation("测试")
        public String<xxBean> selectPagination(WrapperBean wrapper){
            return "测试";
        }
    }

5.在对应的Bean的字段标注含义

class YourBean {
    @Id
    @ApiModelProperty("主键")
    private Long id;// 主键
}

6.可在IDEA使用以下正则替换,将字段注释添加为ApiModelProperty

# 匹配正则
(\s+)(private.*;\s?//\s?)(\S+)
# 替换正则
$1@ApiModelProperty("$3")$1$2$3

7. 导入接口到apifox

启动项目后,swagger接口一般为{IFM_CONTEXT}/v3/api-docs。 打开apifox进入对应项目,选择【项目设置】=》【导入数据(自动同步)】=》【新建数据源】按照提示配置swagger即可。 后续接口更新直接在导入数据菜单手动同步即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值