• SwaggerConfig


    package me.zhengjie.common.swagger2;
    
    import com.google.common.base.Predicates;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.ParameterBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.schema.ModelRef;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.service.Parameter;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * api页面 /swagger-ui.html
     * 如controller在不同的包中,@ComponentScan(basePackages = {"me.aurora.app.rest","..."})
     * @author jie
     * @date 2018-11-23
     */
    
    @Configuration
    @EnableSwagger2
    @ComponentScan(basePackages = {"me.zhengjie.core.rest","me.zhengjie.system.rest","me.zhengjie.system.monitor"})
    public class SwaggerConfig {
    
        @Bean
        public Docket createRestApi() {
            ParameterBuilder ticketPar = new ParameterBuilder();
            List<Parameter> pars = new ArrayList<Parameter>();
            ticketPar.name("Authorization").description("token")
                    .modelRef(new ModelRef("string"))
                    .parameterType("header")
                    .defaultValue("Bearer ")
                    .required(true)
                    .build();
            pars.add(ticketPar.build());
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .paths(Predicates.not(PathSelectors.regex("/error.*")))
                    .build()
                    .globalOperationParameters(pars);
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("elune 接口文档")
                    .version("1.0")
                    .build();
        }
    
    }
  • 相关阅读:
    16-爬虫之scrapy框架手动请求发送实现全站数据爬取03
    15-爬虫之scrapy框架基于管道实现数据库备份02
    14-爬虫之scrapy框架的基本使用01
    13-爬虫之js加密,解密,混淆,逆向破解思路
    12-基于selenium实现12306模拟登录,及京东登录滑动缺口验证模拟登录
    11-selenium浏览器自动化
    10-异步爬虫(线程池/asyncio协程)实战案例
    09-百度ai图片识别
    08-百度ai语音合成
    RNN
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/11222023.html
Copyright © 2020-2023  润新知