Skip to content

[CAT-2382] Enable useSingleRequestParameter for Java Client Generator#203

Merged
dvacca-onfido merged 1 commit intomasterfrom
feat/enable-single-request-parameter-java
Feb 12, 2026
Merged

[CAT-2382] Enable useSingleRequestParameter for Java Client Generator#203
dvacca-onfido merged 1 commit intomasterfrom
feat/enable-single-request-parameter-java

Conversation

@dvacca-onfido
Copy link
Copy Markdown
Contributor

@dvacca-onfido dvacca-onfido commented Jan 29, 2026

Summary

Enables the useSingleRequestParameter configuration option for the Java okhttp-gson client generator to prevent breaking changes when adding optional parameters to API methods.

Problem

Currently, when a new optional parameter is added to an API endpoint, the generated Java client adds a new parameter to the method signature. This creates a breaking change for existing implementations, forcing all consumers to update their code even if they don't need the new parameter.

Solution

The useSingleRequestParameter option changes the code generation pattern to use request builder objects:

Before (breaking changes on new optional params)

List<WorkflowRun> runs = onfido.listWorkflowRuns(applicantId, status, page, perPage, sort);
// Adding a new optional parameter 'createdAt' would break this code

After (backward compatible)

List<WorkflowRun> runs = onfido.listWorkflowRuns()
    .applicantId(applicantId)
    .status(status)
    .page(page)
    .execute();
// New optional parameters like .createdAt() can be added without breaking existing code

Benefits

  • Backward Compatibility: Existing code continues to work when new optional parameters are added
  • Forward Compatibility: New releases with additional optional parameters don't break consumer code
  • Better API Design: Optional parameters are more discoverable and explicit
  • Cleaner Code: Fluent API pattern is more readable, especially with many optional parameters

Changes

  • Added useSingleRequestParameter: true to generators/java/okhttp-gson/config.yaml

Testing

  • Configuration validated in generator test runs
  • See companion PR in onfido-java repository for test adaptations

Migration Notes

This is a breaking change that requires updating all API method calls to use .execute(). However, once adopted, future changes will be non-breaking.

Related PRs

Add useSingleRequestParameter option to Java okhttp-gson generator configuration
to prevent breaking changes when adding optional parameters to API methods.

This configuration generates a request builder pattern where:
- API methods return request objects with fluent setters for optional parameters
- .execute() must be called to perform the actual API request
- New optional parameters become new setter methods, not new method parameters

Benefits:
- Backward compatibility: existing code continues to work when new optional params are added
- Forward compatibility: new optional parameters don't break existing implementations
- Cleaner API: optional parameters are more discoverable and explicit

Example:
- Before: onfido.listWorkflowRuns(applicantId, status, page, sort)
- After: onfido.listWorkflowRuns().applicantId(id).status(status).page(1).execute()
@dvacca-onfido dvacca-onfido merged commit 4a7f7a9 into master Feb 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants