How to add @SecurityRequirement(name = “X-API-KEY”) from microservice swagger in Central Swagger in spring cloud Gateway

i have an issue when i add authorizations from spring gateway like this
image 1
image 2

when i hit the swagger api

the api key not send to the api, and get error like this
image 3

the log in microservice not detect the api key that i send from gateway
image 4

the code that i have in spring gate way like this

import org.springdoc.core.properties.SwaggerUiConfigParameters;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

@Configuration
public class SwaggerConfig {

    @Bean
    public CommandLineRunner openApiGroups(
            RouteDefinitionLocator locator,
            SwaggerUiConfigParameters swaggerUiConfigParameters) {
        return args -> Objects.requireNonNull(locator
                .getRouteDefinitions().collectList().block())
                .stream()
                .map(RouteDefinition::getId)
                .filter(id -> id.matches(".*-service"))
                .map(id -> id.replace("-service", ""))
                .forEach(swaggerUiConfigParameters::addGroup);
    }
}

and micro service like this

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
    @Bean
    public OpenAPI customOpenAPI(){
        final String API_KEY_HEADER_NAME = "X-API-KEY";
        final String securitySchemeName = "ApiKeyAuth";
        return new OpenAPI()
                .info(new Info().title("API Documentation")
                        .version("v1")
                        .description("This is the API documentation for our application.")
                        .license(new License().name("Apache 2.0").url("https://springdoc.org")))
                .addSecurityItem(new SecurityRequirement().addList(API_KEY_HEADER_NAME))
                .components(new Components()
                        .addSecuritySchemes(API_KEY_HEADER_NAME, new SecurityScheme()
                                .name(API_KEY_HEADER_NAME)
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name(API_KEY_HEADER_NAME)));
    }
}

and the application.yaml in spring gateway like this

server:
  port: 5656

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      httpclient:
        connect-timeout: 10000
        response-timeout: 7s
      routes:
        - id: ms-idm-service
          uri: "http://localhost:6992/"
          predicates:
            - Path=/api/v1/menu/* , /v3/api-docs/ms-idm
        - id: ms-master-data-service
          uri: "http://localhost:6991/"
          predicates:
            - Path=/api/v1/role-code/* , /v3/api-docs/ms-master-data
          filters:
            - AddRequestHeader=X-API-KEY , f098c80f-f140-4f92-9db6-98b47b84c2b7

    discovery:
      enabled: true

resilience4j:
  time limiter:
    configs:
      default:
        timeoutDuration: 7000
        cancelRunningFuture: true

logging:
  level:
    org:
      springframework:
        cloud.gateway: DEBUG
        http.server.reactive: DEBUG
        web.reactive: DEBUG

this is the example of microservice controller

@GetMapping
    @Operation(summary = "Get All Role Code",security = {@SecurityRequirement(name = "X-API-KEY")})
    public ResponseEntity<ApiResponse> getAll(){
        List<TRoleCodeResponseDTO> tRoleCodeResponseDTOS = tRoleCodeService.getAll();
        return responseBuilderHelper.buildSingleResponse(ResponseEnum.SUCCESS, API_VERSION_1,
                Integer.toString(Constants.OK), Constants.GLB_MESSAGE_SUCCESS, tRoleCodeResponseDTOS);
    }

anyone have the solution ?

i have try like this and nothing happen

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class ApiKeyAuthorizationFilter implements GatewayFilter {

    private static final String API_KEY_PARAM = "f098c80f-f140-4f92-9db6-98b47b84c2b7";
    private static final String AUTHORIZATION_HEADER = "Authorization";

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String apiKey = exchange.getRequest().getQueryParams().getFirst(API_KEY_PARAM);

        if (apiKey != null && !apiKey.isEmpty()) {
            HttpHeaders headers = exchange.getRequest().getHeaders();
            headers.set(AUTHORIZATION_HEADER, "Bearer " + apiKey);

            return chain.filter(exchange);
        }

        return Mono.error(new NullPointerException());
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật