ApiBoot - ApiBoot Swagger 使用文档

ApiBoot是一款基于SpringBoot1.x,2.x的接口服务集成基础框架, 内部提供了框架的封装集成、使用扩展、自动化完成配置,让接口开发者能够选着性完成开箱即用, 再也不为搭建接口框架而犯愁,从而极大的提升开发效率。html

ApiBoot经过整合Swagger2完成自动化接口文档生成,只须要一个简单的注解咱们就能够实现文档的开启,并且文档上面的全部元素均可以自定义配置,经过下面的介绍来详细了解ApiBoot Swagger的简易之处。git

引入ApiBoot Swagger

pom.xml配置文件内经过添加以下依赖进行集成:github

<!--ApiBoot Swagger-->
<dependency>
	<groupId>org.minbox.framework</groupId>
	<artifactId>api-boot-starter-swagger</artifactId>
</dependency>
复制代码

注意:ApiBoot所提供的依赖都不须要添加版本号,可是须要添加版本依赖,具体查看ApiBoot版本依赖web

@EnableApiBootSwagger

在添加依赖后须要经过@EnableApiBootSwagger注解进行开启ApiBoot Swagger相关的配置信息自动化构建,能够配置在XxxApplication入口类上,也能够是配置类,让SpringBoot加载到便可。api

相关配置

配置参数 参数介绍 默认值
api.boot.swagger.enable 是否启用 true
api.boot.swagger.title 文档标题 ApiBoot快速集成Swagger文档
api.boot.swagger.description 文档描述 ApiBoot经过自动化配置快速集成Swagger2文档,仅需一个注解、一个依赖便可。
api.boot.swagger.base-package 文档扫描的package XxxApplication同级以及子级package
api.boot.swagger.version 文档版本号 api.boot.version
api.boot.swagger.license 文档版权 ApiBoot
api.boot.swagger.license-url 文档版权地址 github.com/hengboy/api…
api.boot.swagger.contact.name 文档编写人名称 恒宇少年
api.boot.swagger.contact.website 文档编写人主页 blog.yuqiyu.com
api.boot.swagger.contact.email 文档编写人邮箱地址 jnyuqy@gmail.com
api.boot.swagger.authorization.name 整合Oauth2后受权名称 ApiBoot Security Oauth 认证头信息
api.boot.swagger.authorization.key-name 整合Oauth2后受权Header内的key-name Authorization
api.boot.swagger.authorization.auth-regex 整合Oauth2后受权表达式 ^.*$

以上是目前版本的全部配置参数,大多数都存在默认值,可自行修改。安全

整合ApiBoot Security Oauth

若是你的项目添加了Oauth2资源保护,在Swagger界面上访问接口时须要设置AccessTokenHeader才能够完成接口的访问,ApiBoot Security Oauth默认开放Swagger全部相关路径,若是项目内并不是经过ApiBoot Security Oauth2来作安全认证以及资源保护,须要自行开放Swagger相关路径。框架

整合ApiBoot Security Oauth很简单,访问ApiBoot Security Oauth 查看。ui

携带Token访问Api

启动添加ApiBoot-Swagger依赖的项目后,访问http://localhost:8080/swagger-ui.html页面查看Swagger所生成的所有文档,页面右侧能够看到Authorize,点击后打开配置AccessToken的界面,配置的AccessToken必须携带类型,如:Bearer 0798e1c7-64f4-4a2f-aad1-8c616c5aa85burl

注意:经过ApiBoot Security Oauth所获取的AccessToken类型都为Bearerspa

本章源码地址:github.com/hengboy/api…

ApiBoot 开源交流群
相关文章
相关标签/搜索