Skip to content

Commit

Permalink
Use newly introduced lambdas in Spring's API template to avoid genera…
Browse files Browse the repository at this point in the history
…ting uncompilable example code
  • Loading branch information
smasset committed Apr 17, 2019
1 parent 98b3cab commit e202250
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -133,4 +133,4 @@ public interface {{classname}} {

{{/operation}}
}
{{/operations}}
{{/operations}}

0 comments on commit e202250

Please sign in to comment.