Swagger2添加统一header-token

package com.gx.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
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;


@Configuration
@EnableSwagger2
@ConditionalOnProperty(prefix = "gx.swagger-ui", value = {"enabled"}, havingValue = "true")
public class Swagger2Config {

    private static final String CHITIC_BANK_API_PACKAGE = "com.gx.controller";

    @Bean
    public Docket pdaApi() {
        List<Parameter> parameters = new ArrayList<>();
        parameters.add(new ParameterBuilder()
                .name("token")
                .description("认证token")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build());
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("SpringBoot1.0 API")
                .apiInfo(pdaApiInfo())
.globalOperationParameters(parameters) .select() .apis(RequestHandlerSelectors.basePackage(CHITIC_BANK_API_PACKAGE)) .paths(PathSelectors.any()) .build(); }
private ApiInfo pdaApiInfo() { return new ApiInfoBuilder() .title("SpringBoot1.0接口") .description("SpringBoot1.0 API接口文档") .version("v1.0") .build(); } }

 

posted @ 2019-04-10 15:45  高木子  阅读(10935)  评论(4编辑  收藏  举报