Commit 5434ceb1a3ce131133c8a89d9a20798f4c182232

Authored by RuoYi
1 parent 922f61e0

swagger请求前缀加入配置。

ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
... ... @@ -33,9 +33,13 @@ public class SwaggerConfig
33 33 @Autowired
34 34 private RuoYiConfig ruoyiConfig;
35 35  
36   - /** Swagger开关配置 */
37   - @Value("${swagger.enable}")
38   - private boolean swaggerEnable;
  36 + /** 是否开启swagger */
  37 + @Value("${swagger.enabled}")
  38 + private boolean enabled;
  39 +
  40 + /** 设置请求的统一前缀 */
  41 + @Value("${swagger.pathMapping}")
  42 + private String pathMapping;
39 43  
40 44 /**
41 45 * 创建API
... ... @@ -45,8 +49,7 @@ public class SwaggerConfig
45 49 {
46 50 return new Docket(DocumentationType.SWAGGER_2)
47 51 // 是否启用Swagger
48   - .enable(swaggerEnable)
49   - .pathMapping("/dev-api")
  52 + .enable(enabled)
50 53 // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
51 54 .apiInfo(apiInfo())
52 55 // 设置哪些接口暴露给Swagger展示
... ... @@ -54,13 +57,14 @@ public class SwaggerConfig
54 57 // 扫描所有有注解的api,用这种方式更灵活
55 58 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
56 59 // 扫描指定包中的swagger注解
57   - //.apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
  60 + // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
58 61 // 扫描所有 .apis(RequestHandlerSelectors.any())
59 62 .paths(PathSelectors.any())
60 63 .build()
61 64 /* 设置安全模式,swagger可以设置访问token */
62 65 .securitySchemes(securitySchemes())
63   - .securityContexts(securityContexts());
  66 + .securityContexts(securityContexts())
  67 + .pathMapping(pathMapping);
64 68 }
65 69  
66 70 /**
... ... @@ -72,7 +76,7 @@ public class SwaggerConfig
72 76 apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
73 77 return apiKeyList;
74 78 }
75   -
  79 +
76 80 /**
77 81 * 安全上下文
78 82 */
... ... @@ -86,7 +90,7 @@ public class SwaggerConfig
86 90 .build());
87 91 return securityContexts;
88 92 }
89   -
  93 +
90 94 /**
91 95 * 默认的安全上引用
92 96 */
... ...
ruoyi/src/main/resources/application.yml
... ... @@ -102,7 +102,10 @@ pagehelper:
102 102  
103 103 # Swagger配置
104 104 swagger:
105   - enable: true
  105 + # 是否开启swagger
  106 + enabled: true
  107 + # 请求前缀
  108 + pathMapping: /dev-api
106 109  
107 110 # 防止XSS攻击
108 111 xss:
... ...