Skip to content

Commit 65589a5

Browse files
authored
feat: mark deprecated properties with @deprecated (#421)
* process deprecated flag from json schema * add test parameter and fix whitespace control
1 parent 3a7f6de commit 65589a5

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

template/src/main/java/com/asyncapi/model/$$objectSchema$$.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,17 @@ public class {{allName}} {
144144
*/{% endif %}
145145
@JsonProperty("{{propName}}")
146146
{%- if propName | isRequired(schema.required()) %}@NotNull{% endif %}
147+
{%- if prop.deprecated() %}@Deprecated{% endif %}
147148
{%- 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 %}
148149
{%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern() | addBackSlashToPattern}}"){% endif %}
149150
{%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %}
150151
{%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %}
151152
public {{propType}} get{{className}}() {
152153
return {{varName}};
153154
}
154-
155+
{% if prop.deprecated() %}
156+
@Deprecated
157+
{%- endif %}
155158
public void set{{className}}({{propType}} {{varName}}) {
156159
this.{{varName}} = {{varName}};
157160
}

tests/__snapshots__/additional-formats.test.js.snap

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class SongPayload {
3030
3131
private @Valid java.math.BigDecimal rating;
3232
33+
private @Valid Integer stars;
34+
3335
3436
3537
@@ -97,6 +99,20 @@ public class SongPayload {
9799
this.rating = rating;
98100
}
99101
102+
103+
/**
104+
* Number of stars. Deprecated: Use rating
105+
*/
106+
@JsonProperty("stars")@Deprecated
107+
public Integer getStars() {
108+
return stars;
109+
}
110+
111+
@Deprecated
112+
public void setStars(Integer stars) {
113+
this.stars = stars;
114+
}
115+
100116
@Override
101117
public boolean equals(Object o) {
102118
if (this == o) {
@@ -111,12 +127,13 @@ public class SongPayload {
111127
Objects.equals(this.title, songPayload.title) &&
112128
Objects.equals(this.uri, songPayload.uri) &&
113129
Objects.equals(this.email, songPayload.email) &&
114-
Objects.equals(this.rating, songPayload.rating);
130+
Objects.equals(this.rating, songPayload.rating) &&
131+
Objects.equals(this.stars, songPayload.stars);
115132
}
116133
117134
@Override
118135
public int hashCode() {
119-
return Objects.hash(id, title, uri, email, rating);
136+
return Objects.hash(id, title, uri, email, rating, stars);
120137
}
121138
122139
@Override
@@ -128,6 +145,7 @@ public class SongPayload {
128145
" uri: " + toIndentedString(uri) + "\\n" +
129146
" email: " + toIndentedString(email) + "\\n" +
130147
" rating: " + toIndentedString(rating) + "\\n" +
148+
" stars: " + toIndentedString(stars) + "\\n" +
131149
"}";
132150
}
133151

tests/mocks/additional-type-formats.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ components:
4141
rating:
4242
description: Title rating
4343
type: string
44-
format: decimal
44+
format: decimal
45+
stars:
46+
description: "Number of stars. Deprecated: Use rating"
47+
type: integer
48+
deprecated: true

0 commit comments

Comments
 (0)