Skip to content

Commit 3d57782

Browse files
committed
Switched to reactive Springdoc dependency and adjusted OpenApiConfig #deploy-kodeverk-service
The used Springdoc OpenAPI starter dependency was switched from 'springdoc-openapi-starter-webmvc-ui' to 'springdoc-openapi-starter-webflux-ui' making the application more reactive. Alongside this main change, the 'OpenApiConfig.java' was adjusted to implement 'WebFilter', changing the handling of authentication headers and introducing a new method for routing '/swagger' requests to '/swagger-ui.html'.
1 parent 13684ca commit 3d57782

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

apps/kodeverk-service/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencies {
5353
implementation 'org.springframework.boot:spring-boot-starter-cache'
5454

5555
implementation 'io.micrometer:micrometer-registry-prometheus'
56-
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
56+
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.3.0'
5757
implementation 'io.swagger.core.v3:swagger-annotations-jakarta:2.2.20'
5858

5959
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'

apps/kodeverk-service/src/main/java/no/nav/testnav/kodeverkservice/config/OpenApiConfig.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
import no.nav.testnav.libs.reactivecore.config.ApplicationProperties;
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.http.HttpHeaders;
14+
import org.springframework.web.server.ServerWebExchange;
15+
import org.springframework.web.server.WebFilter;
16+
import org.springframework.web.server.WebFilterChain;
17+
import reactor.core.publisher.Mono;
1318

1419
import java.util.Arrays;
1520

1621
@Configuration
17-
public class OpenApiConfig {
22+
public class OpenApiConfig implements WebFilter {
1823

1924
@Bean
2025
public OpenAPI openApi(ApplicationProperties applicationProperties) {
@@ -24,7 +29,7 @@ public OpenAPI openApi(ApplicationProperties applicationProperties) {
2429
.scheme("bearer")
2530
.bearerFormat("JWT")
2631
.in(SecurityScheme.In.HEADER)
27-
.name("Authorization")
32+
.name(HttpHeaders.AUTHORIZATION)
2833
))
2934
.addSecurityItem(
3035
new SecurityRequirement().addList("bearer-jwt", Arrays.asList("read", "write")))
@@ -44,4 +49,17 @@ public OpenAPI openApi(ApplicationProperties applicationProperties) {
4449
)
4550
);
4651
}
52+
53+
@Override
54+
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
55+
if (exchange.getRequest().getURI().getPath().equals("/swagger")) {
56+
return chain
57+
.filter(exchange.mutate()
58+
.request(exchange.getRequest()
59+
.mutate().path("/swagger-ui.html").build())
60+
.build());
61+
}
62+
63+
return chain.filter(exchange);
64+
}
4765
}

0 commit comments

Comments
 (0)