OpenAPITools / OpenAPITools/openapi-generator
[Java][Spring] Make generated API controller methods throwing Exception.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Spring allows general error handling based on exceptions. It requires the controller method throws plain Java exceptions. Generated API interface should not restrict this behavior. In other words the code
@RequestMapping(value = "/users", method = RequestMethod.POST)
ResponseEntity usersPost(@RequestBody UserCreation userCreationRequest);
should become
@RequestMapping(value = "/users", method = RequestMethod.POST)
ResponseEntity usersPost(@RequestBody UserCreation userCreationRequest) throws Exception;
One can make this feature configurable over the configuration parameter. For example in case of Maven plugin:
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<controllerThrowsExceptions>java.io.IOException,com.example.NotFoundException</controllerThrowsExceptions>
openapi-generator version
openapi-generator-maven-plugin, version 3.3.3
Related issues/PRs
Similar request in swagger-codegen project:
https://github.com/swagger-api/swagger-codegen/issues/5686
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
Start by locating the Java Spring controller generation path and the Maven plugin configuration handling supporting files. Verify how generated controller method declarations are produced, then confirm that the requested exception behavior is configurable and reflected in generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100