Repository navigation
[Java][Spring] Omit annotation attributes with default values - #25137
Open
ondrej-simon wants to merge 2 commits into
Open
ondrej-simon wants to merge 2 commits into
ondrej-simon wants to merge 2 commits into
Conversation
Stop emitting attributes that equal their defaults in generated Spring APIs: - required = true on @RequestHeader, @RequestParam and @RequestPart - description = "" on @parameter and @operation (and the empty javadoc line), by treating empty operation/parameter descriptions as absent Also simplify SpringCodegen#postProcessOperationsWithModels by using an early return and extracting helpers. Fixes OpenAPITools#25136
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 245 files
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Re-trigger cubic
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 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This branch has not been deployed
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.
Fixes #25136.
The
springgenerator emits annotation attributes that are equal to their defaults. This PR removes them, making the generated APIs leaner without changing their semantics:required = trueis no longer emitted on@RequestHeader,@RequestParamand@RequestPart(Spring's default istrue);required = falseis still emitted, consistent with how@CookieValueand@RequestBodyare already generated.required = trueon@Parameteris kept, as its default isfalse.descriptionon@Parameteris only emitted when present.SpringCodegen, so specs withdescription: ''no longer produce@Operation(description = ""),@Parameter(description = "")or an empty*javadoc line. (jmustache treats""as truthy in sections, so{{#notes}}alone is not enough.) This is done on the codegen models rather than with a globalemptyStringIsFalse(true), which would also affect e.g.{{#defaultValue}}, where an explicit empty default is meaningful.Before:
After:
While touching
SpringCodegen#postProcessOperationsWithModels, I reduced its nesting with an early return and extracted the response post-processing and description cleanup into helpers. This refactoring is behavior-preserving: regenerating all Spring samples before and after it produces byte-identical output.Changes:
JavaSpring/headerParams.mustache,queryParams.mustache,formParams.mustache,paramDoc.mustacheSpringCodegen: clear empty descriptions; early return/helpers inpostProcessOperationsWithModelsSpringCodegenTest: newshouldOmitAnnotationAttributesWithDefaultValues, and updated 4 tests that asserted the old redundant attributesspringandjava-camelsamples (73 configs). The sample diff only removes the attributes/lines listed above (verified with a script that every changed line differs only by these removals).Tested: all Spring-related tests pass (
SpringCodegenTest,JavaCamelServerCodegenTest,*Spring*Test, 800 tests).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 Spring technical committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim
Summary by cubic
Fixes #25136 by omitting annotation attributes that equal Spring's defaults in generated Spring APIs, so generated code is leaner without changing semantics.
required = trueis no longer emitted on@RequestHeader,@RequestParam, or@RequestPart;required = falseis still emitted.description = ""no longer appears on@Operationor@Parameter, and no empty javadoc line is generated.Refactor
SpringCodegen#postProcessOperationsWithModelsuses an early return and helpers for response post-processing and description cleanup; behavior is preserved, verified by regenerating all Spring samples.go-oneof-not-enumsample to satisfy the samples up-to-date check.Written for commit 241751d. Summary will update on new commits.