forked from loafle/openapi-generator-original
Add option to disable default interfaces (#3022)
This commit is contained in:
parent
45da167f8e
commit
366ca24062
@ -48,6 +48,7 @@ sidebar_label: spring
|
|||||||
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||||
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
|
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
|
||||||
|singleContentTypes|Whether to select only one produces/consumes content-type by operation.| |false|
|
|singleContentTypes|Whether to select only one produces/consumes content-type by operation.| |false|
|
||||||
|
|skipDefaultInterface|Whether to generate default implementations for java8 interfaces| |false|
|
||||||
|async|use async Callable controllers| |false|
|
|async|use async Callable controllers| |false|
|
||||||
|reactive|wrap responses in Mono/Flux Reactor types (spring-boot only)| |false|
|
|reactive|wrap responses in Mono/Flux Reactor types (spring-boot only)| |false|
|
||||||
|responseWrapper|wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)| |null|
|
|responseWrapper|wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)| |null|
|
||||||
|
@ -52,6 +52,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
public static final String DELEGATE_PATTERN = "delegatePattern";
|
public static final String DELEGATE_PATTERN = "delegatePattern";
|
||||||
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
|
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
|
||||||
public static final String VIRTUAL_SERVICE = "virtualService";
|
public static final String VIRTUAL_SERVICE = "virtualService";
|
||||||
|
public static final String SKIP_DEFAULT_INTERFACE = "skipDefaultInterface";
|
||||||
|
|
||||||
public static final String JAVA_8 = "java8";
|
public static final String JAVA_8 = "java8";
|
||||||
public static final String ASYNC = "async";
|
public static final String ASYNC = "async";
|
||||||
@ -79,6 +80,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
protected boolean async = false;
|
protected boolean async = false;
|
||||||
protected boolean reactive = false;
|
protected boolean reactive = false;
|
||||||
protected String responseWrapper = "";
|
protected String responseWrapper = "";
|
||||||
|
protected boolean skipDefaultInterface = false;
|
||||||
protected boolean useTags = false;
|
protected boolean useTags = false;
|
||||||
protected boolean useBeanValidation = true;
|
protected boolean useBeanValidation = true;
|
||||||
protected boolean performBeanValidation = false;
|
protected boolean performBeanValidation = false;
|
||||||
@ -119,6 +121,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern));
|
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern));
|
||||||
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.", singleContentTypes));
|
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.", singleContentTypes));
|
||||||
updateJava8CliOptions();
|
updateJava8CliOptions();
|
||||||
|
cliOptions.add(CliOption.newBoolean(SKIP_DEFAULT_INTERFACE, "Whether to generate default implementations for java8 interfaces", skipDefaultInterface));
|
||||||
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers", async));
|
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers", async));
|
||||||
cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)", reactive));
|
cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)", reactive));
|
||||||
cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)"));
|
cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)"));
|
||||||
@ -234,6 +237,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString()));
|
this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(SKIP_DEFAULT_INTERFACE)) {
|
||||||
|
this.setSkipDefaultInterface(Boolean.valueOf(additionalProperties.get(SKIP_DEFAULT_INTERFACE).toString()));
|
||||||
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(ASYNC)) {
|
if (additionalProperties.containsKey(ASYNC)) {
|
||||||
this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString()));
|
this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString()));
|
||||||
//fix for issue/1164
|
//fix for issue/1164
|
||||||
@ -393,6 +400,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
|
|
||||||
if (this.java8) {
|
if (this.java8) {
|
||||||
additionalProperties.put("javaVersion", "1.8");
|
additionalProperties.put("javaVersion", "1.8");
|
||||||
|
additionalProperties.put("jdk8-default-interface", !this.skipDefaultInterface);
|
||||||
if (!SPRING_CLOUD_LIBRARY.equals(library)) {
|
if (!SPRING_CLOUD_LIBRARY.equals(library)) {
|
||||||
additionalProperties.put("jdk8", true);
|
additionalProperties.put("jdk8", true);
|
||||||
}
|
}
|
||||||
@ -414,6 +422,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
// Some well-known Spring or Spring-Cloud response wrappers
|
// Some well-known Spring or Spring-Cloud response wrappers
|
||||||
if (isNotEmpty(this.responseWrapper)) {
|
if (isNotEmpty(this.responseWrapper)) {
|
||||||
additionalProperties.put("jdk8", false);
|
additionalProperties.put("jdk8", false);
|
||||||
|
additionalProperties.put("jdk8-default-interface", false);
|
||||||
switch (this.responseWrapper) {
|
switch (this.responseWrapper) {
|
||||||
case "Future":
|
case "Future":
|
||||||
case "Callable":
|
case "Callable":
|
||||||
@ -716,6 +725,8 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
this.singleContentTypes = singleContentTypes;
|
this.singleContentTypes = singleContentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSkipDefaultInterface(boolean skipDefaultInterface) { this.skipDefaultInterface = skipDefaultInterface; }
|
||||||
|
|
||||||
public void setJava8(boolean java8) { this.java8 = java8; }
|
public void setJava8(boolean java8) { this.java8 = java8; }
|
||||||
|
|
||||||
public void setVirtualService(boolean virtualService) { this.virtualService = virtualService; }
|
public void setVirtualService(boolean virtualService) { this.virtualService = virtualService; }
|
||||||
|
@ -66,7 +66,7 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
|
|||||||
@VirtualService
|
@VirtualService
|
||||||
{{/virtualService}}
|
{{/virtualService}}
|
||||||
public interface {{classname}} {
|
public interface {{classname}} {
|
||||||
{{#jdk8}}
|
{{#jdk8-default-interface}}
|
||||||
{{^isDelegate}}
|
{{^isDelegate}}
|
||||||
{{^reactive}}
|
{{^reactive}}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public interface {{classname}} {
|
|||||||
return new {{classname}}Delegate() {};
|
return new {{classname}}Delegate() {};
|
||||||
}
|
}
|
||||||
{{/isDelegate}}
|
{{/isDelegate}}
|
||||||
{{/jdk8}}
|
{{/jdk8-default-interface}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
|
|
||||||
{{#virtualService}}
|
{{#virtualService}}
|
||||||
@ -109,13 +109,13 @@ public interface {{classname}} {
|
|||||||
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
|
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
|
||||||
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
|
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
|
||||||
method = RequestMethod.{{httpMethod}})
|
method = RequestMethod.{{httpMethod}})
|
||||||
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{^hasMore}}{{#reactive}}, {{/reactive}}{{/hasMore}}{{/allParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}){{^jdk8}};{{/jdk8}}{{#jdk8}}{{#unhandledException}} throws Exception{{/unhandledException}} {
|
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{^hasMore}}{{#reactive}}, {{/reactive}}{{/hasMore}}{{/allParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}}{{#unhandledException}} throws Exception{{/unhandledException}} {
|
||||||
{{#delegate-method}}
|
{{#delegate-method}}
|
||||||
return {{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}});
|
return {{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override this method
|
// Override this method
|
||||||
{{#jdk8}}default {{/jdk8}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}ServerWebExchange exchange{{/reactive}}) {
|
{{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}ServerWebExchange exchange{{/reactive}}) {
|
||||||
{{/delegate-method}}
|
{{/delegate-method}}
|
||||||
{{^isDelegate}}
|
{{^isDelegate}}
|
||||||
{{>methodBody}}
|
{{>methodBody}}
|
||||||
@ -123,8 +123,8 @@ public interface {{classname}} {
|
|||||||
{{#isDelegate}}
|
{{#isDelegate}}
|
||||||
return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}});
|
return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}});
|
||||||
{{/isDelegate}}
|
{{/isDelegate}}
|
||||||
}{{/jdk8}}
|
}{{/jdk8-default-interface}}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
@ -39,22 +39,22 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
|
|||||||
*/
|
*/
|
||||||
{{>generatedAnnotation}}
|
{{>generatedAnnotation}}
|
||||||
public interface {{classname}}Delegate {
|
public interface {{classname}}Delegate {
|
||||||
{{#jdk8}}
|
{{#jdk8-default-interface}}
|
||||||
|
|
||||||
default Optional<NativeWebRequest> getRequest() {
|
default Optional<NativeWebRequest> getRequest() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
{{/jdk8}}
|
{{/jdk8-default-interface}}
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/**
|
/**
|
||||||
* @see {{classname}}#{{operationId}}
|
* @see {{classname}}#{{operationId}}
|
||||||
*/
|
*/
|
||||||
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
|
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
|
||||||
{{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}},
|
{{/hasMore}}{{/allParams}}{{#reactive}}{{#hasParams}},
|
||||||
{{/hasParams}}ServerWebExchange exchange{{/reactive}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
|
{{/hasParams}}ServerWebExchange exchange{{/reactive}}){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
|
||||||
{{>methodBody}}
|
{{>methodBody}}
|
||||||
}{{/jdk8}}
|
}{{/jdk8-default-interface}}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user