Skip to content

Commit

Permalink
feat: mark deprecated properties with @deprecated (#421)
Browse files Browse the repository at this point in the history
* process deprecated flag from json schema

* add test parameter and fix whitespace control
  • Loading branch information
maltesmann authored Nov 26, 2024
1 parent 3a7f6de commit 65589a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ public class {{allName}} {
*/{% endif %}
@JsonProperty("{{propName}}")
{%- if propName | isRequired(schema.required()) %}@NotNull{% endif %}
{%- if prop.deprecated() %}@Deprecated{% endif %}
{%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %}
{%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern() | addBackSlashToPattern}}"){% endif %}
{%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %}
{%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %}
public {{propType}} get{{className}}() {
return {{varName}};
}

{% if prop.deprecated() %}
@Deprecated
{%- endif %}
public void set{{className}}({{propType}} {{varName}}) {
this.{{varName}} = {{varName}};
}
Expand Down
22 changes: 20 additions & 2 deletions tests/__snapshots__/additional-formats.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SongPayload {
private @Valid java.math.BigDecimal rating;
private @Valid Integer stars;
Expand Down Expand Up @@ -97,6 +99,20 @@ public class SongPayload {
this.rating = rating;
}
/**
* Number of stars. Deprecated: Use rating
*/
@JsonProperty("stars")@Deprecated
public Integer getStars() {
return stars;
}
@Deprecated
public void setStars(Integer stars) {
this.stars = stars;
}
@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -111,12 +127,13 @@ public class SongPayload {
Objects.equals(this.title, songPayload.title) &&
Objects.equals(this.uri, songPayload.uri) &&
Objects.equals(this.email, songPayload.email) &&
Objects.equals(this.rating, songPayload.rating);
Objects.equals(this.rating, songPayload.rating) &&
Objects.equals(this.stars, songPayload.stars);
}
@Override
public int hashCode() {
return Objects.hash(id, title, uri, email, rating);
return Objects.hash(id, title, uri, email, rating, stars);
}
@Override
Expand All @@ -128,6 +145,7 @@ public class SongPayload {
" uri: " + toIndentedString(uri) + "\\n" +
" email: " + toIndentedString(email) + "\\n" +
" rating: " + toIndentedString(rating) + "\\n" +
" stars: " + toIndentedString(stars) + "\\n" +
"}";
}
Expand Down
6 changes: 5 additions & 1 deletion tests/mocks/additional-type-formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ components:
rating:
description: Title rating
type: string
format: decimal
format: decimal
stars:
description: "Number of stars. Deprecated: Use rating"
type: integer
deprecated: true

0 comments on commit 65589a5

Please sign in to comment.