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(); } }
既然我已经踏上这条道路,那么,任何东西都不应妨碍我沿着这条路走下去!!!!!!!!!! !!! ! !! !
个人公众号《后端技术开发之路》,欢迎您关注!
如果您觉得我写还不过,请打赏下在下吧!【高木子】!