swagger-api / swagger-api/swagger-codegen-generators

[Spring] Useless methods in ApiDelegate interface on java8

Open
#600 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

By default, when java8 is used, the ApiDelegate interfaces get default implementations that return a server error and 3 supporting methods that are supposed to be customized.

However if you disable defaultInterfaces, no method body on the APIs get generated, but the 3 supporting methods still are, even though they are unused.

I would propose the following change to the apiDelegate.mustache template to correct this. If that is something you'd consider merging I can also create a pull request for it.

Index: src/main/resources/handlebars/JavaSpring/apiDelegate.mustache
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/resources/handlebars/JavaSpring/apiDelegate.mustache	(revision 5737ffebb86be3c7fa5f098155d77e706d089d08)
+++ src/main/resources/handlebars/JavaSpring/apiDelegate.mustache	(date 1581672639198)
@@ -42,20 +42,21 @@
 {{>generatedAnnotation}}
 public interface {{classname}}Delegate {
 {{#jdk8}}
-
+{{#defaultInterfaces}}
     Logger log = LoggerFactory.getLogger({{classname}}.class);
 
-    {{#defaultInterfaces}}default {{/defaultInterfaces}}Optional<ObjectMapper> getObjectMapper(){{^defaultInterfaces}};{{/defaultInterfaces}}{{#defaultInterfaces}}{
+    default Optional<ObjectMapper> getObjectMapper() {
         return Optional.empty();
-    }{{/defaultInterfaces}}
+    }
 
-    {{#defaultInterfaces}}default {{/defaultInterfaces}}Optional<HttpServletRequest> getRequest(){{^defaultInterfaces}};{{/defaultInterfaces}}{{#defaultInterfaces}}{
+    default Optional<HttpServletRequest> getRequest() {
         return Optional.empty();
-    }{{/defaultInterfaces}}
+    }
 
-    {{#defaultInterfaces}}default Optional<String> getAcceptHeader() {
+    default Optional<String> getAcceptHeader() {
         return getRequest().map(r -> r.getHeader("Accept"));
-    }{{/defaultInterfaces}}
+    }
+{{/defaultInterfaces}}
 {{/jdk8}}
 
 {{#operation}}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/resources/handlebars/JavaSpring/apiDelegate.mustache and compare the jdk8 and defaultInterfaces template branches. Generate or inspect Java 8 Spring output with defaultInterfaces disabled, then confirm the supporting methods are absent while the generated delegate interface remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.