Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83545c5

Browse files
author
Viktar Beliakou
committed
springfox#3189 - return default value if property not found in environment
1 parent d6b4b21 commit 83545c5

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

springfox-spring-web/src/main/java/springfox/documentation/spring/web/DescriptionResolver.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import static org.springframework.util.StringUtils.*;
3030

3131
public class DescriptionResolver {
32-
private static final Pattern PATTERN = Pattern.compile("\\Q${\\E(.+?)(:.*)?\\Q}\\E");
32+
private static final Pattern PATTERN = Pattern.compile("\\Q${\\E(.+?)(:(.*))?\\Q}\\E");
3333
private final Environment environment;
3434
private Map<String, String> cache;
3535

@@ -69,6 +69,7 @@ public String resolve(String expression) {
6969

7070
// Store the value
7171
String key = matcher.group(1);
72+
String defaultValue = matcher.group(3);
7273

7374
// Get the value
7475
String value = environment.getProperty(key);
@@ -82,6 +83,11 @@ public String resolve(String expression) {
8283
// return the value
8384
return value;
8485

86+
} else if (defaultValue != null) {
87+
// use default if value not found
88+
cache.put(expression, defaultValue);
89+
90+
return defaultValue;
8591
}
8692

8793
}

springfox-spring-web/src/test/groovy/springfox/documentation/spring/web/DescriptionResolverSpec.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class DescriptionResolverSpec extends Specification {
2222
"key2value" | '${key2}'
2323
"key2value" | '${key2:}'
2424
"key2value" | '${key2:key2default}'
25+
"key3default" | '${key3:key3default}'
26+
"" | '${key3:}'
2527
'${unknown}' | '${unknown}'
2628
"key1" | 'key1'
2729
"key2" | 'key2'

0 commit comments

Comments
 (0)