diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringCodegen.java index 3ea33573ce7..43bb6fcdb85 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringCodegen.java @@ -5,6 +5,8 @@ import io.swagger.codegen.*; import io.swagger.codegen.languages.features.BeanValidationFeatures; import io.swagger.codegen.languages.features.OptionalFeatures; +import io.swagger.codegen.mustache.SplitStringLambda; +import io.swagger.codegen.mustache.TrimWhitespaceLambda; import io.swagger.models.Operation; import io.swagger.models.Path; import io.swagger.models.Swagger; @@ -351,6 +353,10 @@ public void execute(Template.Fragment fragment, Writer writer) throws IOExceptio writer.write(fragment.execute().replaceAll("\\r|\\n", "")); } }); + + additionalProperties.put("lambdaTrimWhitespace", new TrimWhitespaceLambda()); + + additionalProperties.put("lambdaSplitString", new SplitStringLambda()); } @Override diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache index 0c67e70c9ac..b8182b83b84 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache @@ -113,7 +113,7 @@ public interface {{classname}} { {{#examples}} if (getAcceptHeader().get().contains("{{{contentType}}}")) { try { - String exampleString = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}"; + String exampleString = {{#lambdaSplitString}}{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{#lambdaTrimWhitespace}}{{{example}}}{{/lambdaTrimWhitespace}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}{{/lambdaSplitString}}; return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(getObjectMapper().get().readValue(exampleString, {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}}; } catch (IOException e) { log.error("Couldn't serialize response for content type {{{contentType}}}", e); @@ -133,4 +133,4 @@ public interface {{classname}} { {{/operation}} } -{{/operations}} \ No newline at end of file +{{/operations}}