Skip to content

Commit e9331fd

Browse files
committed
openApi.getServers() is null in OpenApiCustomiser when using different locales. Fixes #2155
1 parent 2526ba4 commit e9331fd

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
339339
);
340340
if (!CollectionUtils.isEmpty(openAPI.getServers()))
341341
openAPIService.setServersPresent(true);
342+
else
343+
openAPIService.setServersPresent(false);
342344
openAPIService.updateServers(openAPI);
343345

344346
if (springDocConfigProperties.isRemoveBrokenReferenceDefinitions())

springdoc-openapi-common/src/test/java/org/springdoc/api/AbstractOpenApiResourceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public void setUp() {
120120

121121
when(openAPIService.getContext()).thenReturn(context);
122122
when(openAPIService.build(any())).thenReturn(openAPI);
123+
doAnswer(new CallsRealMethods()).when(openAPIService).setServersPresent(false);
123124

124125
when(openAPIBuilderObjectFactory.getObject()).thenReturn(openAPIService);
125126
when(springDocProviders.jsonMapper()).thenReturn(Json.mapper());

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app189/SpringDocApp189Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class SpringDocApp189Test extends AbstractCommonTest {
3434

3535
@Test
3636
public void testWithDifferentLocales() throws Exception {
37-
runTestWithLocale("en-GB");
38-
runTestWithLocale("de-DE");
37+
runTestWithLocale("en-GB");
38+
runTestWithLocale("de-DE");
3939
}
4040

4141
private void runTestWithLocale(String locale) throws JSONException {

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app189/SpringDocTestApp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
import io.swagger.v3.oas.models.info.License;
2525
import io.swagger.v3.oas.models.security.SecurityScheme;
2626
import org.springdoc.core.customizers.OpenApiCustomiser;
27-
import org.springframework.boot.SpringApplication;
2827
import org.springframework.boot.autoconfigure.SpringBootApplication;
2928
import org.springframework.context.annotation.Bean;
3029
import org.springframework.context.annotation.ComponentScan;
3130

3231
@SpringBootApplication
3332
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app189" })
3433
public class SpringDocTestApp {
35-
public static void main(String[] args) {
36-
SpringApplication.run(SpringDocTestApp.class, args);
37-
}
38-
3934
@Bean
4035
public OpenAPI customOpenAPI() {
4136
return new OpenAPI()
@@ -51,7 +46,6 @@ OpenApiCustomiser serverUrlCustomizer() {
5146
openApi.getServers().forEach(server -> {
5247
server.setDescription("customized description");
5348
server.setUrl("https://customized.url");
54-
System.out.println(server);
5549
});
5650
}
5751
}

0 commit comments

Comments
 (0)