OpenAPITools / OpenAPITools/openapi-generator

[REQ] Provide custom ApiException class name to avoid name collisions

Open
#16,403 0 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.

In my projects, it's common to have several Open API clients generated for microservices referenced in the same project. This results in potential for try/catch blocks referring to the wrong ApiException class if you're not careful about your using statements specifying the target client's namespace.

We have a similar issue with our RestSharp clients since RestSharp.ApiException has the same class name.

Describe the solution you'd like

I'd like to be able to provide a different class name for the ApiException class the generated client will throw. Then for each distinct client I could have a unique exception to target (MyApi1Exception, MyApi2Exception, etc).

Describe alternatives you've considered

I'm still new to using the generator, so I suspect this feature already exists but I haven't found much in the documentation or links on google. I did find this DefaultExceptionFactory class which seemed like something we maybe could override or provide our own implementation somehow.

Additional context

None.

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 linked DefaultExceptionFactory discussion and the generator's C# client configuration and templates. Determine where ApiException is named and how a custom name could be passed through generation; done means distinct generated clients can expose distinct exception class names without collisions, with coverage for the new option.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.