OpenAPITools / OpenAPITools/openapi-generator

[Java] Generate overloaded methods to support backward compatibility with optional parameters

Open
#19,631 1 comment 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.

If the server adds an optional parameter, that is a backward compatible and non-breaking change. However, when the client pulls in the latest spec and generates code, the optional parameter is added as an argument to the pre-existing method which breaks the client-side code. If the API change is non-breaking, client code should not break.

Describe the solution you'd like

If the codegen was updated to generate overloaded methods, client code would not break. Suppose for example the client was previously bound to an API with no parameters, and the client code was api.getData(). If overloaded methods are generated and an optional parameter was added, the client should would have the choice of continuing to call api.getData() (which would maintain existing behavior) or api.getData(newParam).

Describe alternatives you've considered

Adding a config option like useOptionals to cause the codegen to wrap optional params in an Optional<> would also be an improvement as the method signature is clear, but would still cause a breaking change in clients.

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

The issue does not name specific files, tests, or entry points. Start by tracing Java client method generation in the OpenAPI Generator codegen implementation and templates, then identify the existing tests for generated method signatures; done means optional-parameter additions preserve the previous overload while supporting the new argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
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.