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())
                .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();
    }

}

 

上一篇:RabbitMQ——使用Exchange中的topic交换机实现消息发送和接收


下一篇:初入cf总结3