2021-08-19

@Bean
public Docket controllerApi() {
    // 添加 head 参数配置 start
    ParameterBuilder token = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<>();
    token.name("Authorization").description("token 信息").modelRef(new ModelRef("String"))
            .parameterType("header").required(false).build();
    pars.add(token.build());
    
    return new Docket(DocumentationType.SWAGGER_2)
            .enable(enable)
            .apiInfo(new ApiInfoBuilder()
                    .title(projectName + "接口文档")
                    .description(projectDesc + "")
                    .license("步尔斯特 csdn")
                    .licenseUrl("https://blog.csdn.net")
                    .version(version)
                    .build())
            .select()
            .apis(RequestHandlerSelectors.basePackage(basePackage))
            .paths(PathSelectors.any())
            .build()
            // 注意一下 globalOperationParameters 这行配置
            .globalOperationParameters(pars);
}

猜你喜欢

转载自blog.csdn.net/m0_51945027/article/details/119813321