其他分享
首页 > 其他分享> > Swagger2添加统一header-token

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

}

 

标签:documentation,Swagger2,header,token,API,new,import,springfox,builders
来源: https://www.cnblogs.com/gaomanito/p/10683848.html