3232import java .util .Map ;
3333
3434import io .swagger .v3 .oas .models .SpecVersion ;
35- import org .apache .commons .lang3 .StringUtils ;
35+ import java .util .stream .Collectors ;
36+
3637import org .slf4j .Logger ;
3738import org .slf4j .LoggerFactory ;
3839import org .springdoc .core .properties .SpringDocConfigProperties ;
@@ -114,23 +115,24 @@ public String resolve(String parameterProperty, Locale locale) {
114115 * Returns a string where all leading indentation has been removed from each line.
115116 * It detects the smallest common indentation of all the lines in the input string,
116117 * and removes it.
118+ * If the input text is {@code null}, the method returns {@code null}.
117119 *
118- * @param text The original string with possible leading indentation.
119- * @return The string with leading indentation removed from each line.
120+ * @param text The original string with possible leading indentation.
121+ * @return The string with the smallest common leading indentation removed from each line,
122+ * or {@code null} if the input text is {@code null}.
120123 */
121124 public String trimIndent (String text ) {
125+ if (text == null ) {
126+ return null ;
127+ }
128+ final String newLine = "\n " ;
129+ String [] lines = text .split ("\\ r?\\ n" );
130+ int minIndent = resolveMinIndent (lines );
122131 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 );
129132 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 ){
133+ .map (line -> line .substring (Math .min (line .length (), minIndent )))
134+ .collect (Collectors .joining (newLine ));
135+ } catch (Exception ex ) {
134136 LOGGER .warn (ex .getMessage ());
135137 return text ;
136138 }
@@ -239,4 +241,4 @@ public Map<String, Object> resolveExtensions(Locale locale, Map<String, Object>
239241 else
240242 return extensions ;
241243 }
242- }
244+ }
0 commit comments