懒羊羊
2023-11-14 1f34866e4697920d4d9d2c59830b450136393d54
提交 | 用户 | 时间
71e81e 1 /**
2  * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
3  * <p>
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  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
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 package cn.stylefeng.guns.config.web;
17
18 import io.swagger.annotations.ApiOperation;
19 import org.springframework.context.annotation.Bean;
20 import org.springframework.context.annotation.Configuration;
21 import springfox.documentation.builders.ApiInfoBuilder;
22 import springfox.documentation.builders.PathSelectors;
23 import springfox.documentation.builders.RequestHandlerSelectors;
24 import springfox.documentation.service.ApiInfo;
25 import springfox.documentation.service.Contact;
26 import springfox.documentation.spi.DocumentationType;
27 import springfox.documentation.spring.web.plugins.Docket;
28 import springfox.documentation.swagger2.annotations.EnableSwagger2;
29
30 /**
31  * swagger配置类
32  *
33  * @author fengshuonan
34  * @date 2017年6月1日19:42:59
35  */
36 @Configuration
37 @EnableSwagger2
38 public class SwaggerConfig {
39
40     @Bean
41     public Docket createRestApi() {
42         return new Docket(DocumentationType.SWAGGER_2)
43                 .apiInfo(apiInfo())
44                 .select()
45                 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))                         //这里采用包含注解的方式来确定要显示的接口
46                 //.apis(RequestHandlerSelectors.basePackage("cn.stylefeng.guns.modular.system.controller"))     //这里采用包扫描的方式来确定要显示的接口
47                 .paths(PathSelectors.any())
48                 .build();
49     }
50
51     private ApiInfo apiInfo() {
52         return new ApiInfoBuilder()
53                 .title("Guns Doc")
54                 .description("Guns Api文档")
55                 .termsOfServiceUrl("https://gitee.com/stylefeng/guns")
56                 .contact(new Contact("stylefeng", "https://gitee.com/stylefeng/guns", ""))
57                 .version("2.0")
58                 .build();
59     }
60
61 }