Repository navigation
Conversation
- Only null-check optional header, cookie and form parameters (and use braces); required parameters are already validated to be non-null - Pass the request body to invokeAPI directly instead of through a redundant postBody local variable - Use the diamond operator for generic instantiations; for anonymous ParameterizedTypeReference classes only when targeting Java 17 - Set the java17 flag for resttemplate when using Jakarta EE and use it to select the Java version in its pom.xml and build.gradle (which also removes duplicated source/target elements with Spring Boot 4)
The sample on master is out of date after OpenAPITools#25064 and OpenAPITools#25089 were merged concurrently, which fails the "Samples up-to-date" check.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 145 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simplifies the API code generated by the Spring-based Java client libraries (
webclient,restclient,resttemplate), which share the same template structure. IDEs (e.g. IntelliJ) flag the current output with several warnings.Example (webclient, before):
After:
Changes (in all three libraries unless noted):
if (param != null), which is always true for required parameters, as they are already validated to be non-null (an exception is thrown otherwise) at the start of the method. These are now added unconditionally; optional parameters keep the null check, now with braces. This also reduces the cyclomatic complexity of the generated methods.postBodylocal variable. It was only ever assigned from the body parameter (ornull) and passed toinvokeAPI, so the body is now passed directly. Same forlocalVarPostBody = requestin resttemplate's genericinvokeAPIhelper.HashMap/LinkedMultiValueMapinstantiations. For anonymousParameterizedTypeReferencesubclasses the diamond operator requires Java 9+, so it is only used when the generated project targets Java 17 (webclient,resttemplatecan still target Java 1.8;restclientalready used it).JavaClientCodegennow sets the existingjava17flag for resttemplate whenuseJakartaEeis enabled (same as for webclient), and itspom.xml/build.gradleselect the Java version viajava17too, so the generated code and build stay consistent. The effective Java version is unchanged; as a side effect, the duplicated<source>17</source><target>17</target>elements in the pom withuseSpringBoot4are gone.Verification:
webclient/restclient/resttemplatesample configs; a script verified that every changed line falls into one of the categories above.webclientandresttemplate(Java 1.8 target),webclient-jakarta,resttemplate-jakarta,resttemplate-springBoot4-jackson3andrestclient(Java 17) samples.JavaClientCodegenTest(shouldNotNullCheckRequiredParametersTwice,shouldUseDiamondOperatorWhereSupported) for all three libraries; all Java generator tests pass.The second commit updates the
go-oneof-not-enumsample, which is stale on master after #25064 and #25089 were merged concurrently and fails the "Samples up-to-date" check.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.
cc Java technical committee: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim
Summary by cubic
Simplifies the API code generated by the Spring-based Java client libraries (
webclient,restclient,resttemplate) by removing redundant patterns that IDEs flag as warnings.Refactors
postBodyandlocalVarPostBodylocal variables.HashMapandLinkedMultiValueMapinstantiations use the diamond operator; anonymousParameterizedTypeReferencesubclasses use it only when the target is Java 17.resttemplatenow sets the existingjava17flag whenuseJakartaEeis enabled and uses it to pick the Java version inpom.xml/build.gradle, with no change to the effective Java version and duplicated<source>/<target>elements removed foruseSpringBoot4.go-oneof-not-enumsample that failed the "Samples up-to-date" check after concurrent merges.Written for commit 6c9bf74. Summary will update on new commits.