When using delegatePattern + unhandledException configuration :
<configOptions>
<delegatePattern>true</delegatePattern>
<unhandledException>true</unhandledException>
</configOptions>
In the interface, we have :
default ResponseEntity<Elements> _getElements(@RequestHeader(value="If-Modified-Since", required=false) OffsetDateTime ifModifiedSince) throws Exception {
return getElements(ifModifiedSince);
}
// Override this method
default ResponseEntity<Shipments> getElements(OffsetDateTime ifModifiedSince) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(...);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.valueOf(200));
}
And we need to throws Exception also in the delegate method otherwise, it's not possible to implement it with the unhandled Exception (signature changed).
Would it possible to have:
default ResponseEntity<Elements> _getElements(@RequestHeader(value="If-Modified-Since", required=false) OffsetDateTime ifModifiedSince) throws Exception {
return getElements(ifModifiedSince);
}
// Override this method
default ResponseEntity<Shipments> getElements(OffsetDateTime ifModifiedSince) throws Exception {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(...);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.valueOf(200));
}
4.1.3 and it's not a regression
https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/samples/yaml/pet.yml
<configuration>
...
<configOptions>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>true</delegatePattern>
<unhandledException>true</unhandledException>
<library>spring-mvc</library>
</configOptions>
<library>spring-mvc</library>
</configuration>
1/ run with any swagger openAPI or not
2/ configure delegatePattern + unhandledException
3/ generate code for JAVA Spring
4/ have a look to the interface and the throws Exception in delegate methods
{{#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}}){{#unhandledException}} throws Exception{{/unhandledException}} {
Most helpful comment
4327