swagger-api / swagger-api/swagger-codegen-generators
[Spring] Useless methods in ApiDelegate interface on java8
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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