OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring] Unhandled exception ignored
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
The option to add unhandledException is ignored when skipDefaultInterface is set to true. This behaviour is obvious by inspecting line 132 of the api.mustache.
openapi-generator version
4.3.0
Steps to reproduce
- Generate Spring server code from any specification with unhandledException=true. Observe how the default interface methods have 'throws Exception' declared.
- Generate Spring server code from any specification with unhandledException=true and skipDefaultInterface=true. Observe how the interface methods don't have 'throws Exception' declared.
Related issues/PRs
The PR that added the option. https://github.com/OpenAPITools/openapi-generator/pull/2482
Suggest a fix
I suggest moving the parameter outside of the skipDefaultInterface block so that the 2 options are independent. @jimschubert mentioned on Slack that this could affect people that unknowingly have unhandledException set to true, and skipDefaultInterface set to true also, which is correct to some extent, but having an exception thrown in the interface does not force the implementation to throw it too, so the change is definitely backwards compatible.
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
Inspect modules/openapi-generator/src/main/resources/JavaSpring/api.mustache, especially the referenced line 132 and the skipDefaultInterface block. Generate Spring server code with unhandledException=true both with and without skipDefaultInterface, then verify that the generated interface methods consistently declare throws Exception when requested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100