Skip to content

Commit 8a7dca1

Browse files
sonOfRafrantuma
authored andcommitted
Add defaultInterfaces config key to spring2 template
1 parent 4a7d0f4 commit 8a7dca1

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/Spring2Codegen.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class Spring2Codegen extends AbstractJavaCodegen implements BeanValidatio
4343
public static final String IMPLICIT_HEADERS = "implicitHeaders";
4444
public static final String SWAGGER_DOCKET_CONFIG = "swaggerDocketConfig";
4545
public static final String TARGET_OPENFEIGN = "generateForOpenFeign";
46+
public static final String DEFAULT_INTERFACES = "defaultInterfaces";
4647

4748
protected String title = "swagger-petstore";
4849
protected String configPackage = "io.swagger.configuration";
@@ -60,6 +61,7 @@ public class Spring2Codegen extends AbstractJavaCodegen implements BeanValidatio
6061
protected boolean swaggerDocketConfig = false;
6162
protected boolean useOptional = false;
6263
protected boolean openFeign = false;
64+
protected boolean defaultInterfaces = true;
6365

6466
public Spring2Codegen() {
6567
super();
@@ -91,6 +93,7 @@ public Spring2Codegen() {
9193
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,
9294
"Use Optional container for optional parameters"));
9395
cliOptions.add(CliOption.newBoolean(TARGET_OPENFEIGN,"Generate for usage with OpenFeign (instead of feign)"));
96+
cliOptions.add(CliOption.newBoolean(DEFAULT_INTERFACES, "Generate default implementations for interfaces").defaultValue("true"));
9497

9598
supportedLibraries.put(DEFAULT_LIBRARY, "Spring-boot Server application using the SpringFox integration.");
9699
supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration.");
@@ -207,6 +210,10 @@ public void processOpts() {
207210
this.setOpenFeign(convertPropertyToBoolean(TARGET_OPENFEIGN));
208211
}
209212

213+
if (additionalProperties.containsKey(DEFAULT_INTERFACES)) {
214+
this.setDefaultInterfaces(Boolean.valueOf(additionalProperties.get(DEFAULT_INTERFACES).toString()));
215+
}
216+
210217
if (useBeanValidation) {
211218
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
212219
}
@@ -760,4 +767,8 @@ public void setUseOptional(boolean useOptional) {
760767
public void setOpenFeign(boolean openFeign) {
761768
this.openFeign = openFeign;
762769
}
770+
771+
public void setDefaultInterfaces(boolean defaultInterfaces) {
772+
this.defaultInterfaces = defaultInterfaces;
773+
}
763774
}

src/main/resources/handlebars/JavaSpring2/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public interface {{classname}} {
102102
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
103103
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
104104
method = RequestMethod.{{httpMethod}})
105-
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
105+
{{#defaultInterfaces}}default {{/defaultInterfaces}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}){{^defaultInterfaces}};{{/defaultInterfaces}}{{#defaultInterfaces}} {
106106
{{#delegate-method}}
107107
return {{operationId}}({{#parameters}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});
108108
}
@@ -130,7 +130,7 @@ public interface {{classname}} {
130130
{{#isDelegate}}
131131
return getDelegate().{{operationId}}({{#parameters}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});
132132
{{/isDelegate}}
133-
}{{/jdk8}}
133+
}{{/defaultInterfaces}}
134134

135135
{{/contents}}
136136
{{/operation}}

src/main/resources/handlebars/JavaSpring2/apiDelegate.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public interface {{classname}}Delegate {
6363
/**
6464
* @see {{classname}}#{{operationId}}
6565
*/
66-
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#parameters}}{{^isFile}} {{>optionalDataType}} {{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
67-
{{/hasMore}}{{/parameters}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
66+
{{#defaultInterfaces}}default {{/defaultInterfaces}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#parameters}}{{^isFile}} {{>optionalDataType}} {{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
67+
{{/hasMore}}{{/parameters}}){{^defaultInterfaces}};{{/defaultInterfaces}}{{#defaultInterfaces}} {
6868
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
6969
{{#examples}}
7070
if (getAcceptHeader().get().contains("{{{contentType}}}")) {
@@ -80,7 +80,7 @@ public interface {{classname}}Delegate {
8080
log.warn("ObjectMapper or HttpServletRequest not configured in default {{classname}} interface so no example is generated");
8181
}
8282
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
83-
}{{/jdk8}}
83+
}{{/defaultInterfaces}}
8484

8585
{{/contents}}
8686
{{/operation}}

0 commit comments

Comments
 (0)