inleft
2022-02-27 2782f3e576b56a9ca078055026394646d57440f8
commit | author | age
9bcb19 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.sys.config;
26
27 import cn.hutool.core.collection.CollectionUtil;
2782f3 28 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9bcb19 29 import org.springframework.context.annotation.Bean;
I 30 import org.springframework.context.annotation.Configuration;
31 import springfox.documentation.builders.ApiInfoBuilder;
32 import springfox.documentation.builders.ParameterBuilder;
33 import springfox.documentation.builders.PathSelectors;
34 import springfox.documentation.builders.RequestHandlerSelectors;
35 import springfox.documentation.schema.ModelRef;
36 import springfox.documentation.service.ApiInfo;
37 import springfox.documentation.service.Contact;
38 import springfox.documentation.service.Parameter;
39 import springfox.documentation.spi.DocumentationType;
40 import springfox.documentation.spring.web.plugins.Docket;
41 import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
42 import vip.xiaonuo.core.consts.CommonConstant;
43
44 import java.util.List;
45
46 /**
47  * swagger配置
48  *
49  * @author xuyuxiang
50  * 加入分组功能(默认注释掉)
51  * <p>
52  * https://doc.xiaominfo.com/knife4j/changelog/2017-12-18-swagger-bootstrap-ui-1.7-issue.html
53  * </p>
54  * @author ldw4033#163.com
55  * @date 2021/4/9 10:42
56  **/
57 @Configuration
58 @EnableSwagger2WebMvc
2782f3 59 @ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
9bcb19 60 public class SwaggerConfig {
I 61
62     private List<Parameter> getParameters() {
63         Parameter parameter = new ParameterBuilder()
64                 .name("Authorization")
65                 .description("token令牌")
66                 .modelRef(new ModelRef("string"))
67                 .parameterType("header")
68                 .required(false)
69                 .build();
70
71         List<Parameter> parameters = CollectionUtil.newArrayList();
72         parameters.add(parameter);
73         return parameters;
74     }
75
76     @Bean
77     public Docket defaultApi() {
78         List<Parameter> parameters = getParameters();
79         return new Docket(DocumentationType.SWAGGER_2)
80                 .apiInfo(defaultApiInfo())
81                 .groupName("默认接口")
82                 .select()
83                 .apis(RequestHandlerSelectors.basePackage(CommonConstant.DEFAULT_PACKAGE_NAME))
84                 .paths(PathSelectors.any())
85                 .build()
86                 .globalOperationParameters(parameters);
87     }
88
89     private ApiInfo defaultApiInfo() {
90         return new ApiInfoBuilder()
91                 .title("Snowy Doc")
92                 .description("Snowy Doc文档")
93                 .termsOfServiceUrl("https://www.xiaonuo.vip")
94                 .contact(new Contact("xuyuxiang, yubaoshan, dongxiayu", "https://www.xiaonuo.vip", ""))
95                 .version("1.0")
96                 .build();
97     }
98
99     /**
100      * 想分组请放开注释
101      */
102
103     // @Bean
104     // public Docket groupRestApi() {
105     //     List<Parameter> parameters = getParameters();
106     //     return new Docket(DocumentationType.SWAGGER_2)
107     //             .apiInfo(groupApiInfo())
108     //             .groupName("自定义")
109     //             .select()
110     //             //TODO 这里改为自己的包名
111     //             .apis(RequestHandlerSelectors.basePackage("com.example.XXX"))
112     //             .paths(PathSelectors.any())
113     //             .build()
114     //             .globalOperationParameters(parameters);
115     // }
116     //
117     // private ApiInfo groupApiInfo() {
118     //     return new ApiInfoBuilder()
119     //             .title("自定义")
120     //             .description("自定义API")
121     //             .termsOfServiceUrl("http://www.example.com/")
122     //             .version("1.0")
123     //             .build();
124     // }
125
126 }