Skip to content

Commit 665d723

Browse files
committed
Refactor trimIndent method: streamline indentation removal and handle exceptions gracefully
1 parent 7af67d7 commit 665d723

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/PropertyResolverUtils.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
import java.util.Map;
3333

3434
import io.swagger.v3.oas.models.SpecVersion;
35-
import org.apache.commons.lang3.StringUtils;
35+
import java.util.stream.Collectors;
36+
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
3839
import org.springdoc.core.properties.SpringDocConfigProperties;
@@ -119,18 +120,17 @@ public String resolve(String parameterProperty, Locale locale) {
119120
* @return The string with leading indentation removed from each line.
120121
*/
121122
public String trimIndent(String text) {
123+
if (text == null) {
124+
return null;
125+
}
126+
final String newLine = "\n";
127+
String[] lines = text.split("\\r?\\n");
128+
int minIndent = resolveMinIndent(lines);
122129
try {
123-
if (text == null) {
124-
return null;
125-
}
126-
final String newLine = "\n";
127-
String[] lines = text.split(newLine);
128-
int minIndent = resolveMinIndent(lines);
129130
return Arrays.stream(lines)
130-
.map(line -> line.substring(Math.min(line.length(), minIndent)))
131-
.reduce((a, b) -> a + newLine + b)
132-
.orElse(StringUtils.EMPTY);
133-
} catch (Exception ex){
131+
.map(line -> line.substring(Math.min(line.length(), minIndent)))
132+
.collect(Collectors.joining(newLine));
133+
} catch (Exception ex) {
134134
LOGGER.warn(ex.getMessage());
135135
return text;
136136
}
@@ -239,4 +239,4 @@ public Map<String, Object> resolveExtensions(Locale locale, Map<String, Object>
239239
else
240240
return extensions;
241241
}
242-
}
242+
}

0 commit comments

Comments
 (0)