Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{^lombok.Data}}

{{! begin feature: fluent setter methods }}
{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} {{name}}({{#useJspecify}}{{#lambda.jSpecifyNullable}}{{^required}}{{^useOptional}}@Nullable {{/useOptional}}{{#useOptional}}{{#optionalAcceptNullable}}@Nullable {{/optionalAcceptNullable}}{{/useOptional}}{{/required}}{{/lambda.jSpecifyNullable}}{{#lambda.jSpecifyDatatype}}{{{datatypeWithEnum}}}{{/lambda.jSpecifyDatatype}}{{/useJspecify}}{{^useJspecify}}{{>nullableAnnotation_default}}{{{datatypeWithEnum}}}{{/useJspecify}} {{name}}) {
{{#openApiNullable}}
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of{{#optionalAcceptNullable}}Nullable{{/optionalAcceptNullable}}({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
Expand All @@ -165,6 +168,9 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
}
{{#isArray}}

{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
{{#openApiNullable}}
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
Expand All @@ -183,6 +189,9 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{/isArray}}
{{#isMap}}

{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
{{#openApiNullable}}
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
Expand Down Expand Up @@ -270,19 +279,26 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}

{{^lombok.Setter}}
{{! begin feature: fluent setter methods for inherited properties }}
{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
super.{{name}}({{name}});
return this;
}
{{#isArray}}

{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
super.add{{nameInPascalCase}}Item({{name}}Item);
return this;
}
{{/isArray}}
{{#isMap}}

{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
super.put{{nameInPascalCase}}Item(key, {{name}}Item);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5833,6 +5833,24 @@ public void shouldGenerateSingleDeprecatedAnnotation() {
.assertMethod("build")
.doesNotHaveAnnotation("Deprecated");
}
/**
* Regression test for <a href="https://github.com/OpenAPITools/openapi-generator/issues/24704">#24704</a>
*/
@Test
public void shouldGenerateDeprecatedAnnotationOnFluentSetter() {
final var tempDir = TestUtils.newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.addAdditionalProperty(GENERATE_BUILDERS, true)
.addGlobalProperty(CodegenConstants.MODELS, "Pet")
.setInputSpec("src/test/resources/3_0/petstore.yaml")
.setGeneratorName("spring")
.setOutputDir(tempDir.toString());

new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

JavaFileAssert.assertThat(tempDir.resolve("src/main/java/org/openapitools/model/Pet.java"))
.assertMethod("status", "StatusEnum").hasAnnotation("Deprecated");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This regression test only covers the single fluent setter of the own enum property status. The fix claims to cover inherited-property fluent setters and the addXxxItem/putXxxItem variants, none of which this test exercises (Pet is not a child schema and status is not a container). Extend the test to cover those variants so a regression in the rest of the fix is detected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 5852:

<comment>This regression test only covers the single fluent setter of the own enum property `status`. The fix claims to cover inherited-property fluent setters and the `addXxxItem`/`putXxxItem` variants, none of which this test exercises (Pet is not a child schema and `status` is not a container). Extend the test to cover those variants so a regression in the rest of the fix is detected.</comment>

<file context>
@@ -5833,6 +5833,24 @@ public void shouldGenerateSingleDeprecatedAnnotation() {
+        new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
+
+        JavaFileAssert.assertThat(tempDir.resolve("src/main/java/org/openapitools/model/Pet.java"))
+                .assertMethod("status", "StatusEnum").hasAnnotation("Deprecated");
+    }
 
</file context>

}

@Test
public void shouldAnnotateNonRequiredFieldsAsNullable() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ public void setName(JsonNullable<String> name) {
this.name = name;
}

@Deprecated
public Pet photoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
}

@Deprecated
public Pet addPhotoUrlsItem(String photoUrlsItem) {
if (this.photoUrls == null) {
this.photoUrls = new ArrayList<>();
Expand Down