@Bean
public Docket apiDocument() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("api")
.select() .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(regex("/api.*"))
.build()
.pathMapping("/")
.globalOperationParameters(setHeaderToken())
.apiInfo(metadata());
}
主要添加 globalOperationParameters(setHeaderToken())
private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name("X-Auth-Token").description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
return pars;
}