feat: 重构接口文档页面
This commit is contained in:
parent
1382d2a32d
commit
fc0a41a4e6
@ -1,46 +0,0 @@
|
||||
package com.agileboot.admin.controller.tool;
|
||||
|
||||
import cn.hutool.core.net.URLEncodeUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import com.agileboot.common.config.AgileBootConfig;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* swagger 接口
|
||||
* TODO Swagger这边权限拦截并没有生效,需要改进
|
||||
* PreAuthorize注解加在transfer接口上 获取不到登录用户 iframe请求header中没有token
|
||||
* @author valarchie
|
||||
*/
|
||||
@Tag(name = "文档API", description = "角色相关接口")
|
||||
@RestController
|
||||
public class SwaggerController extends BaseController {
|
||||
|
||||
/**
|
||||
* TODO 这个接口没有触发, 后续看如何改进, 应该把权限拦截放在下面的接口
|
||||
*/
|
||||
@Operation(summary = "文档首页")
|
||||
@PreAuthorize("@permission.has('tool:swagger:view')")
|
||||
@GetMapping("/tool/swagger")
|
||||
public String index() {
|
||||
return redirect("/doc.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问首页,提示语
|
||||
*/
|
||||
@Operation(summary = "文档接口数据")
|
||||
@GetMapping("/v3/api-docs/{url}")
|
||||
public void transfer(HttpServletResponse response, @PathVariable String url) throws IOException {
|
||||
response.sendRedirect(AgileBootConfig.getApiDocsPathPrefix() + "/v3/api-docs/" + URLEncodeUtil.encode(url,
|
||||
CharsetUtil.CHARSET_UTF_8));
|
||||
}
|
||||
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class AgileBootConfig {
|
||||
*/
|
||||
private static String rsaPrivateKey;
|
||||
|
||||
private static String apiDocsPathPrefix;
|
||||
private static String apiPrefix;
|
||||
|
||||
public static String getFileBaseDir() {
|
||||
return fileBaseDir;
|
||||
@ -66,12 +66,12 @@ public class AgileBootConfig {
|
||||
AgileBootConfig.fileBaseDir = fileBaseDir + File.separator + Constants.RESOURCE_PREFIX;
|
||||
}
|
||||
|
||||
public static String getApiDocsPathPrefix() {
|
||||
return apiDocsPathPrefix;
|
||||
public static String getApiPrefix() {
|
||||
return apiPrefix;
|
||||
}
|
||||
|
||||
public void setApiDocsPathPrefix(String apiDocsPathPrefix) {
|
||||
AgileBootConfig.apiDocsPathPrefix = apiDocsPathPrefix;
|
||||
public void setApiPrefix(String apiDocsPathPrefix) {
|
||||
AgileBootConfig.apiPrefix = apiDocsPathPrefix;
|
||||
}
|
||||
|
||||
public static boolean isAddressEnabled() {
|
||||
|
||||
@ -34,6 +34,12 @@ public class MetaDTO {
|
||||
private Boolean keepAlive;
|
||||
// 需要内嵌的iframe链接地址
|
||||
private String frameSrc;
|
||||
/**
|
||||
* 是否是内部页面 使用frameSrc来嵌入页面时,当isFrameSrcInternal=true的时候, 前端需要做特殊处理
|
||||
* 比如链接是 /druid/login.html
|
||||
* 前端需要处理成 http://localhost:8080/druid/login.html
|
||||
*/
|
||||
private Boolean isFrameSrcInternal;
|
||||
// 内嵌的iframe页面是否开启首次加载动画
|
||||
private Boolean frameLoading;
|
||||
// 页面加载动画(两种模式,第一种直接采用vue内置的transitions动画,第二种是使用animate.css编写进、离场动画,平台更推荐使用第二种模式,已经内置了animate.css,直接写对应的动画名即可)
|
||||
|
||||
@ -109,13 +109,6 @@
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-springdoc-ui</artifactId>
|
||||
<!--在引用时请在maven中央仓库搜索3.X最新版本号-->
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -145,7 +145,7 @@ public class SecurityConfig {
|
||||
.antMatchers("/swagger-ui.html").anonymous()
|
||||
.antMatchers("/swagger-resources/**").anonymous()
|
||||
.antMatchers("/webjars/**").anonymous()
|
||||
.antMatchers("/**/api-docs/**" ).anonymous()
|
||||
.antMatchers("/*/api-docs","/*/api-docs/swagger-config").anonymous()
|
||||
.antMatchers("/**/api-docs.yaml" ).anonymous()
|
||||
.antMatchers("/druid/**").anonymous()
|
||||
// 除上面外的所有请求全部需要鉴权认证
|
||||
|
||||
@ -118,19 +118,10 @@ springdoc:
|
||||
path: /v3/api-docs
|
||||
groups:
|
||||
enabled: true
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
# setting:
|
||||
# language: zh_cn
|
||||
# swagger-model-name: 实体类列表
|
||||
# documents:
|
||||
# - name: 标题1
|
||||
# locations: classpath:markdown/*
|
||||
# group: default
|
||||
# - name: 标题2
|
||||
# locations: classpath:markdown1/*
|
||||
# group: 用户模块
|
||||
# 配置需要生成接口文档的扫描包
|
||||
packages-to-scan: com.agileboot
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -88,13 +88,18 @@ logging:
|
||||
|
||||
|
||||
springdoc:
|
||||
api-docs:
|
||||
path: ${agileboot.api-docs-path-prefix}/v3/api-docs
|
||||
swagger-ui:
|
||||
# 开启Swagger UI界面 **安全考虑的话生产环境需要关掉**
|
||||
# 因为knife4j的一些配置不灵活 所以重新改回springdoc+swagger的组合 真实开发的时候 使用apifox这种工具效率更高
|
||||
enabled: true
|
||||
url: ${agileboot.api-prefix}/v3/api-docs
|
||||
config-url: ${agileboot.api-prefix}/v3/api-docs/swagger-config
|
||||
|
||||
|
||||
# 项目相关配置
|
||||
agileboot:
|
||||
# 文件基路径 示例( Windows配置D:\agileboot,Linux配置 /home/agileboot)
|
||||
file-base-dir: D:\agileboot
|
||||
# 因为knife4j不能给configUrl 配置前缀, 所以只能自己配置一个,然后通过转发来实现
|
||||
api-docs-path-prefix: /dev-api
|
||||
# 前端url请求转发前缀
|
||||
api-prefix: /dev-api
|
||||
demo-enabled: false
|
||||
|
||||
@ -91,7 +91,7 @@ class SysUserServiceImplTest {
|
||||
void testGetMenuPermissionsForUsers() {
|
||||
Set<String> permissionByUser = userService.getMenuPermissionsForUser(2L);
|
||||
List<SysMenuEntity> allMenus = menuService.list();
|
||||
Set<String> allPermissions = allMenus.stream().map(SysMenuEntity::getPerms).collect(Collectors.toSet());
|
||||
Set<String> allPermissions = allMenus.stream().map(SysMenuEntity::getPermission).collect(Collectors.toSet());
|
||||
|
||||
Assertions.assertEquals(allPermissions.size() - 1, permissionByUser.size());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user