OpenAPITools / OpenAPITools/openapi-generator

[REQ][Java][Microprofile] Use WebApplicationException as default API exception

Open
#21,845 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Currently each Api generates a custom ApiException and its accompanying ApiExceptionMapper implementation although the JavaEE/JakartaEE would define the WebApplicationException as the matching exception in this case making those two classes obsolete in the default configuration.

In our usecase we run into problems when using more than one generated OpenAPI definition as the two separate interfaces create their own ApiException and ApiExceptionMapper where as the mapper implementation can not distinguish between each other by only taking the HTTP response code into account and therefore allways the first one found will win and the resulting ApiException is wrong for the second one.

Describe the solution you'd like

I would propose:

  • using WebApplicationException within the API interface in favor of generating a custom ApiException and ApiExceptionMapper implementations.
  • drop microprofileGlobalExceptionMapper and microprofileRegisterExceptionMapper options all together

Describe alternatives you've considered

Disabling the use of ApiExceptionMapper by setting microprofileGlobalExceptionMapper and microprofileRegisterExceptionMapper to false. Those will relax the wrong type creation for now. The downside is that the both classes are superflows.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the generated API interface and the ApiException and ApiExceptionMapper generation paths, then trace how microprofileGlobalExceptionMapper and microprofileRegisterExceptionMapper affect them. Done means the default generated API uses WebApplicationException, the custom exception and mapper are no longer generated by default, and the related options are removed or accounted for.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.