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

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.

P3: The fluent setters and collection helpers get the @Deprecated annotation but, unlike the getter and regular setter for the same deprecated property, they emit no /** @deprecated */ Javadoc block. Add a matching Javadoc deprecation tag for consistency so @deprecated HTML docs stay uniform across generated code.

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/JavaSpring/pojo.mustache, line 158:

<comment>The fluent setters and collection helpers get the `@Deprecated` annotation but, unlike the getter and regular setter for the same deprecated property, they emit no `/** @deprecated */` Javadoc block. Add a matching Javadoc deprecation tag for consistency so `@deprecated` HTML docs stay uniform across generated code.</comment>

<file context>
@@ -154,6 +154,9 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
 
   {{! 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}}) {
</file context>

{{/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,28 @@ 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 @@ -3254,6 +3254,41 @@ public void contractWithDeprecatedEnumGeneratesDeprecatedAnnotation() throws IOE
.fileDoesNotContain("@Deprecated");
}

@Test
public void contractWithDeprecatedPropertiesAnnotatesFluentSettersAndCollectionHelpers() throws IOException {
Map<String, File> output = generateFromContract(
"src/test/resources/3_0/spring/issue_24704.yaml",
SPRING_BOOT,
Map.of(GENERATE_BUILDERS, true)
);

JavaFileAssert.assertThat(output.get("Example.java"))
.assertMethod("deprecatedProperty", "String")
.hasAnnotation("Deprecated")
.toFileAssert()
.assertMethod("deprecatedValues")
.hasAnnotation("Deprecated")
.toFileAssert()
.assertMethod("deprecatedMap")
.hasAnnotation("Deprecated")
.toFileAssert()
.assertMethod("addDeprecatedValuesItem", "String")
.hasAnnotation("Deprecated")
.toFileAssert()
.assertMethod("putDeprecatedMapItem", "String", "String")
.hasAnnotation("Deprecated")
.toFileAssert()
.assertMethod("currentProperty", "String")
.doesNotHaveAnnotation("Deprecated")
.toFileAssert()
.assertInnerClass("Builder")
.assertMethod("deprecatedProperty", "String")
.hasAnnotation("Deprecated")
.toInnerClassAssert()
.assertMethod("currentProperty", "String")
.doesNotHaveAnnotation("Deprecated");
}

@Test
public void contractWithResolvedInnerEnumContainsEnumConverter() throws IOException {
File output = Files.createTempDirectory("test").toFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.3
info:
title: Deprecated property example
version: 1.0.0
paths:
/example:
get:
operationId: getExample
responses:
"200":
description: Example response
content:
application/json:
schema:
$ref: "#/components/schemas/Example"
components:
schemas:
Example:
type: object
properties:
currentProperty:
type: string
deprecatedProperty:
type: string
deprecated: true
deprecatedValues:
type: array
deprecated: true
items:
type: string
deprecatedMap:
type: object
deprecated: true
additionalProperties:
type: string
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void setTags(List<@Valid TagDto> tags) {
this.tags = tags;
}

@Deprecated
public PetDto status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public void setTags(List<TagDto> tags) {
this.tags = tags;
}

@Deprecated
public PetDto status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void setTags(List<TagDto> tags) {
this.tags = tags;
}

@Deprecated
public PetDto status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void setTags(List<Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void setTags(List<Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void setTags(List<@Valid TagDto> tags) {
this.tags = tags;
}

@Deprecated
public PetDto status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public void setTags(List<TagDto> tags) {
this.tags = tags;
}

@Deprecated
public PetDto status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(StatusEnum status) {
this.status = Optional.ofNullable(status);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

@Deprecated
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
Expand Down
Loading