From 5434ceb1a3ce131133c8a89d9a20798f4c182232 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 17 May 2020 22:43:09 +0800 Subject: [PATCH] =?UTF-8?q?swagger=E8=AF=B7=E6=B1=82=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=85=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/framework/config/SwaggerConfig.java | 22 +++++++++++-------- ruoyi/src/main/resources/application.yml | 5 ++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java b/ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java index 74786d9ed..969268565 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java @@ -33,9 +33,13 @@ public class SwaggerConfig @Autowired private RuoYiConfig ruoyiConfig; - /** Swagger开关配置 */ - @Value("${swagger.enable}") - private boolean swaggerEnable; + /** 是否开启swagger */ + @Value("${swagger.enabled}") + private boolean enabled; + + /** 设置请求的统一前缀 */ + @Value("${swagger.pathMapping}") + private String pathMapping; /** * 创建API @@ -45,8 +49,7 @@ public class SwaggerConfig { return new Docket(DocumentationType.SWAGGER_2) // 是否启用Swagger - .enable(swaggerEnable) - .pathMapping("/dev-api") + .enable(enabled) // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) .apiInfo(apiInfo()) // 设置哪些接口暴露给Swagger展示 @@ -54,13 +57,14 @@ public class SwaggerConfig // 扫描所有有注解的api,用这种方式更灵活 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 扫描指定包中的swagger注解 - //.apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger")) + // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger")) // 扫描所有 .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() /* 设置安全模式,swagger可以设置访问token */ .securitySchemes(securitySchemes()) - .securityContexts(securityContexts()); + .securityContexts(securityContexts()) + .pathMapping(pathMapping); } /** @@ -72,7 +76,7 @@ public class SwaggerConfig apiKeyList.add(new ApiKey("Authorization", "Authorization", "header")); return apiKeyList; } - + /** * 安全上下文 */ @@ -86,7 +90,7 @@ public class SwaggerConfig .build()); return securityContexts; } - + /** * 默认的安全上引用 */ diff --git a/ruoyi/src/main/resources/application.yml b/ruoyi/src/main/resources/application.yml index 8de79e792..89ea4a60a 100644 --- a/ruoyi/src/main/resources/application.yml +++ b/ruoyi/src/main/resources/application.yml @@ -102,7 +102,10 @@ pagehelper: # Swagger配置 swagger: - enable: true + # 是否开启swagger + enabled: true + # 请求前缀 + pathMapping: /dev-api # 防止XSS攻击 xss: