@Configuration
@EnableSwagger2
public class SwaggerConfig {
// 设置默认TOKEN,方便测试
private static final String TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbi1bXSIsImlhdCI6MTY1MDE1OTY5MiwiZXhwIjoxNjUwMTg5NjkyfQ.SqJw_zheT9A8sWsqL3sSGRMuNkY_Oi-SJh1ztqq-zx61Vv0t66WsxZOGspLt2CqIzaKXzq-jmnpjkpsy_44S4w";
@Bean
public Docket api() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
tokenPar.name("Authorization").description("令牌").defaultValue(TOKEN).modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.zdc.controller"))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(pars)
.apiInfo(apiInfo())
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 queue").responseModel(new ModelRef("Error")).build(), new ResponseMessageBuilder().code(403).message("Forbidden!!!!!").build()));
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("api")
.description("")
.version("1.0")
.build();
}
}