From 083b68654e8c3775f64231f6bc240865b29a9f3a Mon Sep 17 00:00:00 2001 From: Malte Otten <42797596+maltesmann@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:16:20 +0100 Subject: [PATCH 1/2] process deprecated flag from json schema --- .../src/main/java/com/asyncapi/model/$$objectSchema$$.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java index de7ccc3b4..a8fe79790 100644 --- a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java @@ -144,6 +144,7 @@ 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 %} @@ -152,6 +153,7 @@ public class {{allName}} { return {{varName}}; } + {% if prop.deprecated() -%}@Deprecated{%- endif %} public void set{{className}}({{propType}} {{varName}}) { this.{{varName}} = {{varName}}; } @@ -199,4 +201,4 @@ private String toIndentedString(Object o) { } return o.toString().replace("\n", "\n "); } -} \ No newline at end of file +} From e10eb6cf141188a8832d332f8cac0c5454c2ef69 Mon Sep 17 00:00:00 2001 From: Malte Otten Date: Tue, 19 Nov 2024 10:16:08 +0100 Subject: [PATCH 2/2] add test parameter and fix whitespace control --- .../com/asyncapi/model/$$objectSchema$$.java | 7 +++--- .../additional-formats.test.js.snap | 22 +++++++++++++++++-- tests/mocks/additional-type-formats.yml | 6 ++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java index a8fe79790..d08d12c7a 100644 --- a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java @@ -152,8 +152,9 @@ public class {{allName}} { public {{propType}} get{{className}}() { return {{varName}}; } - - {% if prop.deprecated() -%}@Deprecated{%- endif %} +{% if prop.deprecated() %} + @Deprecated +{%- endif %} public void set{{className}}({{propType}} {{varName}}) { this.{{varName}} = {{varName}}; } @@ -201,4 +202,4 @@ private String toIndentedString(Object o) { } return o.toString().replace("\n", "\n "); } -} +} \ No newline at end of file diff --git a/tests/__snapshots__/additional-formats.test.js.snap b/tests/__snapshots__/additional-formats.test.js.snap index 93a7ce2fe..261fd77e6 100644 --- a/tests/__snapshots__/additional-formats.test.js.snap +++ b/tests/__snapshots__/additional-formats.test.js.snap @@ -30,6 +30,8 @@ public class SongPayload { private @Valid java.math.BigDecimal rating; + private @Valid Integer stars; + @@ -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) { @@ -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 @@ -128,6 +145,7 @@ public class SongPayload { " uri: " + toIndentedString(uri) + "\\n" + " email: " + toIndentedString(email) + "\\n" + " rating: " + toIndentedString(rating) + "\\n" + + " stars: " + toIndentedString(stars) + "\\n" + "}"; } diff --git a/tests/mocks/additional-type-formats.yml b/tests/mocks/additional-type-formats.yml index 1d4c572a9..13ae8d826 100644 --- a/tests/mocks/additional-type-formats.yml +++ b/tests/mocks/additional-type-formats.yml @@ -41,4 +41,8 @@ components: rating: description: Title rating type: string - format: decimal \ No newline at end of file + format: decimal + stars: + description: "Number of stars. Deprecated: Use rating" + type: integer + deprecated: true \ No newline at end of file