jtlgb

导航

 
@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;
    }
posted on 2019-04-01 20:30  jtlgb  阅读(1390)  评论(0编辑  收藏  举报