[Java][WebClient][RestClient] Standardize useAbstractionForFiles behavior to use Resource interface#23382
[Java][WebClient][RestClient] Standardize useAbstractionForFiles behavior to use Resource interface#23382Nawrok wants to merge 1 commit intoOpenAPITools:masterfrom
useAbstractionForFiles behavior to use Resource interface#23382Conversation
…havior to use Resource interface (OpenAPITools#23381)
There was a problem hiding this comment.
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}}){} |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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?
This PR updates the
webclientandrestclientJava generators to use Spring'sorg.springframework.core.io.Resourceinterface instead ofAbstractResourcewhen usinguseAbstractionForFilesproperty. This standardizes the file handling abstraction across all Spring-based HTTP clients, aligning them with theresttemplateimplementation.Fixes #23381
PR checklist
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg
Summary by cubic
Standardized file handling for Java
webclientandrestclientgenerators by using Spring’sorg.springframework.core.io.Resource(instead oforg.springframework.core.io.AbstractResource) whenuseAbstractionForFilesis enabled, matchingresttemplate. Fixes #23381.Refactors
org.springframework.core.io.AbstractResourcewithorg.springframework.core.io.Resourcefor file parameters (single and collections) inwebclientandrestclienttemplates.samples/client/others/java/restclient-useAbstractionForFilesto the JDK17 workflow matrix.Migration
AbstractResourcecan be passed to APIs expectingResource. Recompile generated clients.Written for commit cbf9c69. Summary will update on new commits.