(轉) 增加 header 參數,spring boot + swagger2(springfox)

來源:互聯網
上載者:User

標籤:require   control   operation   tor   script   rest   class   default   header   

 1 @Configuration 2 @EnableSwagger2 3 public class Swagger2 { 4     @Bean 5     public Docket createRestApi() { 6         String auth = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6Inh4IiwidGVybWluYWwiOiIxfDIiLCJleHAiOjE0OTIwNTIwMzIsIm5iZiI6MTQ5MTg3OTIzMn0.JAmqhJq9rIJOj7WCOm5t2bxcWRmRejADfwUWXmvlSEo"; 7         ParameterBuilder aParameterBuilder = new ParameterBuilder(); 8         aParameterBuilder.name("Authorization").defaultValue(auth).description("i").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); 9 10        // ParameterBuilder aParameterBuilder1 = new ParameterBuilder();11        // aParameterBuilder1.name("token").description("").modelRef(new ModelRef("string")).parameterType("query").required(false).build();12 13         List<Parameter> aParameters = new ArrayList<Parameter>();14         aParameters.add(aParameterBuilder.build());15        // aParameters.add(aParameterBuilder1.build());16 17         return new Docket(DocumentationType.SWAGGER_2)18                 .apiInfo(apiInfo())19                 .useDefaultResponseMessages(false)20                 .globalOperationParameters(aParameters)21                 .select()22                 .apis(RequestHandlerSelectors.basePackage("com.controller"))23                 .paths(PathSelectors.any())24                 .build();25     }26     private ApiInfo apiInfo() {27         return new ApiInfoBuilder()28                 .title("Spring Boot中使用Swagger2構建RESTful APIs")29                 .description("更多Spring Boot相關文章請關註:https://spring.io")30                 .version("1.0.1")31                 .build();32     }33 }

此方法對所有的 rest api 添加 header , 如果想只在部分添加,login這樣的不需要添加怎麼辦呢?暫時沒找到辦法

(轉) 增加 header 參數,spring boot + swagger2(springfox)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.