springdoc-openapi apply default global SecurityScheme possible?

前端 未结 2 1406
無奈伤痛
無奈伤痛 2021-02-07 15:30

I have the following SecurityScheme definition using springdoc-openapi for java SpringBoot RESTful app:

    @Bean
    public OpenAPI customOpenAPI() {
        re         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 16:24

    Tested with v1.2.29 of springdoc-openapi: Its possible to disable security for particular Endpoint using: @SecurityRequirements

    @GetMapping("/open")
    @ResponseBody
    @SecurityRequirements
    public String open() {
        return "It works!";
    }
    

    For older versions, for example tested with v1.2.28 using OperationCustomizer:

    public static final String UNSECURED = "security.open";
    
    @Bean
    public OperationCustomizer customize() {
        return (Operation operation, HandlerMethod handlerMethod) -> {
            List tags = operation.getTags();
            if (tags != null && tags.contains(UNSECURED)) {
                operation.setSecurity(Collections.emptyList());
                operation.setTags(tags.stream()
                        .filter(t -> !t.equals(UNSECURED))
                        .collect(Collectors.toList()));
            }
            return operation;
        };
    }
    

提交回复
热议问题