Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4326
Closed
Open
Issue created Oct 30, 2019 by Administrator@rootContributor6 of 6 checklist items completed6/6 checklist items

[BUG][SPRING] delegatePattern + unhandledException configuration Exception not throws

Created by: Thodin3

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

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));

    }
openapi-generator version

4.1.3 and it's not a regression

OpenAPI declaration file content or url

https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/samples/yaml/pet.yml

Command line used for generation
<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>
Steps to reproduce

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

Related issues/PRs

#4327

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/66be33a37b030fced0169b8df392c0d7817b13a1/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache#L118

	{{#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}} {
Assignee
Assign to
Time tracking