Skip to content

Commit 9cbfff9

Browse files
committed
Merge branch 'master' of https://github.com/springdoc/springdoc-openapi into 1354_unit_test_170
2 parents b4fc7d2 + e995192 commit 9cbfff9

File tree

8 files changed

+102
-14
lines changed

8 files changed

+102
-14
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import com.fasterxml.jackson.annotation.JsonView;
4747
import com.fasterxml.jackson.core.JsonProcessingException;
48+
import com.fasterxml.jackson.core.type.TypeReference;
4849
import com.fasterxml.jackson.databind.MapperFeature;
4950
import com.fasterxml.jackson.databind.ObjectMapper;
5051
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -321,8 +322,17 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
321322

322323
// run the optional customisers
323324
List<Server> servers = openApi.getServers();
325+
List<Server> serversCopy = null;
326+
try {
327+
serversCopy = Json.mapper()
328+
.readValue(Json.mapper().writeValueAsString(servers), new TypeReference<List<Server>>() {});
329+
}
330+
catch (JsonProcessingException e) {
331+
LOGGER.warn("Json Processing Exception occurred: {}", e.getMessage());
332+
}
333+
324334
openApiCustomisers.ifPresent(apiCustomisers -> apiCustomisers.forEach(openApiCustomiser -> openApiCustomiser.customise(openApi)));
325-
if ((!CollectionUtils.isEmpty(openApi.getServers()) && !Objects.equals(servers, openApi.getServers())))
335+
if (!CollectionUtils.isEmpty(openApi.getServers()) && !openApi.getServers().equals(serversCopy))
326336
openAPIService.setServersPresent(true);
327337

328338
openAPIService.setCachedOpenAPI(openApi, locale);

springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ public class OpenAPIService {
211211
*/
212212
public static String splitCamelCase(String str) {
213213
return str.replaceAll(
214-
String.format(
215-
"%s|%s|%s",
216-
"(?<=[A-Z])(?=[A-Z][a-z])",
217-
"(?<=[^A-Z])(?=[A-Z])",
218-
"(?<=[A-Za-z])(?=[^A-Za-z])"),
219-
"-")
214+
String.format(
215+
"%s|%s|%s",
216+
"(?<=[A-Z])(?=[A-Z][a-z])",
217+
"(?<=[^A-Z])(?=[A-Z])",
218+
"(?<=[A-Za-z])(?=[^A-Za-z])"),
219+
"-")
220220
.toLowerCase(Locale.ROOT);
221221
}
222222

@@ -375,7 +375,10 @@ private void addTags(List<Tag> sourceTags, Set<io.swagger.v3.oas.models.tags.Tag
375375
Optional<Set<io.swagger.v3.oas.models.tags.Tag>> optionalTagSet = AnnotationsUtils
376376
.getTags(sourceTags.toArray(new Tag[0]), false);
377377
optionalTagSet.ifPresent(tagsSet -> {
378-
tagsSet.forEach(tag -> tag.name(propertyResolverUtils.resolve(tag.getName(), locale)));
378+
tagsSet.forEach(tag -> {
379+
tag.name(propertyResolverUtils.resolve(tag.getName(), locale));
380+
tag.description(propertyResolverUtils.resolve(tag.getDescription(), locale));
381+
});
379382
tags.addAll(tagsSet);
380383
});
381384
}
@@ -718,7 +721,7 @@ public void addMappings(Map<String, Object> mappings) {
718721
public Map<String, Object> getControllerAdviceMap() {
719722
Map<String, Object> controllerAdviceMap = context.getBeansWithAnnotation(ControllerAdvice.class);
720723
return Stream.of(controllerAdviceMap).flatMap(mapEl -> mapEl.entrySet().stream()).filter(
721-
controller -> (AnnotationUtils.findAnnotation(controller.getValue().getClass(), Hidden.class) == null))
724+
controller -> (AnnotationUtils.findAnnotation(controller.getValue().getClass(), Hidden.class) == null))
722725
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1, LinkedHashMap::new));
723726
}
724727

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app170;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class HelloController {
8+
@GetMapping("hello")
9+
public String hello() {
10+
return "Hello";
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package test.org.springdoc.api.app170;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springdoc.core.customizers.OpenApiCustomiser;
5+
import test.org.springdoc.api.AbstractSpringDocTest;
6+
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.Bean;
9+
10+
11+
public class SpringDocApp170Test extends AbstractSpringDocTest {
12+
13+
@SpringBootApplication
14+
static class SpringDocTestApp {
15+
@Bean
16+
public OpenApiCustomiser openApiCustomiser() {
17+
return openApi -> openApi.getServers().forEach(s -> s.url("URL"));
18+
}
19+
}
20+
21+
@Test
22+
public void testApp1() throws Exception {
23+
this.testApp();
24+
}
25+
26+
}

springdoc-openapi-webmvc-core/src/test/resources/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ greeting=Hello! Welcome to our website!
22
lang.change=Change the language
33
lang.eng=English
44
lang.fr=French
5-
mySample=toto
5+
mySample=toto
6+
test=This is a test message

springdoc-openapi-webmvc-core/src/test/resources/results/app14.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
],
1313
"tags": [
1414
{
15-
"name": "Change the language"
15+
"name": "Hello! Welcome to our website!",
16+
"description": "This is a test message"
1617
},
1718
{
18-
"name": "Hello! Welcome to our website!",
19-
"description": "test"
19+
"name": "Change the language"
2020
}
2121
],
2222
"paths": {

springdoc-openapi-webmvc-core/src/test/resources/results/app161.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"tags": [
1717
"hello-controller"
1818
],
19-
"summary": "test",
19+
"summary": "This is a test message",
2020
"operationId": "test",
2121
"requestBody": {
2222
"content": {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "URL",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/hello": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "hello",
20+
"responses": {
21+
"200": {
22+
"description": "OK",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"components": {}
36+
}

0 commit comments

Comments
 (0)