Skip to content

[Java][WebClient][RestClient] Standardize useAbstractionForFiles behavior to use Resource interface#23382

Open
Nawrok wants to merge 1 commit intoOpenAPITools:masterfrom
Nawrok:issue-23381
Open

[Java][WebClient][RestClient] Standardize useAbstractionForFiles behavior to use Resource interface#23382
Nawrok wants to merge 1 commit intoOpenAPITools:masterfrom
Nawrok:issue-23381

Conversation

@Nawrok
Copy link
Copy Markdown

@Nawrok Nawrok commented Mar 27, 2026

This PR updates the webclient and restclient Java generators to use Spring's org.springframework.core.io.Resource interface instead of AbstractResource when using useAbstractionForFiles property. This standardizes the file handling abstraction across all Spring-based HTTP clients, aligning them with the resttemplate implementation.

Fixes #23381

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg


Summary by cubic

Standardized file handling for Java webclient and restclient generators by using Spring’s org.springframework.core.io.Resource (instead of org.springframework.core.io.AbstractResource) when useAbstractionForFiles is enabled, matching resttemplate. Fixes #23381.

  • Refactors

    • Replace org.springframework.core.io.AbstractResource with org.springframework.core.io.Resource for file parameters (single and collections) in webclient and restclient templates.
    • Update tests (re-enable WebClient case) and add samples/client/others/java/restclient-useAbstractionForFiles to the JDK17 workflow matrix.
  • Migration

    • No changes required for most users. Code using AbstractResource can be passed to APIs expecting Resource. Recompile generated clients.

Written for commit cbf9c69. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/Java/libraries/restclient/single_request_parameter.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/restclient/single_request_parameter.mustache:5">
P2: Changing public collection parameter types from `Collection<AbstractResource>` to `Collection<Resource>` introduces a source-compatibility break for existing callers due to Java generic invariance.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


{{^staticRequest}}
public record {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request({{#allParams}}{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.AbstractResource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.AbstractResource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{>nullable_var_annotations}} {{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{>nullable_var_annotations}} {{{dataType}}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){}
public record {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request({{#allParams}}{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.Resource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.Resource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{>nullable_var_annotations}} {{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{>nullable_var_annotations}} {{{dataType}}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){}
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Changing public collection parameter types from Collection<AbstractResource> to Collection<Resource> introduces a source-compatibility break for existing callers due to Java generic invariance.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/restclient/single_request_parameter.mustache, line 5:

<comment>Changing public collection parameter types from `Collection<AbstractResource>` to `Collection<Resource>` introduces a source-compatibility break for existing callers due to Java generic invariance.</comment>

<file context>
@@ -2,27 +2,27 @@
 
     {{^staticRequest}}
-    public record {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request({{#allParams}}{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.AbstractResource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.AbstractResource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{>nullable_var_annotations}} {{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{>nullable_var_annotations}} {{{dataType}}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){}
+    public record {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request({{#allParams}}{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.Resource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.Resource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{>nullable_var_annotations}} {{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{>nullable_var_annotations}} {{{dataType}}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){}
     {{/staticRequest}}
     {{#staticRequest}}
</file context>
Fix with Cubic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a valid point regarding the source-compatibility break caused by Java's generic invariance.

A backward-compatible solution would be to use an upper bound wildcard Collection<? extends Resource>. However, to keep the generated API unified across all Spring-based HTTP clients, we would need to apply this wildcard approach to all generators. This means we would also need to modify the resttemplate generator, which currently uses Collection<Resource> without wildcards.

We have two options: accept the breaking change here to align webclient and restclient with the current resttemplate implementation, or update all of them to use upper bounds.

What is the preferred direction for the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][WebClient][RestClient] Standardize useAbstractionForFiles behavior to use Resource interface

1 participant