diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/IndentedLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/IndentedLambda.java index 72a6cbb4251..d6dceb581be 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/IndentedLambda.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/IndentedLambda.java @@ -109,7 +109,8 @@ public class IndentedLambda implements Mustache.Lambda { String prefixedIndention = StringUtils.repeat(new String(Character.toChars(spaceCode)), prefixSpaceCount); StringBuilder sb = new StringBuilder(); - String[] lines = text.split(System.lineSeparator()); + // use \n instead of System.lineSeparator (e.g. \r\n in Windows) as templates use \n + String[] lines = text.split("\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; // Mustache will apply correct indentation to the first line of a template (to match declaration location). @@ -121,9 +122,9 @@ public class IndentedLambda implements Mustache.Lambda { sb.append(line); - // We've split on the system's line separator. We don't want to add an additional trailing line. + // We've split on \n. We don't want to add an additional trailing line. if (i < lines.length - 1) { - sb.append(System.lineSeparator()); + sb.append("\n"); } } writer.write(sb.toString()); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/templating/mustache/IndentedLambdaTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/templating/mustache/IndentedLambdaTest.java index ef46b2767e7..223afaf913f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/templating/mustache/IndentedLambdaTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/templating/mustache/IndentedLambdaTest.java @@ -6,18 +6,17 @@ import org.testng.annotations.Test; public class IndentedLambdaTest extends LambdaTest { - String lineSeparator = System.lineSeparator(); + String lineSeparator = "\n"; @Test public void defaultIndentTest() { // Given Map ctx = context("indented", new IndentedLambda()); - String lineSeparator = System.lineSeparator(); // When & Then // IndentedLambda applies indentation from second line on of a template. test("first line" + lineSeparator + " second line", - "{{#indented}}first line" + lineSeparator +"second line{{/indented}}", ctx); + "{{#indented}}first line" + lineSeparator + "second line{{/indented}}", ctx); } @Test @@ -28,7 +27,7 @@ public class IndentedLambdaTest extends LambdaTest { // When & Then // IndentedLambda applies indentation from second line on of a template. test("first line" + lineSeparator + " second line", - "{{#indented}}first line" + lineSeparator +"second line{{/indented}}", ctx); + "{{#indented}}first line" + lineSeparator + "second line{{/indented}}", ctx); }